import { readFileSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { entitySlug, findDataspace, findEntity, findKind } from "./catalog"; const root = join(process.cwd(), "../examples/dataspaces"); function titles(dataspaceId: string, kindId: string): string[] { const snapshot = JSON.parse(readFileSync(join(root, dataspaceId, "snapshot.json"), "utf8")) as { entities: { kindId: string; title: string }[]; }; return snapshot.entities.filter((entity) => entity.kindId === kindId).map((entity) => entity.title).sort(); } describe("catalog", () => { it("takes the kind index from the snapshot registry", () => { const concept = findKind("systems-thinking", "concept"); const pattern = findKind("software-architecture", "pattern"); expect(concept?.plural).toBe("Concepts"); expect(concept?.rows.map((row) => row.title).sort()).toEqual(titles("systems-thinking", "concept")); expect(pattern?.rows.map((row) => row.title).sort()).toEqual(titles("software-architecture", "pattern")); expect(concept?.rows.every((row) => row.href?.startsWith("/systems-thinking/concept/"))).toBe(true); }); it("resolves one entity and hides unknown routes", () => { expect(entitySlug("urn:ce:systems-thinking:concept:system-boundary", "concept")).toBe("system-boundary"); const feedback = findEntity("systems-thinking", "concept", "feedback"); expect(feedback?.title).toBe("Feedback"); expect(feedback?.relations.some((relation) => relation.otherTitle === "Causal loop diagram")).toBe(true); expect(findEntity("systems-thinking", "concept", "missing")).toBeNull(); expect(findKind("systems-thinking", "no-such-kind")).toBeNull(); expect(findDataspace("software-architecture")?.title).toBe("Software Architecture"); }); });