Skip to content

Commit

Permalink
feat: add fake user creator
Browse files Browse the repository at this point in the history
  • Loading branch information
timepresent95 committed Aug 9, 2024
1 parent 3da28e6 commit 4cb2b6f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mocks/fakers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './user';
19 changes: 19 additions & 0 deletions src/mocks/fakers/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {faker} from '@faker-js/faker';

import {getRandom} from './util';

import {birthType, roles} from '@/constants';
import type {Member} from '@/types';
import {formatDate} from '@/utils';

export function createUser(isHost: boolean): Member {
return {
nickName: faker.person.fullName(),
groupRole: getRandom(roles),
birth: formatDate(faker.date.birthdate()),
birthType: getRandom(birthType),
email: faker.internet.email(),
signUpDate: faker.date.past(),
isHost,
};
}
9 changes: 9 additions & 0 deletions src/mocks/fakers/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}

export function getRandom<T>(source: readonly T[]): T {
return source[getRandomInt(0, source.length - 1)];
}

0 comments on commit 4cb2b6f

Please sign in to comment.