import { describe, expect, it } from "vitest"; import { canCancelTask } from "./taskCancellation"; import type { TaskStatus } from "./types"; describe("canCancelTask", () => { it.each(["queued", "assigned", "dispatched"])( "allows cancelling a %s task when the caller can submit", (status) => { expect(canCancelTask(status, true)).toBe(true); }, ); it.each(["done", "failed", "cancelled"])( "refuses to cancel a terminal %s task even when the caller can submit", (status) => { expect(canCancelTask(status, true)).toBe(false); }, ); it("refuses to cancel a cancellable task when the caller lacks submit permission", () => { expect(canCancelTask("assigned", false)).toBe(false); }); });