Protect referenced feeder structures from deletion
This commit is contained in:
parent
b893c72534
commit
855a04e655
13 changed files with 369 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ import { circuitDeviceRows } from "../src/db/schema/circuit-device-rows.js";
|
|||
import { circuitProtectionDevices } from "../src/db/schema/circuit-protection-devices.js";
|
||||
import { circuitSections } from "../src/db/schema/circuit-sections.js";
|
||||
import { circuits } from "../src/db/schema/circuits.js";
|
||||
import { distributionBoards } from "../src/db/schema/distribution-boards.js";
|
||||
import { projectRevisions } from "../src/db/schema/project-revisions.js";
|
||||
import { projects } from "../src/db/schema/projects.js";
|
||||
import {
|
||||
|
|
@ -611,6 +612,62 @@ describe("circuit device-row move project-command repository", () => {
|
|||
}
|
||||
});
|
||||
|
||||
it("blocks undo from removing a generated circuit used as a feeder", () => {
|
||||
const fixture = createTestDatabase();
|
||||
try {
|
||||
const store = new CircuitDeviceRowMoveProjectCommandRepository(
|
||||
fixture.context.db
|
||||
);
|
||||
const targetCircuit = createMoveTargetSnapshot(fixture);
|
||||
const command = createCircuitDeviceRowMoveWithNewCircuitProjectCommand(
|
||||
"create",
|
||||
targetCircuit,
|
||||
[{
|
||||
rowId: "row-1",
|
||||
expectedCircuitId: "circuit-1",
|
||||
expectedSortOrder: 10,
|
||||
targetCircuitId: targetCircuit.id,
|
||||
targetSortOrder: 10,
|
||||
}]
|
||||
);
|
||||
const moved = store.execute({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 0,
|
||||
source: "user",
|
||||
command,
|
||||
});
|
||||
const downstream = new DistributionBoardFixtureRepository(
|
||||
fixture.context.db
|
||||
).createWithCircuitListAndDefaultSections("project-1", "UV-02");
|
||||
fixture.context.db
|
||||
.update(distributionBoards)
|
||||
.set({
|
||||
feedingDistributionBoardId: fixture.circuitListId,
|
||||
feedingCircuitId: targetCircuit.id,
|
||||
})
|
||||
.where(eq(distributionBoards.id, downstream.id))
|
||||
.run();
|
||||
|
||||
assert.throws(
|
||||
() => store.execute({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 1,
|
||||
source: "undo",
|
||||
historyTargetChangeSetId: moved.revision.changeSetId,
|
||||
command: moved.inverse,
|
||||
}),
|
||||
/Speist UV-02 – erst Einspeisung ändern\./
|
||||
);
|
||||
assert.equal(getRow(fixture.context, "row-1")?.circuitId, targetCircuit.id);
|
||||
assert.ok(
|
||||
fixture.context.db.select().from(circuits)
|
||||
.where(eq(circuits.id, targetCircuit.id)).get()
|
||||
);
|
||||
} finally {
|
||||
fixture.context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects deletion when the created target changed outside history", () => {
|
||||
const fixture = createTestDatabase();
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue