fix: Ensure tax lines are generated for all items and shipping methods in cart (#10372)
* fix: Generate tax lines for all items in cart * fix: Correct test
This commit is contained in:
1 parent
94f6265dfc
commit
eacd691951
6 files changed
+98
-9
No files matched your search
@@ -362,6 +362,91 @@ medusaIntegrationTestRunner({
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should add item to cart with tax lines multiple times", async () => {
|
||||||
|
let response = await api.post(
|
||||||
|
`/store/carts/${cart.id}/line-items`,
|
||||||
|
{
|
||||||
|
variant_id: product.variants[0].id,
|
||||||
|
quantity: 1,
|
||||||
|
},
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.cart).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: cart.id,
|
||||||
|
currency_code: "usd",
|
||||||
|
items: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
unit_price: 1500,
|
||||||
|
compare_at_unit_price: null,
|
||||||
|
is_tax_inclusive: true,
|
||||||
|
title: "S / Black",
|
||||||
|
quantity: 2,
|
||||||
|
tax_lines: [
|
||||||
|
expect.objectContaining({
|
||||||
|
description: "CA Default Rate",
|
||||||
|
code: "CADEFAULT",
|
||||||
|
rate: 5,
|
||||||
|
provider_id: "system",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
response = await api.post(
|
||||||
|
`/store/carts/${cart.id}/line-items`,
|
||||||
|
{
|
||||||
|
variant_id: product.variants[1].id,
|
||||||
|
quantity: 1,
|
||||||
|
},
|
||||||
|
storeHeaders
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.status).toEqual(200)
|
||||||
|
expect(response.data.cart).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: cart.id,
|
||||||
|
currency_code: "usd",
|
||||||
|
items: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
unit_price: 1500,
|
||||||
|
compare_at_unit_price: null,
|
||||||
|
is_tax_inclusive: true,
|
||||||
|
quantity: 2,
|
||||||
|
title: "S / Black",
|
||||||
|
tax_lines: [
|
||||||
|
expect.objectContaining({
|
||||||
|
description: "CA Default Rate",
|
||||||
|
code: "CADEFAULT",
|
||||||
|
rate: 5,
|
||||||
|
provider_id: "system",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
unit_price: 1500,
|
||||||
|
compare_at_unit_price: null,
|
||||||
|
is_tax_inclusive: true,
|
||||||
|
quantity: 1,
|
||||||
|
title: "S / White",
|
||||||
|
tax_lines: [
|
||||||
|
expect.objectContaining({
|
||||||
|
description: "CA Default Rate",
|
||||||
|
code: "CADEFAULT",
|
||||||
|
rate: 5,
|
||||||
|
provider_id: "system",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
describe("with sale price lists", () => {
|
describe("with sale price lists", () => {
|
||||||
let priceList
|
let priceList
|
||||||
|
|
||||||
|
|||||||
@@ -876,7 +876,14 @@ medusaIntegrationTestRunner({
|
|||||||
is_tax_inclusive: false,
|
is_tax_inclusive: false,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
title: "Test item",
|
title: "Test item",
|
||||||
tax_lines: [],
|
tax_lines: [
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "CADEFAULT",
|
||||||
|
description: "CA Default Rate",
|
||||||
|
provider_id: "system",
|
||||||
|
rate: 5,
|
||||||
|
}),
|
||||||
|
],
|
||||||
adjustments: [
|
adjustments: [
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.not.stringContaining(lineItemAdjustment.id),
|
id: expect.not.stringContaining(lineItemAdjustment.id),
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ export const addShippingMethodToCartWorkflow = createWorkflow(
|
|||||||
return cart.shipping_methods.map((sm) => sm.id)
|
return cart.shipping_methods.map((sm) => sm.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
const [, shippingMethodsToAdd] = parallelize(
|
parallelize(
|
||||||
removeShippingMethodFromCartStep({
|
removeShippingMethodFromCartStep({
|
||||||
shipping_method_ids: currentShippingMethods,
|
shipping_method_ids: currentShippingMethods,
|
||||||
}),
|
}),
|
||||||
@@ -148,7 +148,6 @@ export const addShippingMethodToCartWorkflow = createWorkflow(
|
|||||||
updateTaxLinesWorkflow.runAsStep({
|
updateTaxLinesWorkflow.runAsStep({
|
||||||
input: {
|
input: {
|
||||||
cart_id: input.cart_id,
|
cart_id: input.cart_id,
|
||||||
shipping_methods: shippingMethodsToAdd,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ export const addToCartWorkflow = createWorkflow(
|
|||||||
updateTaxLinesWorkflow.runAsStep({
|
updateTaxLinesWorkflow.runAsStep({
|
||||||
input: {
|
input: {
|
||||||
cart_id: input.cart.id,
|
cart_id: input.cart.id,
|
||||||
items,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export const refreshCartItemsWorkflow = createWorkflow(
|
|||||||
return items
|
return items
|
||||||
})
|
})
|
||||||
|
|
||||||
const items = updateLineItemsStep({
|
updateLineItemsStep({
|
||||||
id: cart.id,
|
id: cart.id,
|
||||||
items: lineItems,
|
items: lineItems,
|
||||||
})
|
})
|
||||||
@@ -103,7 +103,7 @@ export const refreshCartItemsWorkflow = createWorkflow(
|
|||||||
refreshCartShippingMethodsStep({ cart: refetchedCart })
|
refreshCartShippingMethodsStep({ cart: refetchedCart })
|
||||||
|
|
||||||
updateTaxLinesWorkflow.runAsStep({
|
updateTaxLinesWorkflow.runAsStep({
|
||||||
input: { cart_id: cart.id, items },
|
input: { cart_id: cart.id },
|
||||||
})
|
})
|
||||||
|
|
||||||
const cartPromoCodes = transform({ cart, input }, ({ cart, input }) => {
|
const cartPromoCodes = transform({ cart, input }, ({ cart, input }) => {
|
||||||
|
|||||||
@@ -86,9 +86,8 @@ export const updateTaxLinesWorkflow = createWorkflow(
|
|||||||
const taxLineItems = getItemTaxLinesStep(
|
const taxLineItems = getItemTaxLinesStep(
|
||||||
transform({ input, cart }, (data) => ({
|
transform({ input, cart }, (data) => ({
|
||||||
orderOrCart: data.cart,
|
orderOrCart: data.cart,
|
||||||
items: data.input.items || data.cart.items,
|
items: data.cart.items,
|
||||||
shipping_methods:
|
shipping_methods: data.cart.shipping_methods,
|
||||||
data.input.shipping_methods || data.cart.shipping_methods,
|
|
||||||
force_tax_calculation: data.input.force_tax_calculation,
|
force_tax_calculation: data.input.force_tax_calculation,
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user