Prevent stale cell update overwrites
This commit is contained in:
parent
0800f984bb
commit
1c57df46fa
5 changed files with 128 additions and 47 deletions
|
|
@ -44,7 +44,7 @@ describe("circuit write service rules", () => {
|
|||
async existsByEquipmentIdentifier() {
|
||||
return false;
|
||||
},
|
||||
async update(_id: string, payload: Record<string, unknown>) {
|
||||
async updateFields(_id: string, payload: Record<string, unknown>) {
|
||||
updatePayload = payload;
|
||||
},
|
||||
} as never,
|
||||
|
|
@ -52,8 +52,10 @@ describe("circuit write service rules", () => {
|
|||
|
||||
await service.updateCircuit("c1", { voltage: 400, controlRequirement: "DALI" });
|
||||
|
||||
assert.equal(updatePayload.voltage, 400);
|
||||
assert.equal(updatePayload.controlRequirement, "DALI");
|
||||
assert.deepEqual(updatePayload, {
|
||||
voltage: 400,
|
||||
controlRequirement: "DALI",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects duplicate equipment identifiers in same circuit list", async () => {
|
||||
|
|
@ -1147,7 +1149,7 @@ describe("circuit write service rules", () => {
|
|||
});
|
||||
|
||||
it("tracks local edits on linked device rows as overridden fields", async () => {
|
||||
let savedOverrides: string | undefined;
|
||||
let updatePayload: Record<string, unknown> = {};
|
||||
const current = {
|
||||
id: "r1",
|
||||
circuitId: "c1",
|
||||
|
|
@ -1165,14 +1167,17 @@ describe("circuit write service rules", () => {
|
|||
async findById() {
|
||||
return current as never;
|
||||
},
|
||||
async update(_rowId: string, input: { overriddenFields?: string }) {
|
||||
savedOverrides = input.overriddenFields;
|
||||
async updateFields(_rowId: string, input: Record<string, unknown>) {
|
||||
updatePayload = input;
|
||||
},
|
||||
} as never,
|
||||
});
|
||||
|
||||
await service.updateDeviceRow("r1", { quantity: 2 });
|
||||
|
||||
assert.deepEqual(JSON.parse(savedOverrides ?? "[]"), ["quantity"]);
|
||||
assert.deepEqual(updatePayload, {
|
||||
quantity: 2,
|
||||
overriddenFields: "[\"quantity\"]",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue