fix: Update tax lines on cart when region changes (#9367)

**What**
- Removes broken cart retrieval step `retrieveWithCartLinks` in favor of `useRemoteQueryStep` in `updateTaxLinesWorkflows`

**Why**
- Filters variables in the step were passed with an incorrect shape
  - I removed the step, since it's only used once and the behavior is identical to the generic remote query step

**Note**
- Because the filters were passed incorrectly, the, now-removed, step has always returned the first cart in the database. As a result all tax calculations so far have been based on whatever the shape of that cart has. It basically ignores all input to this workflow
This commit is contained in:
Oli Juhl
2024-09-30 11:55:54 +00:00
committed by GitHub
parent 852df3f764
commit 8851ae7b51
9 changed files with 151 additions and 63 deletions
@@ -1001,6 +1001,137 @@ medusaIntegrationTestRunner({
)
})
it("should update tax lines on cart items when region changes", async () => {
await setupTaxStructure(taxModule)
const region = await regionModule.createRegions({
name: "us",
currency_code: "usd",
countries: ["us"],
})
const otherRegion = await regionModule.createRegions({
name: "dk",
currency_code: "dkk",
countries: ["dk"],
})
const salesChannel = await scModule.createSalesChannels({
name: "Webshop",
})
const [productWithDefaultTax] = await productModule.createProducts([
{
title: "Test product default tax",
variants: [
{ title: "Test variant default tax", manage_inventory: false },
],
},
])
const [priceSetDefaultTax] = await pricingModule.createPriceSets([
{
prices: [{ amount: 2000, currency_code: "usd" }],
},
])
await remoteLink.create([
{
Product: {
variant_id: productWithDefaultTax.variants[0].id,
},
Pricing: { price_set_id: priceSetDefaultTax.id },
},
])
await api.post(
"/admin/price-preferences",
{
attribute: "currency_code",
value: "usd",
is_tax_inclusive: true,
},
adminHeaders
)
let response = await api.post(
`/store/carts`,
{
sales_channel_id: salesChannel.id,
shipping_address: {
country_code: "us",
},
region_id: region.id,
items: [
{
variant_id: productWithDefaultTax.variants[0].id,
quantity: 1,
},
],
},
storeHeaders
)
expect(response.data.cart).toEqual(
expect.objectContaining({
id: response.data.cart.id,
currency_code: "usd",
region_id: region.id,
items: expect.arrayContaining([
expect.objectContaining({
unit_price: 2000,
quantity: 1,
title: "Test variant default tax",
tax_lines: [
// Uses the california default rate
expect.objectContaining({
description: "US Default Rate",
code: "US_DEF",
rate: 2,
provider_id: "system",
}),
],
}),
]),
})
)
response = await api.post(
`/store/carts/${response.data.cart.id}`,
{
region_id: otherRegion.id,
shipping_address: {
country_code: "dk",
},
},
storeHeaders
)
expect(response.data.cart).toEqual(
expect.objectContaining({
id: response.data.cart.id,
currency_code: "dkk",
region_id: otherRegion.id,
items: expect.arrayContaining([
expect.objectContaining({
unit_price: 2000,
quantity: 1,
title: "Test variant default tax",
tax_lines: [
// Uses the danish default rate
expect.objectContaining({
description: "Denmark Default Rate",
code: "DK_DEF",
rate: 25,
provider_id: "system",
}),
],
}),
]),
})
)
})
it("should remove invalid shipping methods", async () => {
await setupTaxStructure(taxModule)
@@ -1714,6 +1845,7 @@ medusaIntegrationTestRunner({
name: "US",
currency_code: "usd",
automatic_taxes: false,
countries: ["us"],
})
const cart = await cartModule.createCarts({