feat(sp6): inbox api client + types

This commit is contained in:
Tyler
2026-06-20 18:36:14 -06:00
parent f4baceb574
commit f3e5d800e1
2 changed files with 192 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
import { describe, expect, it, vi } from "vitest";
import {
fetchInboxLanes,
matchCandidate,
dismissCandidates,
resubmitRejected,
exportInboxCsvUrl,
} from "./inbox-api";
const BASE = "http://test.local";
describe("inbox-api", () => {
it("fetchInboxLanes hits /api/inbox/lanes", async () => {
const fetchSpy = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ rejected: [], candidates: [], unmatched: [], done_today: [] }),
});
vi.stubGlobal("fetch", fetchSpy);
const lanes = await fetchInboxLanes();
expect(fetchSpy).toHaveBeenCalledWith(`${BASE}/api/inbox/lanes`);
expect(lanes.rejected).toEqual([]);
vi.unstubAllGlobals();
});
it("matchCandidate posts to the candidates/{remit_id}/match endpoint", async () => {
const fetchSpy = vi.fn().mockResolvedValue({ ok: true, json: async () => ({}) });
vi.stubGlobal("fetch", fetchSpy);
await matchCandidate("R-1", "C-1");
expect(fetchSpy).toHaveBeenCalledWith(
`${BASE}/api/inbox/candidates/R-1/match`,
expect.objectContaining({
method: "POST",
body: JSON.stringify({ claim_id: "C-1" }),
}),
);
vi.unstubAllGlobals();
});
it("dismissCandidates posts pairs", async () => {
const fetchSpy = vi.fn().mockResolvedValue({ ok: true, json: async () => ({}) });
vi.stubGlobal("fetch", fetchSpy);
await dismissCandidates([{ claim_id: "C-1", remit_id: "R-1" }]);
expect(fetchSpy).toHaveBeenCalledWith(
`${BASE}/api/inbox/candidates/dismiss`,
expect.objectContaining({
method: "POST",
body: JSON.stringify({ pairs: [{ claim_id: "C-1", remit_id: "R-1" }] }),
}),
);
vi.unstubAllGlobals();
});
it("resubmitRejected posts claim_ids", async () => {
const fetchSpy = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({ ok: true, resubmitted: ["C-1"], conflicts: [] }),
});
vi.stubGlobal("fetch", fetchSpy);
const r = await resubmitRejected(["C-1"]);
expect(fetchSpy).toHaveBeenCalledWith(
`${BASE}/api/inbox/rejected/resubmit`,
expect.objectContaining({ method: "POST" }),
);
expect(r.resubmitted).toEqual(["C-1"]);
vi.unstubAllGlobals();
});
it("exportInboxCsvUrl returns the export endpoint with the lane", () => {
expect(exportInboxCsvUrl("rejected")).toBe(`${BASE}/api/inbox/export.csv?lane=rejected`);
});
});