Fix/pricing update fixes (#5275)
* fix for merging line items and quantity prices * add changeset * fix draft order unit_price calculation * update test to reflect only quantity change * fix unit tests * update conditional
This commit is contained in:
@@ -950,6 +950,41 @@ describe("/admin/draft-orders", () => {
|
||||
expect(updatedDraftOrder.data.draft_order.cart.subtotal).not.toEqual(0)
|
||||
})
|
||||
|
||||
it("updates a line item on the draft order with quantity", async () => {
|
||||
const api = useApi()
|
||||
await api.post(
|
||||
"/admin/draft-orders/test-draft-order/line-items/test-item",
|
||||
{
|
||||
unit_price: 1000,
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders/test-draft-order/line-items/test-item",
|
||||
{
|
||||
quantity: 2,
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const updatedDraftOrder = await api.get(
|
||||
`/admin/draft-orders/test-draft-order`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const item = updatedDraftOrder.data.draft_order.cart.items[0]
|
||||
|
||||
expect(item.unit_price).toEqual(1000)
|
||||
expect(item.quantity).toEqual(2)
|
||||
expect(updatedDraftOrder.data.draft_order.cart.subtotal).not.toEqual(
|
||||
undefined
|
||||
)
|
||||
expect(updatedDraftOrder.data.draft_order.cart.subtotal).not.toEqual(0)
|
||||
})
|
||||
|
||||
it("removes the line item, if quantity is 0", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
@@ -1017,6 +1017,44 @@ describe("/store/carts", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("updates line item quantity with unit price reflected when merging line-items", async () => {
|
||||
const api = useApi()
|
||||
|
||||
await simplePriceListFactory(dbConnection, {
|
||||
id: "pl_current",
|
||||
prices: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
amount: 10,
|
||||
min_quantity: 5,
|
||||
currency_code: "usd",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const response = await api
|
||||
.post(
|
||||
"/store/carts/test-cart-3/line-items",
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
quantity: 4,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
.catch(console.log)
|
||||
|
||||
expect(response.data.cart.items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
cart_id: "test-cart-3",
|
||||
unit_price: 10,
|
||||
variant_id: "test-variant",
|
||||
quantity: 5,
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("creates and updates line item quantity with unit price reflected", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user