Route project devices through history
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { createProjectDeviceSchema } from "../src/shared/validation/project-device.schemas.js";
|
||||
import {
|
||||
createProjectDeviceCommandSchema,
|
||||
createProjectDeviceSchema,
|
||||
projectDeviceStructureCommandSchema,
|
||||
updateProjectDeviceCommandSchema,
|
||||
} from "../src/shared/validation/project-device.schemas.js";
|
||||
|
||||
describe("project device circuit-first schema", () => {
|
||||
it("accepts circuit device fields", () => {
|
||||
@@ -33,4 +38,53 @@ describe("project device circuit-first schema", () => {
|
||||
|
||||
assert.equal(result.success, false);
|
||||
});
|
||||
|
||||
it("requires a project revision for create and update commands", () => {
|
||||
const device = {
|
||||
name: "E-Line Pro",
|
||||
displayName: "Bürobeleuchtung",
|
||||
phaseType: "single_phase" as const,
|
||||
quantity: 6,
|
||||
powerPerUnit: 0.04,
|
||||
simultaneityFactor: 0.8,
|
||||
};
|
||||
|
||||
assert.equal(createProjectDeviceCommandSchema.safeParse(device).success, false);
|
||||
assert.equal(updateProjectDeviceCommandSchema.safeParse(device).success, false);
|
||||
assert.equal(
|
||||
createProjectDeviceCommandSchema.safeParse({
|
||||
...device,
|
||||
expectedRevision: 4,
|
||||
}).success,
|
||||
true
|
||||
);
|
||||
assert.equal(
|
||||
updateProjectDeviceCommandSchema.safeParse({
|
||||
...device,
|
||||
expectedRevision: 4,
|
||||
}).success,
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it("accepts only non-negative integer revisions for structure commands", () => {
|
||||
assert.equal(
|
||||
projectDeviceStructureCommandSchema.safeParse({
|
||||
expectedRevision: 0,
|
||||
}).success,
|
||||
true
|
||||
);
|
||||
assert.equal(
|
||||
projectDeviceStructureCommandSchema.safeParse({
|
||||
expectedRevision: -1,
|
||||
}).success,
|
||||
false
|
||||
);
|
||||
assert.equal(
|
||||
projectDeviceStructureCommandSchema.safeParse({
|
||||
expectedRevision: 1.5,
|
||||
}).success,
|
||||
false
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user