Add project device update history

This commit is contained in:
2026-07-24 08:57:57 +02:00
parent 2668fc2f16
commit 0bc6c7372f
14 changed files with 785 additions and 13 deletions
+60
View File
@@ -42,6 +42,10 @@ import {
createProjectDeviceRowSyncProjectCommand,
type ProjectDeviceSyncRowSnapshot,
} from "../src/domain/models/project-device-row-sync-project-command.model.js";
import {
assertProjectDeviceUpdateProjectCommand,
createProjectDeviceUpdateProjectCommand,
} from "../src/domain/models/project-device-project-command.model.js";
describe("serialized project commands", () => {
it("round-trips a versioned command envelope", () => {
@@ -293,6 +297,62 @@ describe("project-device row sync project commands", () => {
});
});
describe("project-device update project commands", () => {
it("creates typed canonical field changes with null clearing", () => {
const command = createProjectDeviceUpdateProjectCommand(
"project-device-1",
{
displayName: "Flurbeleuchtung",
cosPhi: null,
voltageV: 230,
}
);
assert.doesNotThrow(() =>
assertProjectDeviceUpdateProjectCommand(command)
);
assert.deepEqual(command.payload.changes, [
{ field: "displayName", value: "Flurbeleuchtung" },
{ field: "cosPhi", value: null },
{ field: "voltageV", value: 230 },
]);
});
it("rejects empty, duplicate and invalid canonical values", () => {
assert.throws(
() =>
createProjectDeviceUpdateProjectCommand(
"project-device-1",
{}
),
/at least one change/
);
assert.throws(
() =>
assertProjectDeviceUpdateProjectCommand({
schemaVersion: 1,
type: "project-device.update",
payload: {
projectDeviceId: "project-device-1",
changes: [
{ field: "quantity", value: 1 },
{ field: "quantity", value: 2 },
],
},
}),
/duplicate field/
);
assert.throws(
() =>
createProjectDeviceUpdateProjectCommand(
"project-device-1",
{ simultaneityFactor: 1.1 }
),
/outside its allowed range/
);
});
});
describe("circuit device-row structure project commands", () => {
const row = {
id: "row-1",