From 4cb2b6fbb8f0f4b90db2784772cbe7e6adaa83cc Mon Sep 17 00:00:00 2001 From: timepresent95 Date: Sat, 10 Aug 2024 01:37:32 +0900 Subject: [PATCH] feat: add fake user creator #19 --- src/mocks/fakers/index.ts | 1 + src/mocks/fakers/user.ts | 19 +++++++++++++++++++ src/mocks/fakers/util.ts | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/mocks/fakers/index.ts create mode 100644 src/mocks/fakers/user.ts create mode 100644 src/mocks/fakers/util.ts diff --git a/src/mocks/fakers/index.ts b/src/mocks/fakers/index.ts new file mode 100644 index 0000000..e5abc85 --- /dev/null +++ b/src/mocks/fakers/index.ts @@ -0,0 +1 @@ +export * from './user'; diff --git a/src/mocks/fakers/user.ts b/src/mocks/fakers/user.ts new file mode 100644 index 0000000..b422585 --- /dev/null +++ b/src/mocks/fakers/user.ts @@ -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, + }; +} diff --git a/src/mocks/fakers/util.ts b/src/mocks/fakers/util.ts new file mode 100644 index 0000000..ac849ad --- /dev/null +++ b/src/mocks/fakers/util.ts @@ -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(source: readonly T[]): T { + return source[getRandomInt(0, source.length - 1)]; +}