test(buyer-tasks): lock wire shape of mail_failed group in po_draft

The route is a pass-through, but the smoke test guards against a
future refactor silently dropping the new emailError field — the
operator's retry affordance depends on it.

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
SJCoetz 2026-08-03 10:55:10 +02:00
parent 010bba475c
commit faaa47a4fe

View file

@ -46,6 +46,36 @@ describe("GET /api/v1/buyer-tasks", () => {
expect(body.groups[0].supplierName).toBe("Steel Co");
});
it("returns mail_failed groups when tab=po_draft (operator can retry from buyer-tasks)", async () => {
vi.mocked(listBuyerTasks).mockResolvedValue([
{
groupId: "order-1::sup-1",
orderId: "order-1",
orderNumber: "ORD-001",
supplierId: "sup-1",
supplierName: "Steel Co",
customerName: "J. Smith",
companyName: "Acme",
items: [],
itemCount: 1,
totalCost: 50,
purchaseOrderId: "po-1",
poStatus: "mail_failed",
poNumber: "PO-26080301",
supplierEmail: "orders@steelco.example",
emailError: "[webhook] Webhook returned HTTP 502",
step: "po_draft",
},
]);
const res = await GET(makeRequest("po_draft") as never);
expect(res.status).toBe(200);
const body = await res.json();
expect(body.groups).toHaveLength(1);
expect(body.groups[0].poStatus).toBe("mail_failed");
expect(body.groups[0].emailError).toMatch(/webhook/i);
});
it("returns 400 on invalid tab", async () => {
const res = await GET(makeRequest("invalid") as never);
expect(res.status).toBe(400);