Add component update commands

This commit is contained in:
2026-07-30 19:42:09 +02:00
parent 604604f056
commit 69b020339e
11 changed files with 547 additions and 21 deletions
+87 -1
View File
@@ -51,7 +51,10 @@ import {
createDistributionBoardInsertProjectCommand,
createDistributionBoardStructureSnapshot,
} from "../src/domain/models/distribution-board-structure-project-command.model.js";
import { createDistributionBoardComponentInsertProjectCommand } from "../src/domain/models/distribution-board-component-structure-project-command.model.js";
import {
createDistributionBoardComponentInsertProjectCommand,
createDistributionBoardComponentUpdateProjectCommand,
} from "../src/domain/models/distribution-board-component-structure-project-command.model.js";
import {
createProjectFloorInsertProjectCommand,
createProjectFloorSnapshot,
@@ -1121,6 +1124,89 @@ describe("project command service", () => {
}
});
it("dispatches distribution-board component updates", () => {
const context = createTestDatabase();
try {
const service = createService(context);
const circuitListId = context.db
.select()
.from(circuitSections)
.get()!.circuitListId;
const expected = {
component: {
id: "component-service-update",
circuitListId,
sectionId: null,
equipmentIdentifier: "-K11",
name: "KNX Aktor",
role: "auxiliary" as const,
placement: "footer" as const,
sortOrder: 10,
},
protectionDevice: null,
};
const target = {
component: {
...expected.component,
name: "KNX Jalousieaktor",
sortOrder: 20,
},
protectionDevice: null,
};
service.executeUser({
projectId: "project-1",
expectedRevision: 0,
command:
createDistributionBoardComponentInsertProjectCommand(
expected
),
});
const updated = service.executeUser({
projectId: "project-1",
expectedRevision: 1,
command:
createDistributionBoardComponentUpdateProjectCommand(
expected,
target
),
});
assert.equal(updated.history.currentRevision, 2);
assert.equal(
context.db
.select()
.from(distributionBoardComponents)
.where(
eq(
distributionBoardComponents.id,
expected.component.id
)
)
.get()?.name,
target.component.name
);
createService(context).undo({
projectId: "project-1",
expectedRevision: 2,
});
assert.equal(
context.db
.select()
.from(distributionBoardComponents)
.where(
eq(
distributionBoardComponents.id,
expected.component.id
)
)
.get()?.name,
expected.component.name
);
} finally {
context.close();
}
});
it("dispatches floor and room setup with their persisted inverses", () => {
const context = createTestDatabase();
try {