Add component update commands
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user