Add public building project setting

This commit is contained in:
2026-07-31 17:41:30 +02:00
parent 43a3bb0b69
commit 44b6fde940
29 changed files with 2057 additions and 54 deletions
+5
View File
@@ -1057,6 +1057,7 @@ describe("project command service", () => {
externalProjectNumber: null,
buildingOwner: null,
description: null,
isPublicBuilding: true,
singlePhaseVoltageV: 240,
threePhaseVoltageV: 415,
enabledDistributionBoardSupplyTypes: [
@@ -1073,6 +1074,7 @@ describe("project command service", () => {
assert.deepEqual(
context.db
.select({
isPublicBuilding: projects.isPublicBuilding,
singlePhaseVoltageV: projects.singlePhaseVoltageV,
threePhaseVoltageV: projects.threePhaseVoltageV,
})
@@ -1080,6 +1082,7 @@ describe("project command service", () => {
.where(eq(projects.id, "project-1"))
.get(),
{
isPublicBuilding: true,
singlePhaseVoltageV: 240,
threePhaseVoltageV: 415,
}
@@ -1093,6 +1096,7 @@ describe("project command service", () => {
assert.deepEqual(
context.db
.select({
isPublicBuilding: projects.isPublicBuilding,
singlePhaseVoltageV: projects.singlePhaseVoltageV,
threePhaseVoltageV: projects.threePhaseVoltageV,
})
@@ -1100,6 +1104,7 @@ describe("project command service", () => {
.where(eq(projects.id, "project-1"))
.get(),
{
isPublicBuilding: false,
singlePhaseVoltageV: 230,
threePhaseVoltageV: 400,
}
@@ -47,6 +47,7 @@ function getSettings(context: DatabaseContext) {
externalProjectNumber: projects.externalProjectNumber,
buildingOwner: projects.buildingOwner,
description: projects.description,
isPublicBuilding: projects.isPublicBuilding,
singlePhaseVoltageV: projects.singlePhaseVoltageV,
threePhaseVoltageV: projects.threePhaseVoltageV,
enabledDistributionBoardSupplyTypes:
@@ -69,6 +70,7 @@ function settings(
externalProjectNumber: null,
buildingOwner: null,
description: null,
isPublicBuilding: false,
singlePhaseVoltageV: 230,
threePhaseVoltageV: 400,
enabledDistributionBoardSupplyTypes: [
@@ -204,6 +206,7 @@ describe("project settings project-command repository", () => {
externalProjectNumber: null,
buildingOwner: null,
description: null,
isPublicBuilding: false,
singlePhaseVoltageV: 240,
threePhaseVoltageV: 415,
enabledDistributionBoardSupplyTypes: [
@@ -231,6 +234,7 @@ describe("project settings project-command repository", () => {
...settings(),
name: "Neuer Projektname",
buildingOwner: "Beispiel Bau GmbH",
isPublicBuilding: true,
singlePhaseVoltageV: 240,
threePhaseVoltageV: 415,
enabledDistributionBoardSupplyTypes: [
@@ -252,6 +256,7 @@ describe("project settings project-command repository", () => {
...settings({
name: "Neuer Projektname",
buildingOwner: "Beispiel Bau GmbH",
isPublicBuilding: true,
singlePhaseVoltageV: 240,
threePhaseVoltageV: 415,
}),
@@ -273,6 +278,7 @@ describe("project settings project-command repository", () => {
externalProjectNumber: null,
buildingOwner: null,
description: null,
isPublicBuilding: false,
singlePhaseVoltageV: 230,
threePhaseVoltageV: 400,
enabledDistributionBoardSupplyTypes: [
@@ -300,6 +306,7 @@ describe("project settings project-command repository", () => {
externalProjectNumber: null,
buildingOwner: null,
description: null,
isPublicBuilding: false,
singlePhaseVoltageV: 230,
threePhaseVoltageV: 400,
enabledDistributionBoardSupplyTypes: [
@@ -338,6 +345,7 @@ describe("project settings project-command repository", () => {
externalProjectNumber: null,
buildingOwner: "Beispiel Bau GmbH",
description: null,
isPublicBuilding: true,
singlePhaseVoltageV: 240,
threePhaseVoltageV: 415,
enabledDistributionBoardSupplyTypes: [
@@ -365,6 +373,66 @@ describe("project settings project-command repository", () => {
}
});
it("preserves the building classification when applying a baseline command", () => {
const context = createTestDatabase();
try {
context.db
.update(projects)
.set({ isPublicBuilding: true })
.where(eq(projects.id, "project-1"))
.run();
const repository = new ProjectSettingsProjectCommandRepository(
context.db
);
const forward = repository.executeUpdate({
projectId: "project-1",
expectedRevision: 0,
source: "user",
command: {
schemaVersion: 1,
type: "project.update-settings",
payload: {
name: "Stand aus Baseline-Command",
internalProjectNumber: "INT-1",
externalProjectNumber: null,
buildingOwner: null,
description: null,
singlePhaseVoltageV: 230,
threePhaseVoltageV: 400,
enabledDistributionBoardSupplyTypes: [
"AV",
"SV",
"EV",
"USV",
"MSR",
"SiBe",
],
},
},
});
assert.equal(getSettings(context)?.name, "Stand aus Baseline-Command");
assert.equal(getSettings(context)?.isPublicBuilding, true);
assert.equal(forward.inverse.schemaVersion, 1);
const history = new ProjectHistoryRepository(context.db);
const undoStep = history.getNextCommand("project-1", "undo");
assert.ok(undoStep);
repository.executeUpdate({
projectId: "project-1",
expectedRevision: 1,
source: "undo",
historyTargetChangeSetId: undoStep.changeSetId,
command: forward.inverse,
});
assert.equal(getSettings(context)?.name, "Testprojekt");
assert.equal(getSettings(context)?.isPublicBuilding, true);
} finally {
context.close();
}
});
it("persists the project supply-type selection and rejects disabling an in-use type", () => {
const context = createTestDatabase();
try {
+13 -1
View File
@@ -18,6 +18,7 @@ function minimalSnapshot() {
externalProjectNumber: null,
buildingOwner: null,
description: null,
isPublicBuilding: true,
singlePhaseVoltageV: 230,
threePhaseVoltageV: 400,
enabledDistributionBoardSupplyTypes: [
@@ -142,7 +143,18 @@ describe("project state snapshot model", () => {
);
});
it("rejects pre-baseline snapshot shapes", () => {
it("upgrades the supported baseline snapshot with a safe building default", () => {
const baseline = structuredClone(minimalSnapshot());
baseline.schemaVersion = 1 as typeof baseline.schemaVersion;
delete (baseline.project as Record<string, unknown>).isPublicBuilding;
const upgraded = parseProjectStateSnapshot(baseline);
assert.equal(upgraded.schemaVersion, projectStateSnapshotSchemaVersion);
assert.equal(upgraded.project.isPublicBuilding, false);
});
it("rejects malformed baseline and unknown snapshot shapes", () => {
const outdated = structuredClone(minimalSnapshot());
delete (outdated.project as Record<string, unknown>).description;
assert.throws(() => parseProjectStateSnapshot(outdated));
+2
View File
@@ -247,6 +247,7 @@ describe("project settings presentation", () => {
externalProjectNumber: null,
buildingOwner: null,
description: null,
isPublicBuilding: true,
singlePhaseVoltageV: 230,
threePhaseVoltageV: 400,
enabledDistributionBoardSupplyTypes: [
@@ -262,6 +263,7 @@ describe("project settings presentation", () => {
assert.match(markup, /MSR/);
assert.match(markup, /SiBe/);
assert.match(markup, /in Verwendung/);
assert.match(markup, /Öffentliches Gebäude/);
});
});