Files
velum-raycast/tests/mapping-created-at.test.ts

51 lines
2.2 KiB
TypeScript

import { expect, it } from "bun:test";
import { projectMappingCreatedAt, sortMappingRowsByCreatedAt } from "../src/lib/mapping-created-at";
import type { ProjectRun } from "../src/lib/velum-project";
import type { PlaceholderMapping } from "../src/types";
function run(createdAt: string, mapping: PlaceholderMapping): ProjectRun {
return { version: 2, id: createdAt, projectPath: "/synthetic", projectName: "synthetic",
createdAt, mapping, files: [] };
}
it("ermittelt die erste gespeicherte Projektfassung je unveränderter Zuordnung", () => {
const earlier = run("2026-01-01T10:00:00.000Z", {
PERSON_01: { type: "PERSON", original: "Beispiel Eins" },
ORG_01: { type: "ORG", original: "Frühere Organisation" },
});
const latest = run("2026-02-01T10:00:00.000Z", {
PERSON_01: { type: "PERSON", original: "Beispiel Eins" },
PERSON_02: { type: "PERSON", original: "Beispiel Zwei" },
ORG_01: { type: "ORG", original: "Neue Organisation" },
});
expect(projectMappingCreatedAt([latest, earlier], latest.mapping)).toEqual({
PERSON_01: earlier.createdAt,
PERSON_02: latest.createdAt,
ORG_01: latest.createdAt,
});
});
it("sortiert datierte Zuordnungen zuerst, sonst Nummern je Kategorie absteigend", () => {
const rows = ["PERSON_02", "ORT_03", "PERSON_100", "ORT_20", "ORG_01", "PERSON_10"]
.map((placeholder) => ({ placeholder, type: placeholder.split("_")[0] }));
const sorted = sortMappingRowsByCreatedAt(rows, {
PERSON_02: "2026-05-01T00:00:00.000Z",
ORG_01: "2026-06-01T00:00:00.000Z",
});
expect(sorted.map((row) => row.placeholder))
.toEqual(["ORG_01", "PERSON_02", "ORT_20", "ORT_03", "PERSON_100", "PERSON_10"]);
});
it("behandelt importierte Erststände ohne echtes Anlagedatum als Nummern-Fallback", () => {
const imported = { ...run("2026-01-01T10:00:00.000Z", {
PERSON_01: { type: "PERSON", original: "Altbestand" },
}), origin: "imported" as const };
const later = { ...run("2026-02-01T10:00:00.000Z", {
PERSON_01: { type: "PERSON", original: "Altbestand" },
PERSON_02: { type: "PERSON", original: "Neu" },
}), origin: "imported" as const, revisedFrom: imported.id };
expect(projectMappingCreatedAt([later, imported], later.mapping)).toEqual({
PERSON_02: later.createdAt,
});
});