Add project device sync history
This commit is contained in:
@@ -16,10 +16,12 @@ import { CircuitSectionRenumberProjectCommandRepository } from "../src/db/reposi
|
||||
import { CircuitStructureProjectCommandRepository } from "../src/db/repositories/circuit-structure-project-command.repository.js";
|
||||
import { DistributionBoardRepository } from "../src/db/repositories/distribution-board.repository.js";
|
||||
import { ProjectHistoryRepository } from "../src/db/repositories/project-history.repository.js";
|
||||
import { ProjectDeviceRowSyncProjectCommandRepository } from "../src/db/repositories/project-device-row-sync-project-command.repository.js";
|
||||
import { circuitDeviceRows } from "../src/db/schema/circuit-device-rows.js";
|
||||
import { circuitSections } from "../src/db/schema/circuit-sections.js";
|
||||
import { circuits } from "../src/db/schema/circuits.js";
|
||||
import { projectChangeSets } from "../src/db/schema/project-change-sets.js";
|
||||
import { projectDevices } from "../src/db/schema/project-devices.js";
|
||||
import { projectRevisions } from "../src/db/schema/project-revisions.js";
|
||||
import { projects } from "../src/db/schema/projects.js";
|
||||
import { ProjectHistoryOperationUnavailableError } from "../src/domain/errors/project-history-operation-unavailable.error.js";
|
||||
@@ -34,6 +36,7 @@ import { createCircuitUpdateProjectCommand } from "../src/domain/models/circuit-
|
||||
import { createCircuitSectionReorderProjectCommand } from "../src/domain/models/circuit-section-reorder-project-command.model.js";
|
||||
import { createCircuitSectionRenumberProjectCommand } from "../src/domain/models/circuit-section-renumber-project-command.model.js";
|
||||
import { createCircuitInsertProjectCommand } from "../src/domain/models/circuit-structure-project-command.model.js";
|
||||
import { createProjectDeviceRowSyncProjectCommand } from "../src/domain/models/project-device-row-sync-project-command.model.js";
|
||||
import { ProjectCommandService } from "../src/domain/services/project-command.service.js";
|
||||
|
||||
function createTestDatabase(): DatabaseContext {
|
||||
@@ -90,6 +93,7 @@ function createService(context: DatabaseContext) {
|
||||
new CircuitStructureProjectCommandRepository(context.db),
|
||||
new CircuitSectionReorderProjectCommandRepository(context.db),
|
||||
new CircuitSectionRenumberProjectCommandRepository(context.db),
|
||||
new ProjectDeviceRowSyncProjectCommandRepository(context.db),
|
||||
new ProjectHistoryRepository(context.db)
|
||||
);
|
||||
}
|
||||
@@ -177,6 +181,91 @@ describe("project command service", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("dispatches project-device row synchronization and its inverse", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
context.db
|
||||
.insert(projectDevices)
|
||||
.values({
|
||||
id: "project-device-1",
|
||||
projectId: "project-1",
|
||||
name: "Luminaire",
|
||||
displayName: "Office lighting",
|
||||
phaseType: "single_phase",
|
||||
quantity: 4,
|
||||
powerPerUnit: 0.04,
|
||||
simultaneityFactor: 0.8,
|
||||
})
|
||||
.run();
|
||||
context.db
|
||||
.update(circuitDeviceRows)
|
||||
.set({
|
||||
linkedProjectDeviceId: "project-device-1",
|
||||
overriddenFields: '["displayName"]',
|
||||
})
|
||||
.where(eq(circuitDeviceRows.id, "row-1"))
|
||||
.run();
|
||||
const expected = {
|
||||
linkedProjectDeviceId: "project-device-1",
|
||||
name: "Leuchte",
|
||||
displayName: "Leuchte",
|
||||
phaseType: null,
|
||||
connectionKind: null,
|
||||
costGroup: null,
|
||||
category: null,
|
||||
quantity: 1,
|
||||
powerPerUnit: 0.1,
|
||||
simultaneityFactor: 1,
|
||||
cosPhi: null,
|
||||
remark: null,
|
||||
overriddenFields: '["displayName"]',
|
||||
};
|
||||
const service = createService(context);
|
||||
const synchronized = service.executeUser({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 0,
|
||||
command: createProjectDeviceRowSyncProjectCommand(
|
||||
"project-device-1",
|
||||
"synchronize",
|
||||
[
|
||||
{
|
||||
rowId: "row-1",
|
||||
expected,
|
||||
target: {
|
||||
...expected,
|
||||
name: "Luminaire",
|
||||
displayName: "Office lighting",
|
||||
quantity: 4,
|
||||
powerPerUnit: 0.04,
|
||||
simultaneityFactor: 0.8,
|
||||
overriddenFields: null,
|
||||
},
|
||||
},
|
||||
]
|
||||
),
|
||||
});
|
||||
assert.equal(synchronized.history.undoDepth, 1);
|
||||
assert.equal(getRowQuantity(context), 4);
|
||||
|
||||
const undone = createService(context).undo({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 1,
|
||||
});
|
||||
assert.equal(undone.history.redoDepth, 1);
|
||||
assert.equal(getRowQuantity(context), 1);
|
||||
assert.equal(
|
||||
context.db
|
||||
.select()
|
||||
.from(circuitDeviceRows)
|
||||
.where(eq(circuitDeviceRows.id, "row-1"))
|
||||
.get()?.overriddenFields,
|
||||
'["displayName"]'
|
||||
);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects stale undo and preserves the domain value and stack", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user