mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 09:13:11 +00:00
Admins may revoke only admin-approved uplifts. The Work Order Uplifts dialog showed Revoke to whoever requested an auto-approved uplift, so an admin requester saw it and was sent into the optional-reason revoke flow.
97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
canRevokeWorkOrderUplift,
|
|
getRemainingUpliftAllowance,
|
|
hasOpenWorkOrderUplift,
|
|
upliftRevokeRequiresReason,
|
|
} from "@/domain/work-orders/utils/uplift-display-utils";
|
|
|
|
describe("canRevokeWorkOrderUplift", () => {
|
|
it("allows a dispatcher to revoke their own auto-approved uplift", () => {
|
|
expect(
|
|
canRevokeWorkOrderUplift(
|
|
{ status: "auto_approved", requestedById: "dispatcher-1" },
|
|
"dispatcher-1",
|
|
false,
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("rejects a dispatcher revoking another user's auto-approved uplift", () => {
|
|
expect(
|
|
canRevokeWorkOrderUplift(
|
|
{ status: "auto_approved", requestedById: "other-dispatcher" },
|
|
"dispatcher-1",
|
|
false,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("rejects admin revoking auto-approved uplift they did not request", () => {
|
|
expect(
|
|
canRevokeWorkOrderUplift(
|
|
{ status: "auto_approved", requestedById: "dispatcher-1" },
|
|
"admin-user",
|
|
true,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("rejects admin revoking an auto-approved uplift even as its requester", () => {
|
|
expect(
|
|
canRevokeWorkOrderUplift(
|
|
{ status: "auto_approved", requestedById: "admin-user" },
|
|
"admin-user",
|
|
true,
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("rejects approved revoke on the Work Order surface (SH-214)", () => {
|
|
const uplift = { status: "approved" as const, requestedById: "dispatcher-1" };
|
|
expect(canRevokeWorkOrderUplift(uplift, "dispatcher-1", false)).toBe(false);
|
|
expect(canRevokeWorkOrderUplift(uplift, "admin-user", true)).toBe(false);
|
|
});
|
|
|
|
it("rejects revoke for other statuses", () => {
|
|
expect(canRevokeWorkOrderUplift({ status: "pending", requestedById: "u1" }, "u1", false)).toBe(
|
|
false,
|
|
);
|
|
expect(canRevokeWorkOrderUplift({ status: "rejected", requestedById: "u1" }, "u1", false)).toBe(
|
|
false,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("upliftRevokeRequiresReason", () => {
|
|
it("requires reason only for approved uplifts", () => {
|
|
expect(upliftRevokeRequiresReason("approved")).toBe(true);
|
|
expect(upliftRevokeRequiresReason("auto_approved")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("SH-196 allowance helpers", () => {
|
|
it("uses a $500 cap for non-emergency work orders", () => {
|
|
expect(getRemainingUpliftAllowance("PM", [])).toBe(500);
|
|
expect(getRemainingUpliftAllowance("PM", [{ status: "auto_approved", amount: 400 }])).toBe(100);
|
|
});
|
|
|
|
it("uses a $5,000 cap for emergency work orders", () => {
|
|
expect(getRemainingUpliftAllowance("Emergency", [])).toBe(5000);
|
|
});
|
|
|
|
it("ignores revoked and pending amounts when computing remaining allowance", () => {
|
|
expect(
|
|
getRemainingUpliftAllowance("PM", [
|
|
{ status: "auto_approved", amount: 200 },
|
|
{ status: "revoked", amount: 300 },
|
|
{ status: "pending", amount: 400 },
|
|
]),
|
|
).toBe(300);
|
|
});
|
|
|
|
it("detects an open pending request", () => {
|
|
expect(hasOpenWorkOrderUplift([{ status: "pending" }])).toBe(true);
|
|
expect(hasOpenWorkOrderUplift([{ status: "auto_approved" }])).toBe(false);
|
|
});
|
|
});
|