mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 12:03:12 +00:00
SH-214/SH-212 own that action on Uplift Approvals; the WO surface only revokes the requester's auto-approved uplift.
89 lines
3 KiB
TypeScript
89 lines
3 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",
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("rejects a dispatcher revoking another user's auto-approved uplift", () => {
|
|
expect(
|
|
canRevokeWorkOrderUplift(
|
|
{ status: "auto_approved", requestedById: "other-dispatcher" },
|
|
"dispatcher-1",
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("rejects admin revoking auto-approved uplift they did not request", () => {
|
|
expect(
|
|
canRevokeWorkOrderUplift(
|
|
{ status: "auto_approved", requestedById: "dispatcher-1" },
|
|
"admin-user",
|
|
),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("allows admin to revoke their own auto-approved uplift as the requester", () => {
|
|
expect(
|
|
canRevokeWorkOrderUplift(
|
|
{ status: "auto_approved", requestedById: "admin-user" },
|
|
"admin-user",
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
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")).toBe(false);
|
|
expect(canRevokeWorkOrderUplift(uplift, "admin-user")).toBe(false);
|
|
});
|
|
|
|
it("rejects revoke for other statuses", () => {
|
|
expect(canRevokeWorkOrderUplift({ status: "pending", requestedById: "u1" }, "u1")).toBe(false);
|
|
expect(canRevokeWorkOrderUplift({ status: "rejected", requestedById: "u1" }, "u1")).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);
|
|
});
|
|
});
|