Add circuit history commands
This commit is contained in:
@@ -18,6 +18,11 @@ import {
|
||||
createCircuitDeviceRowDeleteProjectCommand,
|
||||
createCircuitDeviceRowInsertProjectCommand,
|
||||
} from "../src/domain/models/circuit-device-row-structure-project-command.model.js";
|
||||
import {
|
||||
assertCircuitInsertProjectCommand,
|
||||
createCircuitDeleteProjectCommand,
|
||||
createCircuitInsertProjectCommand,
|
||||
} from "../src/domain/models/circuit-structure-project-command.model.js";
|
||||
|
||||
describe("serialized project commands", () => {
|
||||
it("round-trips a versioned command envelope", () => {
|
||||
@@ -240,3 +245,102 @@ describe("circuit device-row structure project commands", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("circuit structure project commands", () => {
|
||||
const row = {
|
||||
id: "row-1",
|
||||
circuitId: "circuit-1",
|
||||
linkedProjectDeviceId: null,
|
||||
legacyConsumerId: null,
|
||||
sortOrder: 10,
|
||||
name: "Leuchte",
|
||||
displayName: "Leuchte",
|
||||
phaseType: "single_phase",
|
||||
connectionKind: null,
|
||||
costGroup: null,
|
||||
category: "lighting",
|
||||
level: null,
|
||||
roomId: null,
|
||||
roomNumberSnapshot: null,
|
||||
roomNameSnapshot: null,
|
||||
quantity: 1,
|
||||
powerPerUnit: 0.1,
|
||||
simultaneityFactor: 1,
|
||||
cosPhi: null,
|
||||
remark: null,
|
||||
overriddenFields: null,
|
||||
};
|
||||
const circuit = {
|
||||
id: "circuit-1",
|
||||
circuitListId: "list-1",
|
||||
sectionId: "section-1",
|
||||
equipmentIdentifier: "-1F1",
|
||||
displayName: "Beleuchtung",
|
||||
sortOrder: 10,
|
||||
protectionType: null,
|
||||
protectionRatedCurrent: null,
|
||||
protectionCharacteristic: null,
|
||||
cableType: null,
|
||||
cableCrossSection: null,
|
||||
cableLength: null,
|
||||
rcdAssignment: null,
|
||||
terminalDesignation: null,
|
||||
voltage: 230,
|
||||
controlRequirement: "DALI",
|
||||
status: null,
|
||||
isReserve: false,
|
||||
remark: null,
|
||||
deviceRows: [row],
|
||||
};
|
||||
|
||||
it("captures complete circuit blocks and delete identities", () => {
|
||||
const insert = createCircuitInsertProjectCommand(circuit);
|
||||
const remove = createCircuitDeleteProjectCommand(
|
||||
circuit.id,
|
||||
circuit.circuitListId
|
||||
);
|
||||
assert.deepEqual(insert.payload.circuit, circuit);
|
||||
assert.deepEqual(remove.payload, {
|
||||
circuitId: "circuit-1",
|
||||
expectedCircuitListId: "list-1",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects inconsistent reserve state, row ownership and duplicate ids", () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
createCircuitInsertProjectCommand({
|
||||
...circuit,
|
||||
isReserve: true,
|
||||
}),
|
||||
/reserve state/
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
createCircuitInsertProjectCommand({
|
||||
...circuit,
|
||||
deviceRows: [{ ...row, circuitId: "other-circuit" }],
|
||||
}),
|
||||
/different circuit/
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
createCircuitInsertProjectCommand({
|
||||
...circuit,
|
||||
deviceRows: [row, { ...row }],
|
||||
}),
|
||||
/duplicate row ids/
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
assertCircuitInsertProjectCommand({
|
||||
schemaVersion: 1,
|
||||
type: "circuit.insert",
|
||||
payload: {
|
||||
circuit: { ...circuit, equipmentIdentifier: "" },
|
||||
},
|
||||
}),
|
||||
/equipmentIdentifier/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user