Include components in project snapshots
This commit is contained in:
@@ -14,8 +14,11 @@ import { ProjectTransferRepository } from "../src/db/repositories/project-transf
|
||||
import { readProjectStateSnapshot } from "../src/db/repositories/project-state-snapshot.persistence.js";
|
||||
import { circuitDeviceRows } from "../src/db/schema/circuit-device-rows.js";
|
||||
import { circuitLists } from "../src/db/schema/circuit-lists.js";
|
||||
import { circuitProtectionDevices } from "../src/db/schema/circuit-protection-devices.js";
|
||||
import { circuitSections } from "../src/db/schema/circuit-sections.js";
|
||||
import { circuits } from "../src/db/schema/circuits.js";
|
||||
import { distributionBoardComponentProtectionDevices } from "../src/db/schema/distribution-board-component-protection-devices.js";
|
||||
import { distributionBoardComponents } from "../src/db/schema/distribution-board-components.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";
|
||||
@@ -129,9 +132,58 @@ function createTestDatabase(): DatabaseContext {
|
||||
cosPhi: 0.9,
|
||||
})
|
||||
.run();
|
||||
context.db
|
||||
.insert(circuitProtectionDevices)
|
||||
.values({
|
||||
circuitId: "circuit-1",
|
||||
type: "LS",
|
||||
ratedCurrentA: 10,
|
||||
fuseUtilizationCategory: null,
|
||||
tripCharacteristic: "B",
|
||||
rcdType: null,
|
||||
ratedResidualCurrentMa: null,
|
||||
})
|
||||
.run();
|
||||
context.db
|
||||
.insert(distributionBoardComponents)
|
||||
.values({
|
||||
id: "component-1",
|
||||
circuitListId: list.id,
|
||||
sectionId: section.id,
|
||||
equipmentIdentifier: "-1Q1.0",
|
||||
name: "Gruppen-FI",
|
||||
role: "group_residual_current_protection",
|
||||
placement: "group",
|
||||
sortOrder: 10,
|
||||
})
|
||||
.run();
|
||||
context.db
|
||||
.insert(distributionBoardComponentProtectionDevices)
|
||||
.values({
|
||||
componentId: "component-1",
|
||||
type: "FI",
|
||||
ratedCurrentA: 40,
|
||||
fuseUtilizationCategory: null,
|
||||
tripCharacteristic: null,
|
||||
rcdType: "A",
|
||||
ratedResidualCurrentMa: 30,
|
||||
})
|
||||
.run();
|
||||
return context;
|
||||
}
|
||||
|
||||
function removeVersionSevenFields(state: Record<string, unknown>) {
|
||||
delete state.distributionBoardComponents;
|
||||
delete state.circuitProtectionDevices;
|
||||
delete state.distributionBoardComponentProtectionDevices;
|
||||
for (const section of state.circuitSections as Array<
|
||||
Record<string, unknown>
|
||||
>) {
|
||||
delete section.category;
|
||||
delete section.groupNumber;
|
||||
}
|
||||
}
|
||||
|
||||
describe("project snapshot repository", () => {
|
||||
it("captures, hashes and lists a complete named logical snapshot", () => {
|
||||
const context = createTestDatabase();
|
||||
@@ -190,6 +242,12 @@ describe("project snapshot repository", () => {
|
||||
context.db.select().from(circuitSections).all().length
|
||||
);
|
||||
assert.equal(state.circuits.length, 1);
|
||||
assert.equal(state.circuitProtectionDevices.length, 1);
|
||||
assert.equal(state.distributionBoardComponents.length, 1);
|
||||
assert.equal(
|
||||
state.distributionBoardComponentProtectionDevices.length,
|
||||
1
|
||||
);
|
||||
assert.equal(state.circuits[0].deviceRows.length, 1);
|
||||
assert.equal(
|
||||
state.circuits[0].deviceRows[0].linkedProjectDeviceId,
|
||||
@@ -291,6 +349,7 @@ describe("project snapshot repository", () => {
|
||||
project: Record<string, unknown>;
|
||||
};
|
||||
currentPayload.schemaVersion = 1;
|
||||
removeVersionSevenFields(currentPayload);
|
||||
delete currentPayload.project.internalProjectNumber;
|
||||
delete currentPayload.project.externalProjectNumber;
|
||||
delete currentPayload.project.buildingOwner;
|
||||
@@ -368,6 +427,19 @@ describe("portable project transfer", () => {
|
||||
copied.state.circuits[0].id,
|
||||
source.state.circuits[0].id
|
||||
);
|
||||
assert.notEqual(
|
||||
copied.state.distributionBoardComponents[0].id,
|
||||
source.state.distributionBoardComponents[0].id
|
||||
);
|
||||
assert.equal(
|
||||
copied.state.circuitProtectionDevices[0].circuitId,
|
||||
copied.state.circuits[0].id
|
||||
);
|
||||
assert.equal(
|
||||
copied.state.distributionBoardComponentProtectionDevices[0]
|
||||
.componentId,
|
||||
copied.state.distributionBoardComponents[0].id
|
||||
);
|
||||
assert.equal(
|
||||
copied.state.circuits[0].deviceRows[0].linkedProjectDeviceId,
|
||||
copied.state.projectDevices[0].id
|
||||
@@ -438,6 +510,7 @@ describe("portable project transfer", () => {
|
||||
distributionBoards: Array<Record<string, unknown>>;
|
||||
};
|
||||
legacyState.schemaVersion = 2;
|
||||
removeVersionSevenFields(legacyState);
|
||||
delete (
|
||||
legacyState.project as Record<string, unknown>
|
||||
).enabledDistributionBoardSupplyTypes;
|
||||
|
||||
Reference in New Issue
Block a user