fix(medusa): Remove shipping on updates to cart.items (#4715)
* rm shipping on line item updates * Add tests * remove verbose flag * Create real-items-rhyme.md
This commit is contained in:
@@ -1623,7 +1623,8 @@ describe("/store/carts", () => {
|
||||
|
||||
const cart = response.data.cart
|
||||
|
||||
const shippingAmount = 1000
|
||||
// shipping is 0 because of line item update
|
||||
const shippingAmount = 0
|
||||
const expectedTotal =
|
||||
quantity * variant1Price +
|
||||
quantity * variant2Price +
|
||||
@@ -1635,7 +1636,7 @@ describe("/store/carts", () => {
|
||||
expect(cart.total).toBe(expectedTotal)
|
||||
expect(cart.subtotal).toBe(expectedSubtotal)
|
||||
expect(cart.discount_total).toBe(discountAmount)
|
||||
expect(cart.shipping_total).toBe(1000)
|
||||
expect(cart.shipping_total).toBe(shippingAmount)
|
||||
})
|
||||
|
||||
it("updates cart customer id", async () => {
|
||||
@@ -1648,6 +1649,87 @@ describe("/store/carts", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("should remove shipping on line item remove", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const cartId = "test-cart-2"
|
||||
const lineId = "test-item"
|
||||
const optionId = "test-option"
|
||||
|
||||
await api.post(
|
||||
`/store/carts/${cartId}/shipping-methods`,
|
||||
{
|
||||
option_id: optionId,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
|
||||
const cart = await api.get(`/store/carts/${cartId}`)
|
||||
|
||||
expect(cart.data.cart.shipping_total).toEqual(1000)
|
||||
|
||||
const response = await api.delete(
|
||||
`/store/carts/${cartId}/line-items/${lineId}`
|
||||
)
|
||||
|
||||
expect(response.data.cart.shipping_total).toEqual(0)
|
||||
})
|
||||
|
||||
it("should remove shipping on line item update", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const cartId = "test-cart-2"
|
||||
const lineId = "test-item"
|
||||
const optionId = "test-option"
|
||||
|
||||
await api.post(
|
||||
`/store/carts/${cartId}/shipping-methods`,
|
||||
{
|
||||
option_id: optionId,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
|
||||
const cart = await api.get(`/store/carts/${cartId}`)
|
||||
|
||||
expect(cart.data.cart.shipping_total).toEqual(1000)
|
||||
|
||||
const response = await api.post(
|
||||
`/store/carts/${cartId}/line-items/${lineId}`,
|
||||
{
|
||||
quantity: 2,
|
||||
}
|
||||
)
|
||||
|
||||
expect(response.data.cart.shipping_total).toEqual(0)
|
||||
})
|
||||
|
||||
it("should remove shipping on line item add", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const cartId = "test-cart-2"
|
||||
const optionId = "test-option"
|
||||
|
||||
await api.post(
|
||||
`/store/carts/${cartId}/shipping-methods`,
|
||||
{
|
||||
option_id: optionId,
|
||||
},
|
||||
{ withCredentials: true }
|
||||
)
|
||||
|
||||
const cart = await api.get(`/store/carts/${cartId}`)
|
||||
|
||||
expect(cart.data.cart.shipping_total).toEqual(1000)
|
||||
|
||||
const response = await api.post(`/store/carts/${cartId}/line-items`, {
|
||||
variant_id: "test-variant-sale-customer",
|
||||
quantity: 1,
|
||||
})
|
||||
|
||||
expect(response.data.cart.shipping_total).toEqual(0)
|
||||
})
|
||||
|
||||
it("updates prices when cart customer id is updated", async () => {
|
||||
const api = useApi()
|
||||
|
||||
@@ -1958,8 +2040,9 @@ describe("/store/carts", () => {
|
||||
expect(getRes.status).toEqual(200)
|
||||
expect(getRes.data.type).toEqual("order")
|
||||
|
||||
// inventory pre-purchase was 10
|
||||
const variantRes = await api.get("/store/variants/test-variant")
|
||||
expect(variantRes.data.variant.inventory_quantity).toEqual(0)
|
||||
expect(variantRes.data.variant.inventory_quantity).toEqual(9)
|
||||
})
|
||||
|
||||
it("calculates correct payment totals on cart completion taking into account line item adjustments", async () => {
|
||||
@@ -2332,7 +2415,8 @@ describe("/store/carts", () => {
|
||||
}),
|
||||
])
|
||||
)
|
||||
expect(cartWithGiftcard.data.cart.total).toBe(2900) // 1000 (giftcard) + 900 (standard item with 10% discount) + 1000 Shipping
|
||||
expect(cartWithGiftcard.data.cart.total).toBe(1900) // 1000 (giftcard) + 900 (standard item with 10% discount) - 1000 Shipping (because of line item update)
|
||||
expect(cartWithGiftcard.data.cart.shipping_total).toBe(0) // 0 because of line item update
|
||||
expect(cartWithGiftcard.data.cart.discount_total).toBe(100)
|
||||
expect(cartWithGiftcard.status).toEqual(200)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user