Add project device sync history

This commit is contained in:
2026-07-24 08:47:25 +02:00
parent 4b4603b71b
commit 2668fc2f16
14 changed files with 1180 additions and 21 deletions
+102
View File
@@ -37,6 +37,11 @@ import {
assertCircuitSectionRenumberProjectCommand,
createCircuitSectionRenumberProjectCommand,
} from "../src/domain/models/circuit-section-renumber-project-command.model.js";
import {
assertProjectDeviceRowSyncProjectCommand,
createProjectDeviceRowSyncProjectCommand,
type ProjectDeviceSyncRowSnapshot,
} from "../src/domain/models/project-device-row-sync-project-command.model.js";
describe("serialized project commands", () => {
it("round-trips a versioned command envelope", () => {
@@ -191,6 +196,103 @@ describe("circuit device-row update project commands", () => {
});
});
describe("project-device row sync project commands", () => {
const linkedSnapshot: ProjectDeviceSyncRowSnapshot = {
linkedProjectDeviceId: "project-device-1",
name: "Leuchte",
displayName: "Lokaler Name",
phaseType: "single_phase",
connectionKind: null,
costGroup: null,
category: "lighting",
quantity: 1,
powerPerUnit: 0.1,
simultaneityFactor: 1,
cosPhi: 0.9,
remark: null,
overriddenFields: '["displayName"]',
};
it("captures complete expected and target snapshots for synchronization", () => {
const command = createProjectDeviceRowSyncProjectCommand(
"project-device-1",
"synchronize",
[
{
rowId: "row-1",
expected: linkedSnapshot,
target: {
...linkedSnapshot,
displayName: "Projektgerät",
overriddenFields: null,
},
},
]
);
assert.doesNotThrow(() =>
assertProjectDeviceRowSyncProjectCommand(command)
);
assert.equal(
command.payload.rows[0]?.target.displayName,
"Projektgerät"
);
});
it("permits link-only disconnects and rejects invalid sync transitions", () => {
assert.doesNotThrow(() =>
createProjectDeviceRowSyncProjectCommand(
"project-device-1",
"disconnect",
[
{
rowId: "row-1",
expected: linkedSnapshot,
target: {
...linkedSnapshot,
linkedProjectDeviceId: null,
},
},
]
)
);
assert.throws(
() =>
createProjectDeviceRowSyncProjectCommand(
"project-device-1",
"disconnect",
[
{
rowId: "row-1",
expected: linkedSnapshot,
target: {
...linkedSnapshot,
linkedProjectDeviceId: null,
quantity: 2,
},
},
]
),
/must not change local row values/
);
assert.throws(
() =>
createProjectDeviceRowSyncProjectCommand(
"project-device-1",
"synchronize",
[
{
rowId: "row-1",
expected: linkedSnapshot,
target: linkedSnapshot,
},
]
),
/no-op row/
);
});
});
describe("circuit device-row structure project commands", () => {
const row = {
id: "row-1",