131 lines
4.0 KiB
TypeScript
131 lines
4.0 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import type {
|
|
LegacyConsumerMigrationDependencies,
|
|
LegacyMigrationCircuitInput,
|
|
LegacyMigrationReportInput,
|
|
} from "../src/domain/ports/legacy-consumer-migration.store.js";
|
|
import { LegacyConsumerMigrationService } from "../src/domain/services/legacy-consumer-migration.service.js";
|
|
|
|
describe("legacy consumer migration service", () => {
|
|
it("plans the migration through injected readers and persists one complete batch", async () => {
|
|
let defaultsCreatedFor: string | null = null;
|
|
let persisted:
|
|
| {
|
|
circuitListId: string;
|
|
circuits: LegacyMigrationCircuitInput[];
|
|
report: LegacyMigrationReportInput;
|
|
}
|
|
| undefined;
|
|
const dependencies: LegacyConsumerMigrationDependencies = {
|
|
circuitListReader: {
|
|
async findById(projectId, circuitListId) {
|
|
assert.equal(projectId, "project-1");
|
|
assert.equal(circuitListId, "list-1");
|
|
return { id: circuitListId };
|
|
},
|
|
},
|
|
sectionStore: {
|
|
async createDefaults(circuitListId) {
|
|
defaultsCreatedFor = circuitListId;
|
|
},
|
|
async listByCircuitList() {
|
|
return [
|
|
{ id: "section-1", key: "single_phase", prefix: "-2F" },
|
|
{ id: "section-2", key: "unassigned", prefix: "-XF" },
|
|
];
|
|
},
|
|
},
|
|
circuitReader: {
|
|
async listByCircuitList() {
|
|
return [
|
|
{
|
|
sectionId: "section-1",
|
|
equipmentIdentifier: "-2F2",
|
|
sortOrder: 10,
|
|
},
|
|
];
|
|
},
|
|
},
|
|
roomReader: {
|
|
async listByProject() {
|
|
return [
|
|
{ id: "room-1", roomNumber: "1.01", roomName: "Besprechung" },
|
|
];
|
|
},
|
|
},
|
|
migrationStore: {
|
|
async listSourceConsumersByCircuitList() {
|
|
return [
|
|
{
|
|
id: "consumer-1",
|
|
projectDeviceId: null,
|
|
roomId: "room-1",
|
|
circuitNumber: null,
|
|
description: "Steckdosen Besprechung",
|
|
name: "Steckdose",
|
|
category: null,
|
|
deviceType: null,
|
|
phaseType: null,
|
|
tradeOrCostGroup: "KG 440",
|
|
protectionType: null,
|
|
protectionRatedCurrent: null,
|
|
protectionCharacteristic: null,
|
|
cableType: null,
|
|
cableCrossSection: null,
|
|
comment: null,
|
|
quantity: 2,
|
|
installedPowerPerUnitKw: 0.2,
|
|
demandFactor: 0.8,
|
|
voltageV: 230,
|
|
phaseCount: 1,
|
|
powerFactor: 0.95,
|
|
note: "Bestand",
|
|
},
|
|
];
|
|
},
|
|
async listMigratedConsumerIds() {
|
|
return [];
|
|
},
|
|
persistCircuitListMigration(input) {
|
|
persisted = input;
|
|
},
|
|
},
|
|
};
|
|
|
|
const report = await new LegacyConsumerMigrationService(
|
|
dependencies
|
|
).migrateCircuitList("project-1", "list-1");
|
|
|
|
assert.equal(defaultsCreatedFor, "list-1");
|
|
assert.deepEqual(report.generatedIdentifiers, ["-2F3"]);
|
|
assert.equal(report.createdCircuitCount, 1);
|
|
assert.equal(report.createdDeviceRowCount, 1);
|
|
assert.equal(persisted?.circuitListId, "list-1");
|
|
assert.equal(persisted?.circuits[0].circuit.sectionId, "section-1");
|
|
assert.equal(
|
|
persisted?.circuits[0].circuit.equipmentIdentifier,
|
|
"-2F3"
|
|
);
|
|
assert.deepEqual(persisted?.circuits[0].deviceRows[0], {
|
|
linkedProjectDeviceId: undefined,
|
|
legacyConsumerId: "consumer-1",
|
|
sortOrder: 10,
|
|
name: "Steckdose",
|
|
displayName: "Steckdosen Besprechung",
|
|
phaseType: undefined,
|
|
connectionKind: undefined,
|
|
costGroup: "KG 440",
|
|
category: undefined,
|
|
roomId: "room-1",
|
|
roomNumberSnapshot: "1.01",
|
|
roomNameSnapshot: "Besprechung",
|
|
quantity: 2,
|
|
powerPerUnit: 0.2,
|
|
simultaneityFactor: 0.8,
|
|
cosPhi: 0.95,
|
|
remark: "Bestand",
|
|
});
|
|
});
|
|
});
|