Add distribution power summaries
This commit is contained in:
@@ -22,7 +22,10 @@ import {
|
||||
createDistributionBoardStructureSnapshot,
|
||||
type DistributionBoardStructureProjectCommand,
|
||||
} from "../src/domain/models/distribution-board-structure-project-command.model.js";
|
||||
import { createDistributionBoardUpdateProjectCommand } from "../src/domain/models/distribution-board-project-command.model.js";
|
||||
import {
|
||||
createDistributionBoardUpdateProjectCommand,
|
||||
type DistributionBoardUpdateProjectCommand,
|
||||
} from "../src/domain/models/distribution-board-project-command.model.js";
|
||||
import {
|
||||
createDistributionBoard,
|
||||
updateDistributionBoard,
|
||||
@@ -293,7 +296,7 @@ describe("distribution-board structure project command", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("updates floor and supply type with persisted undo and validates project ownership", () => {
|
||||
it("updates floor, supply type and simultaneity factor with persisted undo", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
context.db
|
||||
@@ -335,7 +338,11 @@ describe("distribution-board structure project command", () => {
|
||||
source: "user",
|
||||
command: createDistributionBoardUpdateProjectCommand(
|
||||
structure.distributionBoard.id,
|
||||
{ floorId: "floor-1", supplyType: "SV" }
|
||||
{
|
||||
floorId: "floor-1",
|
||||
supplyType: "SV",
|
||||
simultaneityFactor: 0.75,
|
||||
}
|
||||
),
|
||||
});
|
||||
assert.deepEqual(
|
||||
@@ -343,10 +350,16 @@ describe("distribution-board structure project command", () => {
|
||||
.select({
|
||||
floorId: distributionBoards.floorId,
|
||||
supplyType: distributionBoards.supplyType,
|
||||
simultaneityFactor:
|
||||
distributionBoards.simultaneityFactor,
|
||||
})
|
||||
.from(distributionBoards)
|
||||
.get(),
|
||||
{ floorId: "floor-1", supplyType: "SV" }
|
||||
{
|
||||
floorId: "floor-1",
|
||||
supplyType: "SV",
|
||||
simultaneityFactor: 0.75,
|
||||
}
|
||||
);
|
||||
|
||||
const undoStep = new ProjectHistoryRepository(
|
||||
@@ -365,10 +378,16 @@ describe("distribution-board structure project command", () => {
|
||||
.select({
|
||||
floorId: distributionBoards.floorId,
|
||||
supplyType: distributionBoards.supplyType,
|
||||
simultaneityFactor:
|
||||
distributionBoards.simultaneityFactor,
|
||||
})
|
||||
.from(distributionBoards)
|
||||
.get(),
|
||||
{ floorId: null, supplyType: "AV" }
|
||||
{
|
||||
floorId: null,
|
||||
supplyType: "AV",
|
||||
simultaneityFactor: 1,
|
||||
}
|
||||
);
|
||||
assert.throws(
|
||||
() =>
|
||||
@@ -395,6 +414,52 @@ describe("distribution-board structure project command", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps stored version-one board updates executable", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const repository =
|
||||
new DistributionBoardStructureProjectCommandRepository(
|
||||
context.db
|
||||
);
|
||||
const structure = createDistributionBoardStructureSnapshot(
|
||||
"project-1",
|
||||
"UV Alt",
|
||||
{ supplyType: "AV" }
|
||||
);
|
||||
repository.execute({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 0,
|
||||
source: "user",
|
||||
command:
|
||||
createDistributionBoardInsertProjectCommand(structure),
|
||||
});
|
||||
const legacyUpdate = {
|
||||
schemaVersion: 1,
|
||||
type: "distribution-board.update",
|
||||
payload: {
|
||||
distributionBoardId: structure.distributionBoard.id,
|
||||
changes: [{ field: "supplyType", value: "SV" }],
|
||||
},
|
||||
} as DistributionBoardUpdateProjectCommand;
|
||||
|
||||
repository.executeUpdate({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 1,
|
||||
source: "user",
|
||||
command: legacyUpdate,
|
||||
});
|
||||
|
||||
const board = context.db
|
||||
.select()
|
||||
.from(distributionBoards)
|
||||
.get();
|
||||
assert.equal(board?.supplyType, "SV");
|
||||
assert.equal(board?.simultaneityFactor, 1);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("sends distribution-board updates to the revision-safe API", async () => {
|
||||
const requests: Array<{ url: string; method: string; body: unknown }> = [];
|
||||
const originalFetch = globalThis.fetch;
|
||||
@@ -413,7 +478,11 @@ describe("distribution-board structure project command", () => {
|
||||
await updateDistributionBoard(
|
||||
"project-1",
|
||||
"board-1",
|
||||
{ floorId: "floor-1", supplyType: "USV" },
|
||||
{
|
||||
floorId: "floor-1",
|
||||
supplyType: "USV",
|
||||
simultaneityFactor: 0.8,
|
||||
},
|
||||
9
|
||||
);
|
||||
} finally {
|
||||
@@ -426,6 +495,7 @@ describe("distribution-board structure project command", () => {
|
||||
body: {
|
||||
floorId: "floor-1",
|
||||
supplyType: "USV",
|
||||
simultaneityFactor: 0.8,
|
||||
expectedRevision: 9,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user