106 lines
2.8 KiB
TypeScript
106 lines
2.8 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import {
|
|
formatGroupedCircuitIdentifier,
|
|
formatGroupRcdIdentifier,
|
|
formatGroupUpstreamProtectionIdentifier,
|
|
getNextCircuitGroupNumber,
|
|
getNextGroupedCircuitIdentifier,
|
|
parseGroupedEquipmentIdentifier,
|
|
} from "../src/domain/services/circuit-group-numbering.js";
|
|
import "./circuit-group-structure-project-command.repository.test.js";
|
|
|
|
describe("circuit group numbering", () => {
|
|
it("formats the agreed identifiers including the leading hyphen", () => {
|
|
assert.equal(
|
|
formatGroupUpstreamProtectionIdentifier("lighting", 1),
|
|
"-1F1.0"
|
|
);
|
|
assert.equal(formatGroupRcdIdentifier("lighting", 1), "-1Q1.0");
|
|
assert.equal(
|
|
formatGroupedCircuitIdentifier("lighting", 1, 2),
|
|
"-1F1.2"
|
|
);
|
|
assert.equal(
|
|
formatGroupedCircuitIdentifier("single_phase", 3, 7),
|
|
"-2F3.7"
|
|
);
|
|
assert.equal(
|
|
formatGroupedCircuitIdentifier("three_phase", 2, 1),
|
|
"-3F2.1"
|
|
);
|
|
});
|
|
|
|
it("parses circuit and group component identifiers", () => {
|
|
assert.deepEqual(parseGroupedEquipmentIdentifier("-1F2.4"), {
|
|
category: "lighting",
|
|
groupNumber: 2,
|
|
kind: "circuit",
|
|
circuitNumber: 4,
|
|
});
|
|
assert.deepEqual(parseGroupedEquipmentIdentifier("-2F3.0"), {
|
|
category: "single_phase",
|
|
groupNumber: 3,
|
|
kind: "group_upstream_protection",
|
|
circuitNumber: null,
|
|
});
|
|
assert.deepEqual(parseGroupedEquipmentIdentifier("-3Q1.0"), {
|
|
category: "three_phase",
|
|
groupNumber: 1,
|
|
kind: "group_rcd",
|
|
circuitNumber: null,
|
|
});
|
|
});
|
|
|
|
it("rejects legacy, malformed and unsupported identifiers", () => {
|
|
for (const identifier of [
|
|
"-1F1",
|
|
"1F1.1",
|
|
"-1Q1.2",
|
|
"-4F1.1",
|
|
"-1F0.1",
|
|
"-1F1.01",
|
|
]) {
|
|
assert.equal(parseGroupedEquipmentIdentifier(identifier), null);
|
|
}
|
|
});
|
|
|
|
it("uses the highest target-group suffix plus one without filling gaps", () => {
|
|
assert.equal(
|
|
getNextGroupedCircuitIdentifier("lighting", 2, [
|
|
"-1F2.1",
|
|
"-1F2.3",
|
|
"-1F2.7",
|
|
"-1F1.12",
|
|
"-2F2.9",
|
|
"-1F2.0",
|
|
"-1Q2.0",
|
|
"-1F8",
|
|
]),
|
|
"-1F2.8"
|
|
);
|
|
});
|
|
|
|
it("uses the highest group number in the selected category plus one", () => {
|
|
assert.equal(
|
|
getNextCircuitGroupNumber("lighting", [
|
|
{ category: "lighting", groupNumber: 1 },
|
|
{ category: "lighting", groupNumber: 4 },
|
|
{ category: "single_phase", groupNumber: 9 },
|
|
]),
|
|
5
|
|
);
|
|
});
|
|
|
|
it("rejects non-positive group and circuit numbers", () => {
|
|
assert.throws(
|
|
() => formatGroupedCircuitIdentifier("lighting", 0, 1),
|
|
RangeError
|
|
);
|
|
assert.throws(
|
|
() => formatGroupedCircuitIdentifier("lighting", 1, 0),
|
|
RangeError
|
|
);
|
|
});
|
|
});
|