Add configurable distribution supply types
This commit is contained in:
@@ -11,6 +11,7 @@ import { ProjectHistoryRepository } from "../src/db/repositories/project-history
|
||||
import { ProjectSettingsProjectCommandRepository } from "../src/db/repositories/project-settings-project-command.repository.js";
|
||||
import { projectRevisions } from "../src/db/schema/project-revisions.js";
|
||||
import { projects } from "../src/db/schema/projects.js";
|
||||
import { distributionBoards } from "../src/db/schema/distribution-boards.js";
|
||||
import { ProjectRevisionConflictError } from "../src/domain/errors/project-revision-conflict.error.js";
|
||||
import { createProjectSettingsUpdateProjectCommand } from "../src/domain/models/project-settings-project-command.model.js";
|
||||
import { updateProjectSettings } from "../src/frontend/utils/api.js";
|
||||
@@ -43,6 +44,8 @@ function getSettings(context: DatabaseContext) {
|
||||
description: projects.description,
|
||||
singlePhaseVoltageV: projects.singlePhaseVoltageV,
|
||||
threePhaseVoltageV: projects.threePhaseVoltageV,
|
||||
enabledDistributionBoardSupplyTypes:
|
||||
projects.enabledDistributionBoardSupplyTypes,
|
||||
currentRevision: projects.currentRevision,
|
||||
})
|
||||
.from(projects)
|
||||
@@ -63,6 +66,14 @@ function settings(
|
||||
description: null,
|
||||
singlePhaseVoltageV: 230,
|
||||
threePhaseVoltageV: 400,
|
||||
enabledDistributionBoardSupplyTypes: [
|
||||
"AV",
|
||||
"SV",
|
||||
"EV",
|
||||
"USV",
|
||||
"MSR",
|
||||
"SiBe",
|
||||
],
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -110,6 +121,14 @@ describe("project settings project-command repository", () => {
|
||||
description: null,
|
||||
singlePhaseVoltageV: 240,
|
||||
threePhaseVoltageV: 415,
|
||||
enabledDistributionBoardSupplyTypes: [
|
||||
"AV",
|
||||
"SV",
|
||||
"EV",
|
||||
"USV",
|
||||
"MSR",
|
||||
"SiBe",
|
||||
],
|
||||
},
|
||||
},
|
||||
]);
|
||||
@@ -128,6 +147,14 @@ describe("project settings project-command repository", () => {
|
||||
buildingOwner: "Beispiel Bau GmbH",
|
||||
singlePhaseVoltageV: 240,
|
||||
threePhaseVoltageV: 415,
|
||||
enabledDistributionBoardSupplyTypes: [
|
||||
"AV",
|
||||
"SV",
|
||||
"EV",
|
||||
"USV",
|
||||
"MSR",
|
||||
"SiBe",
|
||||
],
|
||||
});
|
||||
const forward = repository.executeUpdate({
|
||||
projectId: "project-1",
|
||||
@@ -136,13 +163,12 @@ describe("project settings project-command repository", () => {
|
||||
command,
|
||||
});
|
||||
assert.deepEqual(getSettings(context), {
|
||||
name: "Neuer Projektname",
|
||||
internalProjectNumber: "INT-1",
|
||||
externalProjectNumber: null,
|
||||
buildingOwner: "Beispiel Bau GmbH",
|
||||
description: null,
|
||||
singlePhaseVoltageV: 240,
|
||||
threePhaseVoltageV: 415,
|
||||
...settings({
|
||||
name: "Neuer Projektname",
|
||||
buildingOwner: "Beispiel Bau GmbH",
|
||||
singlePhaseVoltageV: 240,
|
||||
threePhaseVoltageV: 415,
|
||||
}),
|
||||
currentRevision: 1,
|
||||
});
|
||||
assert.deepEqual(forward.inverse.payload, {
|
||||
@@ -153,6 +179,14 @@ describe("project settings project-command repository", () => {
|
||||
description: null,
|
||||
singlePhaseVoltageV: 230,
|
||||
threePhaseVoltageV: 400,
|
||||
enabledDistributionBoardSupplyTypes: [
|
||||
"AV",
|
||||
"SV",
|
||||
"EV",
|
||||
"USV",
|
||||
"MSR",
|
||||
"SiBe",
|
||||
],
|
||||
});
|
||||
|
||||
const undoStep = history.getNextCommand("project-1", "undo");
|
||||
@@ -172,6 +206,14 @@ describe("project settings project-command repository", () => {
|
||||
description: null,
|
||||
singlePhaseVoltageV: 230,
|
||||
threePhaseVoltageV: 400,
|
||||
enabledDistributionBoardSupplyTypes: [
|
||||
"AV",
|
||||
"SV",
|
||||
"EV",
|
||||
"USV",
|
||||
"MSR",
|
||||
"SiBe",
|
||||
],
|
||||
currentRevision: 2,
|
||||
});
|
||||
|
||||
@@ -192,6 +234,14 @@ describe("project settings project-command repository", () => {
|
||||
description: null,
|
||||
singlePhaseVoltageV: 240,
|
||||
threePhaseVoltageV: 415,
|
||||
enabledDistributionBoardSupplyTypes: [
|
||||
"AV",
|
||||
"SV",
|
||||
"EV",
|
||||
"USV",
|
||||
"MSR",
|
||||
"SiBe",
|
||||
],
|
||||
currentRevision: 3,
|
||||
});
|
||||
} finally {
|
||||
@@ -230,6 +280,51 @@ describe("project settings project-command repository", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("persists the project supply-type selection and rejects disabling an in-use type", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
const repository = new ProjectSettingsProjectCommandRepository(
|
||||
context.db
|
||||
);
|
||||
repository.executeUpdate({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 0,
|
||||
source: "user",
|
||||
command: createProjectSettingsUpdateProjectCommand({
|
||||
...settings(),
|
||||
enabledDistributionBoardSupplyTypes: ["AV", "MSR", "SiBe"],
|
||||
}),
|
||||
});
|
||||
assert.deepEqual(
|
||||
getSettings(context)?.enabledDistributionBoardSupplyTypes,
|
||||
["AV", "MSR", "SiBe"]
|
||||
);
|
||||
|
||||
context.db.insert(distributionBoards).values({
|
||||
id: "board-1",
|
||||
projectId: "project-1",
|
||||
name: "UV SiBe",
|
||||
supplyType: "SiBe",
|
||||
}).run();
|
||||
assert.throws(
|
||||
() =>
|
||||
repository.executeUpdate({
|
||||
projectId: "project-1",
|
||||
expectedRevision: 1,
|
||||
source: "user",
|
||||
command: createProjectSettingsUpdateProjectCommand({
|
||||
...settings(),
|
||||
enabledDistributionBoardSupplyTypes: ["AV", "MSR"],
|
||||
}),
|
||||
}),
|
||||
/SiBe/
|
||||
);
|
||||
assert.equal(getSettings(context)?.currentRevision, 1);
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects no-op, invalid project and stale revision without partial writes", () => {
|
||||
const context = createTestDatabase();
|
||||
try {
|
||||
@@ -277,13 +372,7 @@ describe("project settings project-command repository", () => {
|
||||
ProjectRevisionConflictError
|
||||
);
|
||||
assert.deepEqual(getSettings(context), {
|
||||
name: "Testprojekt",
|
||||
internalProjectNumber: "INT-1",
|
||||
externalProjectNumber: null,
|
||||
buildingOwner: null,
|
||||
description: null,
|
||||
singlePhaseVoltageV: 230,
|
||||
threePhaseVoltageV: 400,
|
||||
...settings(),
|
||||
currentRevision: 0,
|
||||
});
|
||||
assert.equal(
|
||||
@@ -323,13 +412,7 @@ describe("project settings project-command repository", () => {
|
||||
/forced project settings history failure/
|
||||
);
|
||||
assert.deepEqual(getSettings(context), {
|
||||
name: "Testprojekt",
|
||||
internalProjectNumber: "INT-1",
|
||||
externalProjectNumber: null,
|
||||
buildingOwner: null,
|
||||
description: null,
|
||||
singlePhaseVoltageV: 230,
|
||||
threePhaseVoltageV: 400,
|
||||
...settings(),
|
||||
currentRevision: 0,
|
||||
});
|
||||
assert.equal(
|
||||
|
||||
Reference in New Issue
Block a user