import assert from "node:assert/strict"; import { describe, it } from "node:test"; import { createExternalCsvPreview } from "../src/external-model/application/external-csv-preview.js"; import { externalCsvTestConfiguration, firstIfcGuid, quotedRevitCsv, utf8Bytes, } from "./fixtures/revit-csv-fixtures.js"; describe("external CSV preview", () => { it("projects transport statistics and mapped object source values without writes", () => { const configuration = structuredClone(externalCsvTestConfiguration); configuration.additionalSourceMappings.push({ sourceColumn: "Raumname", targetField: "sourceRoomLabel", }); // The additional mapping intentionally needs a distinct source column in // persisted configuration, so use a separately named synthetic header. configuration.additionalSourceMappings[0].sourceColumn = "Zusatzwert"; const csv = quotedRevitCsv .replace('"Anzahl";"IfcGUID"', '"Anzahl";"Zusatzwert";"IfcGUID"') .replaceAll(';"2";"0Ab', ';"2";"A";"0Ab') .replaceAll(';"1";"1Ab', ';"1";"B";"1Ab') .replaceAll(';"1";""', ';"1";"C";""') .replaceAll(';"";""\r\n', ';"";"";""\r\n'); const preview = createExternalCsvPreview({ fileName: "export.csv", bytes: utf8Bytes(csv, true), configuration, }); assert.equal(preview.fileName, "export.csv"); assert.equal(preview.headerRowNumber, 2); assert.equal(preview.rowCount, 7); assert.equal(preview.objectCount, 2); assert.equal(preview.passthroughCount, 2); assert.equal(preview.nonEmptyPassthroughCount, 1); assert.equal(preview.suspectObjectCount, 1); assert.deepEqual(preview.suspectRowNumbers, [6]); assert.match(preview.sha256, /^[a-f0-9]{64}$/); assert.deepEqual(preview.objects[0], { rowNumber: 4, ifcGuid: firstIfcGuid, roomNumber: "01/101", roomName: "Technik", familyAndType: "Steckdose: Doppelsteckdose", selectionMarker: "Arbeitsplatz", circuitIdentifier: "UV_AV_01-2F1", power: "120,5", quantity: "2", additionalSourceValues: { sourceRoomLabel: "A" }, }); }); });