38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
// test/factories/expense.factory.ts
|
|
export type ExpensePayload = {
|
|
timesheet_id: number;
|
|
bank_code_id: number; // bank code categorie='EXPENSE' and type != 'MILEAGE'
|
|
date: string; // ISO date
|
|
amount: number; // INT (DTO: @IsInt)
|
|
description: string;
|
|
is_approved?: boolean;
|
|
supervisor_comment?: string;
|
|
};
|
|
|
|
const randInt = (min: number, max: number) =>
|
|
Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
const isoDate = (y: number, m: number, d: number) =>
|
|
new Date(Date.UTC(y, m - 1, d, 0, 0, 0)).toISOString();
|
|
|
|
export function makeExpense(
|
|
tsId: number,
|
|
bcId: number,
|
|
overrides: Partial<ExpensePayload> = {}
|
|
): ExpensePayload {
|
|
return {
|
|
timesheet_id: tsId,
|
|
bank_code_id: bcId,
|
|
date: isoDate(2024, 6, randInt(1, 28)),
|
|
amount: randInt(5, 200),
|
|
description: `Expense ${randInt(100, 999)}`,
|
|
supervisor_comment: 'N/A',
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
// volontairement invalide pour 400 via ValidationPipe
|
|
export function makeInvalidExpense(): Record<string, unknown> {
|
|
return { amount: 'oops', timesheet_id: 'nope' };
|
|
}
|