Created
March 2, 2025 17:11
-
-
Save fredgrott/16fa7ca8460e5dda8cb609818606d857 to your computer and use it in GitHub Desktop.
extension json data fixture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'company_model.dart'; | |
extension CompanyFixture on Company { | |
static _CompanyFixtureFactory factory() => | |
_CompanyFixtureFactory(); | |
} | |
class _CompanyFixtureFactory extends | |
JsonFixtureFactory<Company> { | |
@override | |
FixtureDefinition<Company> definition() => define( | |
(faker) => Company( | |
name: faker.company.name(), | |
employees: PersonFixture.factory().makeMany(5), | |
), | |
); | |
@override | |
JsonFixtureDefinition<Company> jsonDefinition() => | |
defineJson( | |
(company) => { | |
"name": company.name, | |
"employees": | |
PersonFixture.factory().makeJsonArrayFromMany(company.employees)/// , | |
}, | |
); | |
JsonFixtureDefinition<Company> empty(String name) => ///redefineJson( | |
(company) => Company( | |
name: name, | |
employees: [], | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment