Skip to content

Commit

Permalink
test: create user seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
stae1102 committed Jan 20, 2024
1 parent de721f1 commit 22e2f84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/seeder/seeder.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Seeder<T> {
generateOne(options?: { [K in keyof T]: any }): T;
}
23 changes: 23 additions & 0 deletions test/seeder/user.seeder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Seeder } from './seeder.interface';
import { User, UserRole } from '../../src/users/entities/user.entity';
import { faker } from '@faker-js/faker';

export class UserSeeder implements Seeder<User> {
private readonly userStub = {
name: faker.person.lastName(),
email: faker.internet.email(),
profileImage: faker.internet.url(),
password:
'1' +
faker.internet.password({
length: 10,
// pattern: /^(?=.*\d)[A-Za-z\d@$!%*?&]{8,}$/,
}),
role: UserRole.Client,
verified: true,
};

generateOne(options?: { [K in keyof User]: any }): User {
return { ...this.userStub, ...options } as User;
}
}

0 comments on commit 22e2f84

Please sign in to comment.