Files
bookmanager/tests/helpers/fixtures.ts
T
bobbanandClaude Sonnet 5.5 dcb5d43429 Automatiska tester, och rättningar som testerna hittade
Vitest med enhetstester utan databas och databastester mot en egen
testdatabas vars namn måste sluta på _test. Rättar tomma MAP_*-värden
i .env och säkerhetskopior med å, ä och ö i filnamnet.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-01 23:19:30 +01:00

39 lines
1.5 KiB
TypeScript

import sharp from "sharp";
import type { ExportData } from "@/lib/book-transfer";
/** En giltig minimal exportfil. Åsidosätt delar för att testa enskilda fall. */
export function validExport(overrides: Partial<ExportData> = {}): ExportData {
return {
format: "bookmanager-export",
version: 1,
exportedAt: "2026-01-01T00:00:00.000Z",
includesImages: false,
book: { title: "Testbok", subtitle: null, genre: null, description: null },
entities: [],
relations: [],
shifts: [],
maps: [],
templates: [],
...overrides,
};
}
export function entityRow(id: string, kind: ExportData["entities"][number]["kind"], name: string, extra: Partial<ExportData["entities"][number]> = {}): ExportData["entities"][number] {
return { id, kind, name, code: null, summary: null, tags: [], data: {}, image: null, ...extra };
}
/** En riktig bild (PNG, JPEG eller WebP) av önskad storlek, för tester av bildbehandling och uppladdning. */
export async function makeImage(
width: number,
height: number,
format: "png" | "jpeg" | "webp" = "png",
options: { orientation?: number } = {},
): Promise<Uint8Array> {
let pipeline = sharp({ create: { width, height, channels: 3, background: { r: 200, g: 60, b: 60 } } });
if (format === "png") pipeline = pipeline.png();
else if (format === "jpeg") pipeline = pipeline.jpeg({ quality: 40 });
else pipeline = pipeline.webp({ quality: 40 });
if (options.orientation) pipeline = pipeline.withMetadata({ orientation: options.orientation });
return new Uint8Array(await pipeline.toBuffer());
}