Skip to content

Instantly share code, notes, and snippets.

@Goldziher
Created August 1, 2021 06:35
Show Gist options
  • Save Goldziher/1d10120df9e4619c504057d69c68b1a2 to your computer and use it in GitHub Desktop.
Save Goldziher/1d10120df9e4619c504057d69c68b1a2 to your computer and use it in GitHub Desktop.
Example Interface Forge Factories
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