Plan circuit group renumbering
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
parseGroupedEquipmentIdentifier,
|
||||
} from "../src/domain/services/circuit-group-numbering.js";
|
||||
import "./circuit-group-structure-project-command.repository.test.js";
|
||||
import { createCircuitGroupRenumberPlan } from "../src/domain/services/circuit-group-renumbering.js";
|
||||
|
||||
describe("circuit group numbering", () => {
|
||||
it("formats the agreed identifiers including the leading hyphen", () => {
|
||||
@@ -103,3 +104,138 @@ describe("circuit group numbering", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("circuit group renumber planning", () => {
|
||||
const groups = [
|
||||
{
|
||||
id: "lighting-1",
|
||||
category: "lighting" as const,
|
||||
groupNumber: 1,
|
||||
prefix: "-1F1.",
|
||||
circuits: [
|
||||
{ id: "circuit-1", equipmentIdentifier: "-1F1.1" },
|
||||
{ id: "circuit-2", equipmentIdentifier: "-1F1.7" },
|
||||
],
|
||||
components: [
|
||||
{
|
||||
id: "fuse-1",
|
||||
role: "group_upstream_protection" as const,
|
||||
equipmentIdentifier: "-1F1.0",
|
||||
},
|
||||
{
|
||||
id: "rcd-1",
|
||||
role: "group_residual_current_protection" as const,
|
||||
equipmentIdentifier: "-1Q1.0",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "lighting-2",
|
||||
category: "lighting" as const,
|
||||
groupNumber: 2,
|
||||
prefix: "-1F2.",
|
||||
circuits: [
|
||||
{ id: "circuit-3", equipmentIdentifier: "-1F2.4" },
|
||||
],
|
||||
components: [],
|
||||
},
|
||||
{
|
||||
id: "single-1",
|
||||
category: "single_phase" as const,
|
||||
groupNumber: 1,
|
||||
prefix: "-2F1.",
|
||||
circuits: [],
|
||||
components: [],
|
||||
},
|
||||
];
|
||||
|
||||
it("preserves circuit suffixes and maps optional group components", () => {
|
||||
const plan = createCircuitGroupRenumberPlan(groups, [
|
||||
{ groupId: "lighting-1", targetGroupNumber: 3 },
|
||||
]);
|
||||
assert.deepEqual(plan.groups[0], {
|
||||
groupId: "lighting-1",
|
||||
category: "lighting",
|
||||
expectedGroupNumber: 1,
|
||||
targetGroupNumber: 3,
|
||||
expectedPrefix: "-1F1.",
|
||||
targetPrefix: "-1F3.",
|
||||
circuits: [
|
||||
{
|
||||
circuitId: "circuit-1",
|
||||
expectedEquipmentIdentifier: "-1F1.1",
|
||||
targetEquipmentIdentifier: "-1F3.1",
|
||||
},
|
||||
{
|
||||
circuitId: "circuit-2",
|
||||
expectedEquipmentIdentifier: "-1F1.7",
|
||||
targetEquipmentIdentifier: "-1F3.7",
|
||||
},
|
||||
],
|
||||
components: [
|
||||
{
|
||||
componentId: "fuse-1",
|
||||
expectedEquipmentIdentifier: "-1F1.0",
|
||||
targetEquipmentIdentifier: "-1F3.0",
|
||||
},
|
||||
{
|
||||
componentId: "rcd-1",
|
||||
expectedEquipmentIdentifier: "-1Q1.0",
|
||||
targetEquipmentIdentifier: "-1Q3.0",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("allows a number swap when every affected group participates", () => {
|
||||
const plan = createCircuitGroupRenumberPlan(groups, [
|
||||
{ groupId: "lighting-1", targetGroupNumber: 2 },
|
||||
{ groupId: "lighting-2", targetGroupNumber: 1 },
|
||||
]);
|
||||
assert.deepEqual(
|
||||
plan.groups.map((group) => [
|
||||
group.expectedGroupNumber,
|
||||
group.targetGroupNumber,
|
||||
]),
|
||||
[
|
||||
[1, 2],
|
||||
[2, 1],
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects collisions, no-op requests and mismatched current BMKs", () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
createCircuitGroupRenumberPlan(groups, [
|
||||
{ groupId: "lighting-1", targetGroupNumber: 2 },
|
||||
]),
|
||||
/unchanged group/
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
createCircuitGroupRenumberPlan(groups, [
|
||||
{ groupId: "lighting-1", targetGroupNumber: 1 },
|
||||
]),
|
||||
/must change/
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
createCircuitGroupRenumberPlan(
|
||||
[
|
||||
{
|
||||
...groups[0],
|
||||
circuits: [
|
||||
{
|
||||
id: "circuit-1",
|
||||
equipmentIdentifier: "-1F9.1",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
[{ groupId: "lighting-1", targetGroupNumber: 3 }]
|
||||
),
|
||||
/Circuit BMK does not match/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user