Add configurable distribution supply types
This commit is contained in:
@@ -16,6 +16,7 @@ import { circuitDeviceRows } from "../src/db/schema/circuit-device-rows.js";
|
||||
import { circuitLists } from "../src/db/schema/circuit-lists.js";
|
||||
import { circuitSections } from "../src/db/schema/circuit-sections.js";
|
||||
import { circuits } from "../src/db/schema/circuits.js";
|
||||
import { distributionBoards } from "../src/db/schema/distribution-boards.js";
|
||||
import { floors } from "../src/db/schema/floors.js";
|
||||
import { projectDevices } from "../src/db/schema/project-devices.js";
|
||||
import { projectSnapshots } from "../src/db/schema/project-snapshots.js";
|
||||
@@ -64,6 +65,11 @@ function createTestDatabase(): DatabaseContext {
|
||||
sortOrder: 10,
|
||||
})
|
||||
.run();
|
||||
context.db
|
||||
.update(distributionBoards)
|
||||
.set({ floorId: "floor-1", supplyType: "SV" })
|
||||
.where(eq(distributionBoards.id, board.id))
|
||||
.run();
|
||||
context.db
|
||||
.insert(rooms)
|
||||
.values({
|
||||
@@ -168,6 +174,8 @@ describe("project snapshot repository", () => {
|
||||
);
|
||||
assert.equal(state.project.id, "project-1");
|
||||
assert.equal(state.distributionBoards.length, 1);
|
||||
assert.equal(state.distributionBoards[0].floorId, "floor-1");
|
||||
assert.equal(state.distributionBoards[0].supplyType, "SV");
|
||||
assert.equal(state.circuitLists.length, 1);
|
||||
assert.equal(
|
||||
state.circuitSections.length,
|
||||
@@ -279,6 +287,13 @@ describe("project snapshot repository", () => {
|
||||
delete currentPayload.project.externalProjectNumber;
|
||||
delete currentPayload.project.buildingOwner;
|
||||
delete currentPayload.project.description;
|
||||
delete currentPayload.project.enabledDistributionBoardSupplyTypes;
|
||||
for (const board of currentPayload.distributionBoards as Array<
|
||||
Record<string, unknown>
|
||||
>) {
|
||||
delete board.floorId;
|
||||
delete board.supplyType;
|
||||
}
|
||||
const legacyPayloadJson = JSON.stringify(currentPayload);
|
||||
context.db
|
||||
.update(projectSnapshots)
|
||||
@@ -352,6 +367,14 @@ describe("portable project transfer", () => {
|
||||
copied.state.circuits[0].deviceRows[0].roomId,
|
||||
copied.state.rooms[0].id
|
||||
);
|
||||
assert.equal(
|
||||
copied.state.distributionBoards[0].floorId,
|
||||
copied.state.floors[0].id
|
||||
);
|
||||
assert.equal(
|
||||
copied.state.distributionBoards[0].supplyType,
|
||||
"SV"
|
||||
);
|
||||
assert.equal(
|
||||
copied.state.circuits[0].deviceRows[0].legacyConsumerId,
|
||||
null
|
||||
@@ -390,6 +413,46 @@ describe("portable project transfer", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("imports a checksum-valid version-two project transfer", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const repository = new ProjectTransferRepository(context.db);
|
||||
const current = repository.exportProject("project-1");
|
||||
assert.ok(current);
|
||||
const legacyState = structuredClone(
|
||||
current.projectState
|
||||
) as unknown as Record<string, unknown> & {
|
||||
distributionBoards: Array<Record<string, unknown>>;
|
||||
};
|
||||
legacyState.schemaVersion = 2;
|
||||
delete (
|
||||
legacyState.project as Record<string, unknown>
|
||||
).enabledDistributionBoardSupplyTypes;
|
||||
for (const board of legacyState.distributionBoards) {
|
||||
delete board.floorId;
|
||||
delete board.supplyType;
|
||||
}
|
||||
const legacyPayloadJson = JSON.stringify(legacyState);
|
||||
const duplicate = repository.importDuplicate({
|
||||
...current,
|
||||
projectState: legacyState,
|
||||
payloadSha256: crypto
|
||||
.createHash("sha256")
|
||||
.update(legacyPayloadJson)
|
||||
.digest("hex"),
|
||||
});
|
||||
const copied = readProjectStateSnapshot(
|
||||
context.db,
|
||||
duplicate.projectId
|
||||
);
|
||||
assert.ok(copied);
|
||||
assert.equal(copied.state.distributionBoards[0].floorId, null);
|
||||
assert.equal(copied.state.distributionBoards[0].supplyType, null);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("rolls back a duplicate when a late project-state insert fails", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user