Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure tax lines are generated for all items and shipping methods in cart #10372

Merged
merged 5 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions integration-tests/http/__tests__/cart/store/cart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
let priceList

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const addShippingMethodToCartWorkflow = createWorkflow(
return cart.shipping_methods.map((sm) => sm.id)
})

const [, shippingMethodsToAdd] = parallelize(
parallelize(
removeShippingMethodFromCartStep({
shipping_method_ids: currentShippingMethods,
}),
Expand All @@ -148,7 +148,6 @@ export const addShippingMethodToCartWorkflow = createWorkflow(
updateTaxLinesWorkflow.runAsStep({
input: {
cart_id: input.cart_id,
shipping_methods: shippingMethodsToAdd,
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ export const addToCartWorkflow = createWorkflow(
updateTaxLinesWorkflow.runAsStep({
input: {
cart_id: input.cart.id,
items,
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const refreshCartItemsWorkflow = createWorkflow(
return items
})

const items = updateLineItemsStep({
updateLineItemsStep({
id: cart.id,
items: lineItems,
})
Expand All @@ -103,7 +103,7 @@ export const refreshCartItemsWorkflow = createWorkflow(
refreshCartShippingMethodsStep({ cart: refetchedCart })

updateTaxLinesWorkflow.runAsStep({
input: { cart_id: cart.id, items },
input: { cart_id: cart.id },
})

const cartPromoCodes = transform({ cart, input }, ({ cart, input }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ export const updateTaxLinesWorkflow = createWorkflow(
const taxLineItems = getItemTaxLinesStep(
transform({ input, cart }, (data) => ({
orderOrCart: data.cart,
items: data.input.items || data.cart.items,
shipping_methods:
data.input.shipping_methods || data.cart.shipping_methods,
items: data.cart.items,
shipping_methods: data.cart.shipping_methods,
force_tax_calculation: data.input.force_tax_calculation,
}))
)
Expand Down
Loading