Created
August 1, 2021 06:35
-
-
Save Goldziher/1d10120df9e4619c504057d69c68b1a2 to your computer and use it in GitHub Desktop.
Example Interface Forge Factories
This file contains 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 * as faker from 'faker'; | |
import { TypeFactory } from 'interface-forge'; | |
import { User, UserProfile } from '@backend/db/entities/User'; | |
export const UserProfileFactory = new TypeFactory< | |
Omit<UserProfile, 'user' | 'id' | 'createdDate' | 'updatedDate'> | |
>(() => ({ | |
location: faker.address.city(), | |
employer: faker.company.companyName(), | |
profession: TypeFactory.iterate([ | |
'Chef', | |
'Programmer', | |
'Fighter Pilot', | |
'Slob', | |
]), | |
phoneNumber: faker.phone.phoneNumber(), | |
imageUrl: faker.internet.url(), | |
birthDate: faker.date.past(faker.datatype.number({ min: 20, max: 80 })), | |
})); | |
export const UserFactory = new TypeFactory< | |
Omit<User, 'id' | 'createdDate' | 'updatedDate'> | |
>(() => ({ | |
firstName: faker.name.firstName(), | |
lastName: faker.name.lastName(), | |
isActive: true, | |
email: faker.internet.email(), | |
profile: UserProfileFactory, | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment