mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-04 09:02:05 +00:00
Wire the backend's GET uplifts/can-approve tier decision into the pending row and detail modal actions. Approve/Reject now stay disabled with the plain 'Requires Tier N role' tooltip unless the backend says the current user may decide at that tier, so roles the backend refuses (Dispatcher) never get a clickable action or a refusal toast.
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const apiGet = vi.fn();
|
|
const apiPost = vi.fn();
|
|
const apiRequestRaw = vi.fn();
|
|
|
|
vi.mock("@/api/api", () => ({
|
|
apiGet: (...args: unknown[]) => apiGet(...args),
|
|
apiPost: (...args: unknown[]) => apiPost(...args),
|
|
apiRequestRaw: (...args: unknown[]) => apiRequestRaw(...args),
|
|
}));
|
|
|
|
import { upliftsApi } from "@/domain/uplifts/api/uplifts-api";
|
|
|
|
describe("upliftsApi", () => {
|
|
beforeEach(() => {
|
|
apiGet.mockReset();
|
|
apiPost.mockReset();
|
|
apiRequestRaw.mockReset();
|
|
});
|
|
|
|
it("posts admin revoke decisions to the uplift decision endpoint", async () => {
|
|
apiPost.mockResolvedValueOnce(undefined);
|
|
|
|
await upliftsApi.revoke(42, "Scope was already covered");
|
|
|
|
expect(apiPost).toHaveBeenCalledWith("uplifts/42/revoke", {
|
|
note: "Scope was already covered",
|
|
});
|
|
});
|
|
|
|
it("reads the backend tier decision permission", async () => {
|
|
apiGet.mockResolvedValueOnce({ status: "Success", data: { canApprove: true } });
|
|
|
|
await expect(upliftsApi.canApprove(1)).resolves.toBe(true);
|
|
|
|
expect(apiGet).toHaveBeenCalledWith("uplifts/can-approve", { searchParams: { tier: 1 } });
|
|
});
|
|
|
|
it("treats a missing tier permission as false", async () => {
|
|
apiGet.mockResolvedValueOnce({ status: "Success", data: {} });
|
|
|
|
await expect(upliftsApi.canApprove(2)).resolves.toBe(false);
|
|
});
|
|
});
|