import assert from "node:assert/strict"; import test from "node:test"; import { autonomyCount, toDraft, toPayload, } from "../src/pages/org/approvals/lib/settings.ts"; // The organisation settings as the server returns them. The page edits some // fields and sends the rest back as it read them. const saved = { approval_deadline: "24h", default_owner: "someone", escalation: [{ account: "someone", deadline: "4h" }], propose_autonomy_after: 3, frozen: false, }; // Guards #2124: how many approvals earn an autonomy proposal is part of the // organisation settings but had no control on the approvals page, so an // operator could read it only through the API and could not change it. test("the approvals draft carries the count that earns a proposal", () => { assert.equal(toDraft(saved).propose_autonomy_after, 3); assert.equal(toDraft({ ...saved, propose_autonomy_after: 12 }).propose_autonomy_after, 12); }); test("saving sends the edited count with the fields the page does not edit", () => { const draft = { ...toDraft(saved), propose_autonomy_after: 7 }; const body = toPayload(saved, draft); assert.equal(body.propose_autonomy_after, 7); assert.equal(body.frozen, false, "a field the page does not edit is sent back as it was read"); assert.equal(body.approval_deadline, "24h"); }); // The server accepts one to a hundred approvals; past that no action type could // ever earn a proposal, so the field never sends a value outside the range. test("a count outside the server's range becomes the nearest bound", () => { for (const [typed, want] of [ [0, 1], [-4, 1], [1, 1], [100, 100], [101, 100], ] as const) { assert.equal(autonomyCount(typed), want, String(typed)); } });