Persist circuit group renumbering
This commit is contained in:
@@ -15,6 +15,7 @@ import { CircuitSectionReorderProjectCommandRepository } from "../src/db/reposit
|
||||
import { CircuitSectionRenumberProjectCommandRepository } from "../src/db/repositories/circuit-section-renumber-project-command.repository.js";
|
||||
import { CircuitStructureProjectCommandRepository } from "../src/db/repositories/circuit-structure-project-command.repository.js";
|
||||
import { CircuitGroupStructureProjectCommandRepository } from "../src/db/repositories/circuit-group-structure-project-command.repository.js";
|
||||
import { CircuitGroupRenumberProjectCommandRepository } from "../src/db/repositories/circuit-group-renumber-project-command.repository.js";
|
||||
import { DistributionBoardFixtureRepository } from "./support/distribution-board-fixture.js";
|
||||
import { DistributionBoardStructureProjectCommandRepository } from "../src/db/repositories/distribution-board-structure-project-command.repository.js";
|
||||
import { DistributionBoardComponentStructureProjectCommandRepository } from "../src/db/repositories/distribution-board-component-structure-project-command.repository.js";
|
||||
@@ -53,6 +54,8 @@ import {
|
||||
createCircuitGroupReorderProjectCommand,
|
||||
createCircuitGroupUpdateProjectCommand,
|
||||
} from "../src/domain/models/circuit-group-structure-project-command.model.js";
|
||||
import { createCircuitGroupRenumberProjectCommand } from "../src/domain/models/circuit-group-renumber-project-command.model.js";
|
||||
import { createCircuitGroupRenumberPlan } from "../src/domain/services/circuit-group-renumbering.js";
|
||||
import {
|
||||
createDistributionBoardInsertProjectCommand,
|
||||
createDistributionBoardStructureSnapshot,
|
||||
@@ -138,6 +141,7 @@ function createService(context: DatabaseContext) {
|
||||
context.db
|
||||
),
|
||||
new CircuitGroupStructureProjectCommandRepository(context.db),
|
||||
new CircuitGroupRenumberProjectCommandRepository(context.db),
|
||||
new ProjectHistoryRepository(context.db)
|
||||
);
|
||||
}
|
||||
@@ -1296,6 +1300,76 @@ describe("project command service", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("dispatches explicit circuit-group renumbering", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const service = createService(context);
|
||||
const existing = context.db
|
||||
.select()
|
||||
.from(circuitSections)
|
||||
.where(eq(circuitSections.category, "three_phase"))
|
||||
.get()!;
|
||||
const added = {
|
||||
id: "group-three-phase-2",
|
||||
circuitListId: existing.circuitListId,
|
||||
key: "three_phase_2",
|
||||
displayName: "3-phasig 2",
|
||||
prefix: "-3F2.",
|
||||
sortOrder: 40,
|
||||
category: "three_phase" as const,
|
||||
groupNumber: 2,
|
||||
};
|
||||
service.executeUser({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 0,
|
||||
command: createCircuitGroupInsertProjectCommand(added),
|
||||
});
|
||||
const plan = createCircuitGroupRenumberPlan(
|
||||
[
|
||||
{
|
||||
id: existing.id,
|
||||
category: "three_phase",
|
||||
groupNumber: 1,
|
||||
prefix: "-3F1.",
|
||||
circuits: [],
|
||||
components: [],
|
||||
},
|
||||
{
|
||||
id: added.id,
|
||||
category: "three_phase",
|
||||
groupNumber: 2,
|
||||
prefix: "-3F2.",
|
||||
circuits: [],
|
||||
components: [],
|
||||
},
|
||||
],
|
||||
[
|
||||
{ groupId: existing.id, targetGroupNumber: 2 },
|
||||
{ groupId: added.id, targetGroupNumber: 1 },
|
||||
]
|
||||
);
|
||||
const result = service.executeUser({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 1,
|
||||
command: createCircuitGroupRenumberProjectCommand(
|
||||
existing.circuitListId,
|
||||
plan
|
||||
),
|
||||
});
|
||||
assert.equal(result.history.currentRevision, 2);
|
||||
assert.equal(
|
||||
context.db
|
||||
.select()
|
||||
.from(circuitSections)
|
||||
.where(eq(circuitSections.id, existing.id))
|
||||
.get()?.prefix,
|
||||
"-3F2."
|
||||
);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("dispatches floor and room setup with their persisted inverses", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user