Add project device structure history
This commit is contained in:
@@ -46,6 +46,10 @@ import {
|
||||
assertProjectDeviceUpdateProjectCommand,
|
||||
createProjectDeviceUpdateProjectCommand,
|
||||
} from "../src/domain/models/project-device-project-command.model.js";
|
||||
import {
|
||||
createProjectDeviceDeleteProjectCommand,
|
||||
createProjectDeviceInsertProjectCommand,
|
||||
} from "../src/domain/models/project-device-structure-project-command.model.js";
|
||||
|
||||
describe("serialized project commands", () => {
|
||||
it("round-trips a versioned command envelope", () => {
|
||||
@@ -353,6 +357,89 @@ describe("project-device update project commands", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("project-device structure project commands", () => {
|
||||
const projectDevice = {
|
||||
id: "project-device-1",
|
||||
projectId: "project-1",
|
||||
name: "Luminaire",
|
||||
displayName: "Office lighting",
|
||||
phaseType: "single_phase" as const,
|
||||
connectionKind: "fixed",
|
||||
costGroup: "440",
|
||||
category: "lighting",
|
||||
quantity: 4,
|
||||
powerPerUnit: 0.04,
|
||||
simultaneityFactor: 0.8,
|
||||
cosPhi: 0.95,
|
||||
remark: "DALI",
|
||||
voltageV: 230,
|
||||
};
|
||||
const disconnectedRow = {
|
||||
id: "row-1",
|
||||
circuitId: "circuit-1",
|
||||
linkedProjectDeviceId: null,
|
||||
legacyConsumerId: null,
|
||||
sortOrder: 10,
|
||||
name: "Luminaire",
|
||||
displayName: "Local lighting",
|
||||
phaseType: "single_phase",
|
||||
connectionKind: "fixed",
|
||||
costGroup: "440",
|
||||
category: "lighting",
|
||||
level: null,
|
||||
roomId: null,
|
||||
roomNumberSnapshot: null,
|
||||
roomNameSnapshot: null,
|
||||
quantity: 4,
|
||||
powerPerUnit: 0.04,
|
||||
simultaneityFactor: 0.8,
|
||||
cosPhi: 0.95,
|
||||
remark: "DALI",
|
||||
overriddenFields: '["displayName"]',
|
||||
};
|
||||
|
||||
it("captures complete device and disconnected-row restore snapshots", () => {
|
||||
const insert = createProjectDeviceInsertProjectCommand(
|
||||
projectDevice,
|
||||
[disconnectedRow]
|
||||
);
|
||||
const remove = createProjectDeviceDeleteProjectCommand(
|
||||
projectDevice.id,
|
||||
projectDevice.projectId
|
||||
);
|
||||
|
||||
assert.deepEqual(insert.payload, {
|
||||
projectDevice,
|
||||
linkedRows: [disconnectedRow],
|
||||
});
|
||||
assert.deepEqual(remove.payload, {
|
||||
projectDeviceId: "project-device-1",
|
||||
expectedProjectId: "project-1",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects invalid device values and rows that are already linked", () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
createProjectDeviceInsertProjectCommand({
|
||||
...projectDevice,
|
||||
quantity: -1,
|
||||
}),
|
||||
/outside its allowed range/
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
createProjectDeviceInsertProjectCommand(projectDevice, [
|
||||
{
|
||||
...disconnectedRow,
|
||||
linkedProjectDeviceId: "project-device-1",
|
||||
},
|
||||
]),
|
||||
/must currently be disconnected/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("circuit device-row structure project commands", () => {
|
||||
const row = {
|
||||
id: "row-1",
|
||||
|
||||
Reference in New Issue
Block a user