Derive project device phases from category

This commit is contained in:
2026-07-31 14:37:45 +02:00
parent 5fb81bab04
commit 1e3c721cfa
9 changed files with 101 additions and 80 deletions
+12 -21
View File
@@ -3,36 +3,27 @@ import { describe, it } from "node:test";
import {
inferProjectDeviceSectionKey,
isProjectDevicePlacementValid,
resolveProjectDevicePhaseType,
} from "../src/domain/services/project-device-placement.service.js";
describe("project device placement", () => {
it("routes lighting categories to the lighting section before phase classification", () => {
assert.equal(
inferProjectDeviceSectionKey({ category: "Lighting", phaseType: "three_phase" }),
"lighting"
);
assert.equal(
inferProjectDeviceSectionKey({ category: "Beleuchtung", phaseType: "single_phase" }),
"lighting"
);
});
it("routes non-lighting devices by phase type", () => {
assert.equal(
inferProjectDeviceSectionKey({ category: "Socket", phaseType: "single_phase" }),
"single_phase"
);
assert.equal(
inferProjectDeviceSectionKey({ category: "Motor", phaseType: "three_phase" }),
"three_phase"
);
it("routes project devices by their required category", () => {
assert.equal(inferProjectDeviceSectionKey({ category: "lighting" }), "lighting");
assert.equal(inferProjectDeviceSectionKey({ category: "single_phase" }), "single_phase");
assert.equal(inferProjectDeviceSectionKey({ category: "three_phase" }), "three_phase");
});
it("accepts only the inferred default section", () => {
const device = { category: "Motor", phaseType: "three_phase" as const };
const device = { category: "three_phase" as const };
assert.equal(isProjectDevicePlacementValid(device, { key: "three_phase" }), true);
assert.equal(isProjectDevicePlacementValid(device, { key: "single_phase" }), false);
assert.equal(isProjectDevicePlacementValid(device, { key: "unassigned" }), false);
});
it("derives the electrical phase type from the category", () => {
assert.equal(resolveProjectDevicePhaseType("lighting"), "single_phase");
assert.equal(resolveProjectDevicePhaseType("single_phase"), "single_phase");
assert.equal(resolveProjectDevicePhaseType("three_phase"), "three_phase");
});
});