Files
Epicnabbo-Catalogus-Updated…/src/lib/services/figuremap.test.ts
T
openhands 4993b75608 perf: self-host fonts, drop unused generated code and add swf tests
- Self-host Nunito and Pixelify Sans via next/font instead of Google Fonts CDN
  (removes render-blocking external stylesheets and preconnects)
- Remove stale mariadb entry from serverExternalPackages (app uses mysql2)
- Exclude unused src/generated Prisma client from typecheck and remove it
- Add unit tests for swf-parser, effectmap and figuremap (0% coverage -> 90%+)
2026-08-09 12:12:02 +02:00

63 lines
1.8 KiB
TypeScript

import { promises as fs } from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { FigureLibrary } from "./figuremap";
import {
__setFigureMapPathForTests,
listFigureLibraries,
mergeLibrary,
} from "./figuremap";
vi.mock("@/lib/services/site-settings", () => ({
siteSettings: { get: vi.fn(async () => "") },
}));
let dir: string;
let file: string;
const LIB: FigureLibrary = {
id: "h_human",
revision: 1,
parts: [{ id: 1, type: "hd" }],
};
beforeEach(async () => {
dir = await fs.mkdtemp(path.join(os.tmpdir(), "figuremap-"));
file = path.join(dir, "FigureMap.json");
await fs.writeFile(file, JSON.stringify({ libraries: [LIB] }));
__setFigureMapPathForTests(file);
});
afterEach(async () => {
__setFigureMapPathForTests(null);
await fs.rm(dir, { recursive: true, force: true });
});
describe("lib/services/figuremap", () => {
it("lists figure libraries from the map", async () => {
const libraries = await listFigureLibraries();
expect(libraries).toEqual([LIB]);
});
it("returns an empty list when the file has no libraries array", async () => {
await fs.writeFile(file, JSON.stringify({}));
expect(await listFigureLibraries()).toEqual([]);
});
it("adds a new library via mergeLibrary", async () => {
const added: FigureLibrary = { id: "hh_human", revision: 2 };
await mergeLibrary(added);
const libraries = await listFigureLibraries();
expect(libraries).toHaveLength(2);
expect(libraries).toContainEqual(added);
});
it("updates an existing library in place via mergeLibrary", async () => {
await mergeLibrary({ ...LIB, revision: 9 });
const libraries = await listFigureLibraries();
expect(libraries).toHaveLength(1);
expect(libraries[0].revision).toBe(9);
});
});