Started multiline manipulations

This commit is contained in:
2026-05-05 21:20:09 +02:00
parent 47dec0df39
commit b1e19a88d5
10 changed files with 631 additions and 790 deletions
+108
View File
@@ -373,6 +373,114 @@ describe("circuit write service rules", () => {
assert.equal(createdCircuitPayload?.isReserve, false);
});
it("moving multiple device rows to a circuit preserves input order and toggles reserve", async () => {
const movedCalls: Array<{ rowId: string; targetCircuitId: string; sortOrder: number }> = [];
const reserveUpdates: Array<{ id: string; isReserve: boolean }> = [];
const service = new CircuitWriteService({
deviceRowRepository: {
async findById(rowId: string) {
if (rowId === "r1") {
return { id: "r1", circuitId: "c1" } as never;
}
return { id: "r2", circuitId: "c2" } as never;
},
async countByCircuit(circuitId: string) {
if (circuitId === "c3") {
return 1;
}
return 0;
},
async moveToCircuit(rowId: string, targetCircuitId: string, sortOrder: number) {
movedCalls.push({ rowId, targetCircuitId, sortOrder });
},
} as never,
circuitRepository: {
async findById(circuitId: string) {
if (circuitId === "c1") {
return { id: "c1", sectionId: "s1", circuitListId: "l1", equipmentIdentifier: "-1F1", sortOrder: 10, isReserve: 0 } as never;
}
if (circuitId === "c2") {
return { id: "c2", sectionId: "s1", circuitListId: "l1", equipmentIdentifier: "-1F2", sortOrder: 20, isReserve: 0 } as never;
}
return { id: "c3", sectionId: "s1", circuitListId: "l1", equipmentIdentifier: "-1F3", sortOrder: 30, isReserve: 1 } as never;
},
async update(id: string, payload: { isReserve: boolean }) {
reserveUpdates.push({ id, isReserve: payload.isReserve });
},
} as never,
});
await service.moveDeviceRowsBulk({ rowIds: ["r1", "r2"], targetCircuitId: "c3" });
assert.deepEqual(movedCalls, [
{ rowId: "r1", targetCircuitId: "c3", sortOrder: 20 },
{ rowId: "r2", targetCircuitId: "c3", sortOrder: 30 },
]);
assert.deepEqual(reserveUpdates, [
{ id: "c1", isReserve: true },
{ id: "c2", isReserve: true },
{ id: "c3", isReserve: false },
]);
});
it("moving multiple device rows to placeholder creates exactly one new circuit", async () => {
let createCount = 0;
const service = new CircuitWriteService({
deviceRowRepository: {
async findById(rowId: string) {
return { id: rowId, circuitId: rowId === "r1" ? "c1" : "c2" } as never;
},
async countByCircuit(circuitId: string) {
if (circuitId === "c-new") {
return 0;
}
return 1;
},
async moveToCircuit() {
return;
},
} as never,
circuitRepository: {
async findById(circuitId: string) {
if (circuitId === "c1" || circuitId === "c2") {
return { id: circuitId, sectionId: "s1", circuitListId: "l1", equipmentIdentifier: "-1F1", sortOrder: 10, isReserve: 0 } as never;
}
if (circuitId === "c-new") {
return { id: "c-new", sectionId: "s2", circuitListId: "l1", equipmentIdentifier: "-2F8", sortOrder: 40, isReserve: 0 } as never;
}
return null as never;
},
async listBySection() {
return [{ sortOrder: 30 }] as never[];
},
async create() {
createCount += 1;
return "c-new";
},
async update() {
return;
},
} as never,
circuitSectionRepository: {
async findById() {
return { id: "s2", circuitListId: "l1", prefix: "-2F" } as never;
},
} as never,
numberingService: {
async getNextIdentifier() {
return "-2F8";
},
} as never,
});
const result = await service.moveDeviceRowsBulk({
rowIds: ["r1", "r2"],
targetSectionId: "s2",
createNewCircuit: true,
});
assert.equal(createCount, 1);
assert.equal(result.createdCircuitId, "c-new");
});
it("reorders circuits inside one section without renumbering identifiers", async () => {
const updates: Array<{ id: string; sortOrder: number; equipmentIdentifier: string }> = [];
const service = new CircuitWriteService({