fix(collection-confirm): make listCollectedItems stock leg fail-soft
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
parent
efe10b9474
commit
15f6ec638d
2 changed files with 45 additions and 1 deletions
|
|
@ -220,6 +220,47 @@ describe("listCollectedItems", () => {
|
|||
const sources = rows.map((r) => r.source).sort();
|
||||
expect(sources).toEqual(["customer", "stock"]);
|
||||
});
|
||||
|
||||
it("returns order_items rows when stock_purchase_items leg throws", async () => {
|
||||
// Mirrors the page's `load()` fail-soft behaviour at page.tsx:294:
|
||||
// the stock leg is wrapped in `.catch(() => [])` so a stock-side
|
||||
// outage doesn't kill the customer-leg results.
|
||||
const orderItem = {
|
||||
id: "oi-1",
|
||||
item_status: "collected",
|
||||
description: "M20 × 40 hex nuts",
|
||||
order_qty: 100,
|
||||
qty_collected: 100,
|
||||
expand: {
|
||||
purchase_order: { id: "po-1", po_number: "PO-1" },
|
||||
order: { id: "o-1" },
|
||||
},
|
||||
};
|
||||
const orderItemsGetFullList = vi.fn().mockResolvedValue([orderItem]);
|
||||
const stockItemsGetFullList = vi
|
||||
.fn()
|
||||
.mockRejectedValue(new Error("stock side down"));
|
||||
const admin = {
|
||||
collection: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === "order_items") {
|
||||
return { getFullList: orderItemsGetFullList };
|
||||
}
|
||||
if (name === "stock_purchase_items") {
|
||||
return { getFullList: stockItemsGetFullList };
|
||||
}
|
||||
throw new Error(`unexpected collection ${name}`);
|
||||
}),
|
||||
};
|
||||
vi.mocked(getAdminPocketBase).mockResolvedValue(admin as never);
|
||||
|
||||
const rows = await listCollectedItems();
|
||||
|
||||
expect(rows).toHaveLength(1);
|
||||
const row = rows[0]!;
|
||||
expect(row.id).toBe("oi-1");
|
||||
expect(row.source).toBe("customer");
|
||||
expect(stockItemsGetFullList).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("stubs for plan tasks 4 and 5", () => {
|
||||
|
|
|
|||
|
|
@ -134,7 +134,10 @@ export async function listCollectedItems(): Promise<ConfirmRow[]> {
|
|||
filter: 'status = "collected"',
|
||||
sort: "-created",
|
||||
expand: "purchase.supplier,purchase,stock_item",
|
||||
}),
|
||||
})
|
||||
// Fail-soft: matches the page's `load()` at page.tsx:294 — a
|
||||
// stock-side outage must not wipe the customer-deliveries view.
|
||||
.catch(() => [] as unknown[]),
|
||||
]);
|
||||
|
||||
// Normalise stock rows into ConfirmRow shape. Stock fields that don't
|
||||
|
|
|
|||
Loading…
Reference in a new issue