forked from jappel/leistungsbilanz-ts
Protect referenced feeder structures from deletion
This commit is contained in:
parent
b893c72534
commit
855a04e655
13 changed files with 369 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ import { circuitSections } from "../src/db/schema/circuit-sections.js";
|
|||
import { circuits } from "../src/db/schema/circuits.js";
|
||||
import { distributionBoardComponentProtectionDevices } from "../src/db/schema/distribution-board-component-protection-devices.js";
|
||||
import { distributionBoardComponents } from "../src/db/schema/distribution-board-components.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 { createCircuitGroupDeleteSubtreeProjectCommand } from "../src/domain/models/circuit-group-subtree-project-command.model.js";
|
||||
|
|
@ -228,6 +229,45 @@ describe("circuit-group subtree project command", () => {
|
|||
}
|
||||
});
|
||||
|
||||
it("blocks deleting a group containing a feeding circuit", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const list = context.db.select().from(circuitLists).get()!;
|
||||
const downstream = new DistributionBoardFixtureRepository(
|
||||
context.db
|
||||
).createWithCircuitListAndDefaultSections("project-1", "Unterverteiler");
|
||||
context.db
|
||||
.update(distributionBoards)
|
||||
.set({
|
||||
feedingDistributionBoardId: list.distributionBoardId,
|
||||
feedingCircuitId: "subtree-circuit",
|
||||
})
|
||||
.where(eq(distributionBoards.id, downstream.id))
|
||||
.run();
|
||||
const repository =
|
||||
new CircuitGroupSubtreeProjectCommandRepository(context.db);
|
||||
const groupId = context.db
|
||||
.select()
|
||||
.from(circuits)
|
||||
.where(eq(circuits.id, "subtree-circuit"))
|
||||
.get()!.sectionId;
|
||||
const snapshot = repository.capture("project-1", groupId);
|
||||
|
||||
assert.throws(
|
||||
() => repository.execute({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 0,
|
||||
source: "user",
|
||||
command: createCircuitGroupDeleteSubtreeProjectCommand(snapshot),
|
||||
}),
|
||||
/Speist Unterverteiler – erst Einspeisung ändern\./
|
||||
);
|
||||
assert.deepEqual(repository.capture("project-1", groupId), snapshot);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("rolls back a cascaded deletion when history persistence fails", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue