Create protected board defaults
This commit is contained in:
@@ -12,6 +12,7 @@ import { ProjectHistoryRepository } from "../src/db/repositories/project-history
|
||||
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 { 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 { projectRevisions } from "../src/db/schema/project-revisions.js";
|
||||
@@ -51,10 +52,51 @@ function getStructureCounts(context: DatabaseContext) {
|
||||
boards: context.db.select().from(distributionBoards).all().length,
|
||||
lists: context.db.select().from(circuitLists).all().length,
|
||||
sections: context.db.select().from(circuitSections).all().length,
|
||||
components: context.db
|
||||
.select()
|
||||
.from(distributionBoardComponents)
|
||||
.all().length,
|
||||
revisions: context.db.select().from(projectRevisions).all().length,
|
||||
};
|
||||
}
|
||||
|
||||
function legacySections(circuitListId: string) {
|
||||
return [
|
||||
{
|
||||
id: "legacy-lighting",
|
||||
circuitListId,
|
||||
key: "lighting",
|
||||
displayName: "Lighting",
|
||||
prefix: "-1F",
|
||||
sortOrder: 10,
|
||||
},
|
||||
{
|
||||
id: "legacy-single-phase",
|
||||
circuitListId,
|
||||
key: "single_phase",
|
||||
displayName: "Single-phase circuits",
|
||||
prefix: "-2F",
|
||||
sortOrder: 20,
|
||||
},
|
||||
{
|
||||
id: "legacy-three-phase",
|
||||
circuitListId,
|
||||
key: "three_phase",
|
||||
displayName: "Three-phase circuits",
|
||||
prefix: "-3F",
|
||||
sortOrder: 30,
|
||||
},
|
||||
{
|
||||
id: "legacy-unassigned",
|
||||
circuitListId,
|
||||
key: "unassigned",
|
||||
displayName: "Unassigned",
|
||||
prefix: "-UF",
|
||||
sortOrder: 90,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
describe("distribution-board structure project command", () => {
|
||||
it("builds the fixed setup and sends the expected frontend revision", async () => {
|
||||
const structure = createDistributionBoardStructureSnapshot(
|
||||
@@ -74,17 +116,26 @@ describe("distribution-board structure project command", () => {
|
||||
section.prefix,
|
||||
]),
|
||||
[
|
||||
["lighting", "-1F"],
|
||||
["single_phase", "-2F"],
|
||||
["three_phase", "-3F"],
|
||||
["unassigned", "-UF"],
|
||||
["lighting", "-1F1."],
|
||||
["single_phase", "-2F1."],
|
||||
["three_phase", "-3F1."],
|
||||
]
|
||||
);
|
||||
assert.deepEqual(
|
||||
structure.components.map((component) => [
|
||||
component.equipmentIdentifier,
|
||||
component.name,
|
||||
]),
|
||||
[
|
||||
["-Q0", "Hauptschalter"],
|
||||
["-FA", "Überspannungsableiter"],
|
||||
]
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
createDistributionBoardInsertProjectCommand({
|
||||
...structure,
|
||||
sections: structure.sections.slice(0, 3),
|
||||
sections: structure.sections.slice(0, 2),
|
||||
}),
|
||||
/incomplete/
|
||||
);
|
||||
@@ -150,7 +201,8 @@ describe("distribution-board structure project command", () => {
|
||||
assert.deepEqual(getStructureCounts(context), {
|
||||
boards: 1,
|
||||
lists: 1,
|
||||
sections: 4,
|
||||
sections: 3,
|
||||
components: 2,
|
||||
revisions: 1,
|
||||
});
|
||||
|
||||
@@ -167,6 +219,7 @@ describe("distribution-board structure project command", () => {
|
||||
boards: 0,
|
||||
lists: 0,
|
||||
sections: 0,
|
||||
components: 0,
|
||||
revisions: 2,
|
||||
});
|
||||
|
||||
@@ -182,7 +235,8 @@ describe("distribution-board structure project command", () => {
|
||||
assert.deepEqual(getStructureCounts(context), {
|
||||
boards: 1,
|
||||
lists: 1,
|
||||
sections: 4,
|
||||
sections: 3,
|
||||
components: 2,
|
||||
revisions: 3,
|
||||
});
|
||||
assert.ok(
|
||||
@@ -274,8 +328,9 @@ describe("distribution-board structure project command", () => {
|
||||
type: "distribution-board.insert",
|
||||
payload: {
|
||||
structure: {
|
||||
...current,
|
||||
distributionBoard: legacyBoard,
|
||||
circuitList: current.circuitList,
|
||||
sections: legacySections(current.circuitList.id),
|
||||
},
|
||||
},
|
||||
} as unknown as DistributionBoardStructureProjectCommand;
|
||||
@@ -291,6 +346,59 @@ describe("distribution-board structure project command", () => {
|
||||
.get();
|
||||
assert.equal(inserted?.floorId, null);
|
||||
assert.equal(inserted?.supplyType, null);
|
||||
assert.equal(
|
||||
context.db.select().from(circuitSections).all().length,
|
||||
4
|
||||
);
|
||||
assert.equal(
|
||||
context.db.select().from(distributionBoardComponents).all()
|
||||
.length,
|
||||
0
|
||||
);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps stored version-two setup commands component-free", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const repository =
|
||||
new DistributionBoardStructureProjectCommandRepository(
|
||||
context.db
|
||||
);
|
||||
const current = createDistributionBoardStructureSnapshot(
|
||||
"project-1",
|
||||
"UV Version 2"
|
||||
);
|
||||
const command = {
|
||||
schemaVersion: 2,
|
||||
type: "distribution-board.insert",
|
||||
payload: {
|
||||
structure: {
|
||||
distributionBoard: current.distributionBoard,
|
||||
circuitList: current.circuitList,
|
||||
sections: legacySections(current.circuitList.id),
|
||||
},
|
||||
},
|
||||
} as DistributionBoardStructureProjectCommand;
|
||||
|
||||
const inserted = repository.execute({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 0,
|
||||
source: "user",
|
||||
command,
|
||||
});
|
||||
assert.equal(inserted.inverse.schemaVersion, 2);
|
||||
assert.equal(
|
||||
context.db.select().from(circuitSections).all().length,
|
||||
4
|
||||
);
|
||||
assert.equal(
|
||||
context.db.select().from(distributionBoardComponents).all()
|
||||
.length,
|
||||
0
|
||||
);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
@@ -545,6 +653,7 @@ describe("distribution-board structure project command", () => {
|
||||
boards: 0,
|
||||
lists: 0,
|
||||
sections: 0,
|
||||
components: 0,
|
||||
revisions: 0,
|
||||
});
|
||||
|
||||
@@ -661,6 +770,7 @@ describe("distribution-board structure project command", () => {
|
||||
boards: 0,
|
||||
lists: 0,
|
||||
sections: 0,
|
||||
components: 0,
|
||||
revisions: 0,
|
||||
});
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user