106 lines
3.5 KiB
TypeScript
106 lines
3.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import { createExternalCircuitListObjects } from "../src/external-model/application/external-circuit-list-objects.js";
|
|
import type {
|
|
ExternalModelObjectSnapshot,
|
|
ExternalModelStateSnapshot,
|
|
} from "../src/external-model/domain/external-model-contracts.js";
|
|
|
|
function object(input: {
|
|
id: string;
|
|
distributionBoardId: string;
|
|
circuitDeviceRowId: string | null;
|
|
roomNumber: string;
|
|
}): ExternalModelObjectSnapshot {
|
|
return {
|
|
id: input.id,
|
|
projectId: "project-1",
|
|
sourceId: "source-1",
|
|
ifcGuid: `ifc-${input.id}`,
|
|
lastSeenImportBatchId: "batch-1",
|
|
lastAcceptedImportBatchId: "batch-1",
|
|
acceptedSourceValues: {
|
|
rowNumber: 2,
|
|
roomNumber: input.roomNumber,
|
|
roomName: "Büro",
|
|
familyAndType: "Steckdose: Standard",
|
|
selectionMarker: `S-${input.id}`,
|
|
circuitIdentifier: "-2F1.1",
|
|
power: "120",
|
|
quantity: "1",
|
|
additionalSourceValues: {},
|
|
},
|
|
planningValues: {
|
|
displayName: "Steckdose",
|
|
internalDeviceType: "socket",
|
|
category: "single_phase",
|
|
connectionKind: "socket",
|
|
effectiveQuantity: 1,
|
|
powerPerUnitW: 120,
|
|
simultaneityFactor: 1,
|
|
cosPhi: null,
|
|
costGroup: null,
|
|
remark: null,
|
|
},
|
|
overriddenFields: [],
|
|
externalRoomMappingId: input.distributionBoardId === "board-1" ? "mapping-1" : null,
|
|
distributionBoardId: input.distributionBoardId,
|
|
linkedProjectDeviceId: null,
|
|
circuitDeviceRowId: input.circuitDeviceRowId,
|
|
presenceStatus: "present",
|
|
};
|
|
}
|
|
|
|
describe("external circuit-list object projection", () => {
|
|
it("returns only the board objects with unassigned objects first", () => {
|
|
const state: ExternalModelStateSnapshot = {
|
|
source: {
|
|
id: "source-1",
|
|
projectId: "project-1",
|
|
name: "Revit-Gesamtmodell",
|
|
sourceType: "revit_csv",
|
|
},
|
|
importBatches: [],
|
|
roomMappings: [{
|
|
id: "mapping-1",
|
|
projectId: "project-1",
|
|
sourceId: "source-1",
|
|
normalizedSourceRoomKey: "number:101",
|
|
sourceFloorName: "EG",
|
|
sourceRoomNumber: "101",
|
|
sourceRoomName: "Besprechung",
|
|
roomId: "room-1",
|
|
defaultDistributionBoardId: "board-1",
|
|
}],
|
|
objects: [
|
|
object({ id: "assigned", distributionBoardId: "board-1", circuitDeviceRowId: "row-1", roomNumber: "102" }),
|
|
object({ id: "unassigned", distributionBoardId: "board-1", circuitDeviceRowId: null, roomNumber: "101" }),
|
|
object({ id: "other-board", distributionBoardId: "board-2", circuitDeviceRowId: null, roomNumber: "001" }),
|
|
],
|
|
};
|
|
|
|
const result = createExternalCircuitListObjects({
|
|
state,
|
|
distributionBoardId: "board-1",
|
|
});
|
|
|
|
assert.equal(result.sourceName, "Revit-Gesamtmodell");
|
|
assert.equal(result.objectCount, 2);
|
|
assert.equal(result.unassignedObjectCount, 1);
|
|
assert.deepEqual(result.objects.map(({ id }) => id), ["unassigned", "assigned"]);
|
|
assert.equal(result.objects[0].sourceRoomName, "Besprechung");
|
|
assert.equal(result.objects[0].roomId, "room-1");
|
|
assert.equal(result.objects[0].sourceCircuitIdentifier, "-2F1.1");
|
|
});
|
|
|
|
it("returns an empty projection before the optional Revit import", () => {
|
|
assert.deepEqual(
|
|
createExternalCircuitListObjects({
|
|
state: { source: null, importBatches: [], roomMappings: [], objects: [] },
|
|
distributionBoardId: "board-1",
|
|
}),
|
|
{ sourceName: null, objectCount: 0, unassignedObjectCount: 0, objects: [] }
|
|
);
|
|
});
|
|
});
|