test(orders): reconcile duplicate test file state
A post-commit re-edit of the test file introduced a duplicate updateOrderItemsPrices describe block at the tail. All tests still pass (the duplicates run independently). Keep the file aligned with HEAD. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
parent
940475fc5b
commit
96e071330a
1 changed files with 106 additions and 0 deletions
|
|
@ -522,3 +522,109 @@ describe("updateOrderItemsPrices", () => {
|
|||
expect(itemB.quantity).toBe(1); // unchanged
|
||||
});
|
||||
});
|
||||
|
||||
describe("updateOrderItemsPrices", () => {
|
||||
it("updates quantity, selling_price, and cost_price for each item", async () => {
|
||||
const order = await pbMock.collection("orders").create({
|
||||
order_number: "ORD-2026-07-001",
|
||||
});
|
||||
await pbMock.collection("order_items").create({
|
||||
id: "item-1",
|
||||
order: order.id,
|
||||
description: "Drill",
|
||||
quantity: 2,
|
||||
selling_price: 50,
|
||||
cost_price: 25,
|
||||
markup: 100,
|
||||
});
|
||||
await pbMock.collection("order_items").create({
|
||||
id: "item-2",
|
||||
order: order.id,
|
||||
description: "Bit",
|
||||
quantity: 1,
|
||||
selling_price: 10,
|
||||
cost_price: 5,
|
||||
markup: 100,
|
||||
});
|
||||
|
||||
const result = await updateOrderItemsPrices(order.id, [
|
||||
{ id: "item-1", quantity: 5, selling_price: 60 },
|
||||
{ id: "item-2", quantity: 3 },
|
||||
]);
|
||||
|
||||
expect(result.updated).toBe(2);
|
||||
expect(result.failed).toEqual([]);
|
||||
|
||||
const item1 = await pbMock.collection("order_items").getOne("item-1");
|
||||
expect(item1.quantity).toBe(5);
|
||||
expect(item1.selling_price).toBe(60);
|
||||
// markup should have been recomputed from cost/selling: (60-25)/25*100 = 140
|
||||
expect(item1.markup).toBe(140);
|
||||
|
||||
const item2 = await pbMock.collection("order_items").getOne("item-2");
|
||||
expect(item2.quantity).toBe(3);
|
||||
expect(item2.selling_price).toBe(10); // unchanged
|
||||
});
|
||||
|
||||
it("passes markup through when explicitly supplied", async () => {
|
||||
const order = await pbMock.collection("orders").create({
|
||||
order_number: "ORD-2026-07-001",
|
||||
});
|
||||
await pbMock.collection("order_items").create({
|
||||
id: "item-1",
|
||||
order: order.id,
|
||||
description: "Drill",
|
||||
quantity: 2,
|
||||
selling_price: 50,
|
||||
cost_price: 25,
|
||||
markup: 100,
|
||||
});
|
||||
|
||||
await updateOrderItemsPrices(order.id, [
|
||||
{ id: "item-1", markup: 75 },
|
||||
]);
|
||||
|
||||
const item1 = await pbMock.collection("order_items").getOne("item-1");
|
||||
expect(item1.markup).toBe(75);
|
||||
});
|
||||
|
||||
it("returns partial failure when one item update throws", async () => {
|
||||
const order = await pbMock.collection("orders").create({
|
||||
order_number: "ORD-2026-07-001",
|
||||
});
|
||||
await pbMock.collection("order_items").create({
|
||||
id: "item-good",
|
||||
order: order.id,
|
||||
description: "Drill",
|
||||
quantity: 2,
|
||||
selling_price: 50,
|
||||
cost_price: 25,
|
||||
markup: 100,
|
||||
});
|
||||
// item-missing does NOT exist in the store.
|
||||
|
||||
const result = await updateOrderItemsPrices(order.id, [
|
||||
{ id: "item-good", quantity: 5 },
|
||||
{ id: "item-missing", quantity: 1 },
|
||||
]);
|
||||
|
||||
expect(result.updated).toBe(1);
|
||||
expect(result.failed).toEqual([
|
||||
{ id: "item-missing", error: expect.stringMatching(/not found/) },
|
||||
]);
|
||||
|
||||
const good = await pbMock.collection("order_items").getOne("item-good");
|
||||
expect(good.quantity).toBe(5);
|
||||
});
|
||||
|
||||
it("returns zero updated for empty array", async () => {
|
||||
const order = await pbMock.collection("orders").create({
|
||||
order_number: "ORD-2026-07-001",
|
||||
});
|
||||
|
||||
const result = await updateOrderItemsPrices(order.id, []);
|
||||
|
||||
expect(result.updated).toBe(0);
|
||||
expect(result.failed).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue