import Chance from 'chance' ; import { Role , Prisma } from '@prisma/client' ; import { buildPrismaIncludeFromAttrs } from '../helpers/buildPrismaIncludeFromAttrs' ; import { prisma } from '../../lib/prisma' ; import { hashPassword } from '../../services/auth' ; const chance = new Chance ( ) ; export const UserFactory = { build : ( attrs = { } ) => { return { email : chance . email ( ) , password : 'test1234' , roles : { set : [ Role . USER ] } , ... attrs , } ; } , create : async ( attrs = { } ) => { const user = UserFactory . build ( attrs ) ; const options = { } ; const includes = buildPrismaIncludeFromAttrs ( attrs ) ; if ( includes ) options . include = includes ; return await prisma . user . create ( { data : { ... user , password : hashPassword ( user . password ) , roles : user . roles } , ... options , } ) ; } , } ;