Add Linear XLSX follow-up import

This commit is contained in:
Julian Appel 2026-09-30 20:40:40 +02:00
parent 1a4c8cad8c
commit 2581beee3c
28 changed files with 1114 additions and 31 deletions

View file

@ -2,7 +2,7 @@ import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { describe, it } from "node:test";
import { createDefaultExternalModelConfiguration } from "../src/external-model/configuration/external-model-configuration.js";
import { applyExternalInitialImport, createExternalReturnWorkbook, detectExternalModelWorkbook, getExternalInitialImportStatus, getExternalModelConfiguration, getExternalProjectObjects, planExternalInitialImport, updateExternalModelConfiguration, updateExternalProjectObjects } from "../src/frontend/utils/api.js";
import { applyExternalFollowUpImport, applyExternalInitialImport, createExternalReturnWorkbook, deleteMissingExternalProjectObjects, detectExternalModelWorkbook, getExternalInitialImportStatus, getExternalModelConfiguration, getExternalProjectObjects, planExternalFollowUpImport, planExternalInitialImport, updateExternalModelConfiguration, updateExternalProjectObjects } from "../src/frontend/utils/api.js";
describe("Revit XLSX settings", () => {
it("uses the project-scoped configuration endpoint with expectedRevision", async () => {
@ -53,6 +53,7 @@ describe("Revit XLSX settings", () => {
const revitPage = readFileSync("src/app/projects/[projectId]/revit/page.tsx", "utf8");
const settings = readFileSync("src/frontend/components/revit-xlsx-settings-modal.tsx", "utf8");
const wizard = readFileSync("src/frontend/components/revit-initial-import-wizard.tsx", "utf8");
const followUpWizard = readFileSync("src/frontend/components/revit-follow-up-import-wizard.tsx", "utf8");
const objectTable = readFileSync("src/frontend/components/revit-object-table.tsx", "utf8");
assert.match(projectPage, /href={`\/projects\/\$\{projectId\}\/revit`}/);
assert.doesNotMatch(projectPage, /RevitCsvModal|Revit-CSV/);
@ -64,10 +65,23 @@ describe("Revit XLSX settings", () => {
assert.match(wizard, /Schritt.*von/);
assert.match(wizard, /keine Gerätezeilen, Stromkreise oder BMKs/);
assert.match(wizard, /GZF 1/);
assert.match(revitPage, /Folgeimport/);
assert.match(followUpWizard, /in Revit noch nicht aktualisiert/);
assert.match(followUpWizard, /Fehlende Objekte werden nicht gelöst oder gelöscht/);
assert.match(objectTable, /viewportHeight/);
assert.match(objectTable, /Sammeländerung anwenden/);
assert.match(objectTable, /Rückgabe-Excel herunterladen/);
assert.match(objectTable, /Nur geänderte Objekte/);
assert.match(objectTable, /Ausgewählte fehlende löschen/);
});
it("deletes missing objects only after explicit confirmation", async () => {
const requests: Array<{ url: string; method: string; body: unknown }> = [];
const originalFetch = globalThis.fetch;
globalThis.fetch = async (input, init) => { requests.push({ url: String(input), method: init?.method ?? "GET", body: init?.body ? JSON.parse(String(init.body)) : undefined }); return new Response(JSON.stringify({ history: { currentRevision: 6 } }), { status: 200, headers: { "Content-Type": "application/json" } }); };
try { await deleteMissingExternalProjectObjects("project-1", 5, ["object-1"]); }
finally { globalThis.fetch = originalFetch; }
assert.deepEqual(requests, [{ url: "/api/projects/project-1/external-model/objects/delete-missing", method: "POST", body: { expectedRevision: 5, objectIds: ["object-1"], confirmed: true } }]);
});
it("loads one project object list and sends revision-safe bulk updates", async () => {
@ -90,4 +104,21 @@ describe("Revit XLSX settings", () => {
finally { globalThis.fetch = originalFetch; }
assert.deepEqual(requests, [{ url: "/api/projects/project-1/external-model/return-workbook", method: "POST", body: { expectedRevision: 7, scope: "selected", selectedObjectIds: ["object-1"] } }]);
});
it("previews and retransmits the complete workbook for follow-up apply", async () => {
const requests: Array<{ url: string; method: string; body: Record<string, unknown> | undefined }> = [];
const originalFetch = globalThis.fetch;
globalThis.fetch = async (input, init) => { requests.push({ url: String(input), method: init?.method ?? "GET", body: init?.body ? JSON.parse(String(init.body)) : undefined }); return new Response(JSON.stringify({ history: { currentRevision: 10 }, import: { objectCount: 2 } }), { status: 200, headers: { "Content-Type": "application/json" } }); };
try {
const configuration = createDefaultExternalModelConfiguration();
const file = new File([new Uint8Array([1, 2])], "follow.xlsx");
await planExternalFollowUpImport("project-1", file, configuration, 9);
await applyExternalFollowUpImport("project-1", file, { expectedRevision: 9, expectedSha256: "a".repeat(64), configuration, objectsWithoutRoomDefaultDistributionBoardId: null, sourceChangeDecisions: [], roomDecisions: [], familyProjectDeviceDecisions: [] });
} finally { globalThis.fetch = originalFetch; }
assert.equal(requests[0].url, "/api/projects/project-1/external-model/follow-up-import/plan");
assert.equal(requests[1].url, "/api/projects/project-1/external-model/follow-up-import/apply");
assert.equal(requests[0].body?.contentBase64, "AQI=");
assert.equal(requests[1].body?.contentBase64, "AQI=");
assert.equal(requests[1].body?.expectedRevision, 9);
});
});