47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
// test/factories/employee.factory.ts
|
||
export type EmployeePayload = {
|
||
// user_id?: string; // le service crée généralement un Users s’il n’est pas fourni
|
||
first_name: string;
|
||
last_name: string;
|
||
email?: string;
|
||
phone_number: number;
|
||
residence?: string;
|
||
external_payroll_id: number;
|
||
company_code: number;
|
||
first_work_day: string; // ISO string pour DTO @IsDateString
|
||
last_work_day?: string;
|
||
};
|
||
|
||
const randInt = (min: number, max: number) =>
|
||
Math.floor(Math.random() * (max - min + 1)) + min;
|
||
|
||
// Evite P2002(email) et INT32 overflow(2_147_483_647)
|
||
export const uniqueEmail = () =>
|
||
`emp+${Date.now()}_${Math.random().toString(36).slice(2,8)}@test.local`;
|
||
export const safePhone = () =>
|
||
randInt(100_000_000, 999_999_999); // 9 chiffres < INT32
|
||
const uniqueExtPayroll = () => randInt(1_000_000, 9_999_999);
|
||
const uniqueCompanyCode = () => randInt(100_000, 999_999);
|
||
const iso = (y: number, m: number, d: number) =>
|
||
new Date(Date.UTC(y, m - 1, d)).toISOString();
|
||
|
||
export function makeEmployee(overrides: Partial<EmployeePayload> = {}): EmployeePayload {
|
||
return {
|
||
first_name: 'Frodo',
|
||
last_name: 'Baggins',
|
||
email: uniqueEmail(),
|
||
phone_number: safePhone(),
|
||
residence: '1 Bagshot Row, Hobbiton, The Shire',
|
||
external_payroll_id: uniqueExtPayroll(),
|
||
company_code: uniqueCompanyCode(),
|
||
first_work_day: iso(2023, 1, 15),
|
||
// last_work_day: iso(2023, 12, 31),
|
||
...overrides,
|
||
};
|
||
}
|
||
|
||
// volontairement invalide pour déclencher 400 via ValidationPipe
|
||
export function makeInvalidEmployee(): Record<string, unknown> {
|
||
return { first_name: '', external_payroll_id: 'nope' };
|
||
}
|