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>
This commit is contained in:
1 parent
4e8d79ee10
commit
dcb5d43429
30 files changed
+2872
-13
No files matched your search
@@ -0,0 +1,38 @@
|
||||
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());
|
||||
}
|
||||
Reference in new issue
Block a user