Add explicit "no protection device" state for circuits

Circuits can now record that they deliberately have no protection device
(type NONE, shown as "–"), separate from circuits whose protection is
still open. Migration 0017 makes rated_current_a nullable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian Appel 2026-10-30 13:11:28 +01:00
parent 1f3b903809
commit 38019fe087
27 changed files with 3673 additions and 132 deletions

View file

@ -135,6 +135,70 @@ describe("circuit-protection project command", () => {
}
});
it("stores an explicit no-protection decision and undoes it to the device", () => {
const context = createTestDatabase();
try {
const repository = new CircuitProtectionProjectCommandRepository(
context.db
);
const history = new ProjectHistoryRepository(context.db);
context.db.insert(circuitProtectionDevices).values(protection).run();
const none: CircuitProtectionSnapshot = {
circuitId: "circuit-1",
type: "NONE",
ratedCurrentA: null,
fuseUtilizationCategory: null,
tripCharacteristic: null,
rcdType: null,
ratedResidualCurrentMa: null,
};
const executed = repository.execute({
projectId: "project-1",
expectedRevision: 0,
source: "user",
command: createCircuitProtectionUpdateProjectCommand(
"circuit-1",
protection,
none
),
});
assert.deepEqual(
context.db.select().from(circuitProtectionDevices).get(),
none
);
const undo = history.getNextCommand("project-1", "undo");
assert.ok(undo);
repository.execute({
projectId: "project-1",
expectedRevision: 1,
source: "undo",
historyTargetChangeSetId: undo.changeSetId,
command: executed.inverse,
});
assert.deepEqual(
context.db.select().from(circuitProtectionDevices).get(),
protection
);
for (const invalid of [
{ ...none, ratedCurrentA: 16 },
{ ...none, tripCharacteristic: "B" as const },
{ ...protection, ratedCurrentA: null },
]) {
assert.throws(
() =>
createCircuitProtectionUpdateProjectCommand(
"circuit-1",
protection,
invalid
),
/configuration is invalid/
);
}
} finally {
context.close();
}
});
it("rejects stale state, foreign ownership and user removal", () => {
const context = createTestDatabase();
try {