Files
TREK/server/tests/helpers/factories/files.ts
T
Maurice 724c88c201 style: format server and shared with prettier
A mechanical prettier --write over server/src, server/tests, server/scripts
and shared/src with the workspaces' .prettierrc; nothing but layout and
import order changes, and every file keeps the same set of imports. shared
is formatted throughout and its format baseline is empty. The server
baseline keeps the 35 files that Prettier would grow past their lint:size
limit (they need a split first, which is not a formatting change), and the
generated entity files stay as their generator writes them.
2026-10-10 21:23:37 +02:00

38 lines
1.3 KiB
TypeScript

import { FileLinks } from '../../../src/db/entities/FileLinks.entity';
import { TripFiles } from '../../../src/db/entities/TripFiles.entity';
import { nextSeq, type FactoryOrm } from './context';
import { createRow } from './rows';
import type { EntityData, EntityDTO } from '@mikro-orm/core';
export type TripFileRow = EntityDTO<TripFiles>;
export type FileLinkRow = EntityDTO<FileLinks>;
/**
* A file row on the trip. Only the row: a test that downloads the file also
* writes the bytes through the storage fixture (`storage-fixture.ts`).
*/
export function makeTripFile(
orm: FactoryOrm,
tripId: number,
overrides: EntityData<TripFiles> = {},
): Promise<TripFileRow> {
const n = nextSeq('trip-file');
return createRow(orm, TripFiles, {
trip: tripId,
filename: `test-file-${n}.pdf`,
original_name: `Test File ${n}.pdf`,
file_size: 1024,
mime_type: 'application/pdf',
...overrides,
});
}
/** Links the file to a booking, an assignment, a place or an expense (name exactly one in `target`). */
export function linkFile(
orm: FactoryOrm,
fileId: number,
target: Pick<EntityData<FileLinks>, 'reservation' | 'assignment' | 'place' | 'budgetItem'>,
): Promise<FileLinkRow> {
return createRow(orm, FileLinks, { file: fileId, ...target });
}