fix: add address and customer metadata to tax calc context (#10122)

Fixes CMRC-713

**What**
- Ensure that customer and shipping address metadata is passed in the tax calculation context when updating tax lines on a cart.

**Why**
- Gives more flexibility in criteria to evaluate tax rates. 
- https://github.com/medusajs/medusa/discussions/10121
- https://github.com/medusajs/medusa/discussions/10114

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Sebastian Rindom
2024-11-19 12:42:31 +01:00
committed by GitHub
parent 3b1463048a
commit 41dc05d0c9
4 changed files with 53 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ import {
updateLineItemInCartWorkflow,
updateLineItemsStepId,
updatePaymentCollectionStepId,
updateTaxLinesWorkflow,
} from "@medusajs/core-flows"
import {
ICartModuleService,
@@ -2159,6 +2160,44 @@ medusaIntegrationTestRunner({
])
})
})
describe("updateTaxLinesWorkflow", () => {
it("should include shipping address metadata in tax calculation context", async () => {
const cart = await cartModuleService.createCarts({
currency_code: "dkk",
region_id: defaultRegion.id,
shipping_address: {
metadata: {
testing_tax: true,
},
},
items: [
{
quantity: 1,
unit_price: 5000,
title: "Test item",
},
],
})
const { transaction } = await updateTaxLinesWorkflow(
appContainer
).run({
input: {
cart_id: cart.id,
},
throwOnError: false,
})
expect(
// @ts-ignore
transaction.context.invoke["use-remote-query"].output.output
.shipping_address.metadata
).toEqual({
testing_tax: true,
})
})
})
})
},
})