feat(core-flows,types,utils,medusa): Translate tax lines (#14359)
* Include locale field for traslations on tax line workflows * Translate tax lines in getItemTaxLinesStep with new util * Update tax calculation context, so that we pass locale to third party tax providers if they want to return translated tax rates * Apply translations to tax lines on product and variant tax middlewares * Cart management translations tests * Update tax lines when order locale gets updated * Add changeset * Get tranlsated tax lines step * Fix wording * Mutate ref directly * Update order tax lines translations upon order locale change * Claims translations tests * Update tax lines upon draft order locale update * Exchange tests for tax lines translations * Order edits test for tax line translation * Add tests for shipping methods tax line translations on various order flows * Returns shipping method translations tests * Execute update in parallel * Use TranslationFeatureFlag.key * Fix feature flag import * Add @medusajs/medusa dependency for feature flag usage * Revert "Add @medusajs/medusa dependency for feature flag usage" This reverts commit e8897aed0a88f83c1034ac73e817e4222250a2c9. * Use feature flag string directly * Fix test * Parallelize tax line translations application
This commit is contained in:
@@ -36,13 +36,16 @@ medusaIntegrationTestRunner({
|
||||
let outboundShippingOption: { id: string }
|
||||
let returnShippingOption: { id: string }
|
||||
let inventoryItem: { id: string }
|
||||
let taxRate: { id: string }
|
||||
|
||||
beforeAll(async () => {
|
||||
appContainer = getContainer()
|
||||
})
|
||||
|
||||
beforeEach(async () => {
|
||||
await setupTaxStructure(appContainer.resolve(Modules.TAX))
|
||||
const taxStructure = await setupTaxStructure(
|
||||
appContainer.resolve(Modules.TAX)
|
||||
)
|
||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||
const publishableKey = await generatePublishableKey(appContainer)
|
||||
storeHeaders = generateStoreHeaders({ publishableKey })
|
||||
@@ -251,6 +254,13 @@ medusaIntegrationTestRunner({
|
||||
adminHeaders
|
||||
)
|
||||
).data.shipping_option
|
||||
const taxRatesResponse = await api.get(
|
||||
`/admin/tax-rates?tax_region_id=${taxStructure.us.children.cal.province.id}`,
|
||||
adminHeaders
|
||||
)
|
||||
taxRate = taxRatesResponse.data.tax_rates.find(
|
||||
(rate: { code: string }) => rate.code === "CADEFAULT"
|
||||
)
|
||||
|
||||
await api.post(
|
||||
"/admin/translations/batch",
|
||||
@@ -330,6 +340,22 @@ medusaIntegrationTestRunner({
|
||||
name: "Rückversand",
|
||||
},
|
||||
},
|
||||
{
|
||||
reference_id: taxRate.id,
|
||||
reference: "tax_rate",
|
||||
locale_code: "fr-FR",
|
||||
translations: {
|
||||
name: "Taux par défaut CA",
|
||||
},
|
||||
},
|
||||
{
|
||||
reference_id: taxRate.id,
|
||||
reference: "tax_rate",
|
||||
locale_code: "de-DE",
|
||||
translations: {
|
||||
name: "CA Standardsteuersatz",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
adminHeaders
|
||||
@@ -447,73 +473,21 @@ medusaIntegrationTestRunner({
|
||||
variant_title: "Moyen",
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should translate exchange items using German locale", async () => {
|
||||
const order = await createOrderFromCart("de-DE")
|
||||
|
||||
await api.post(
|
||||
`/admin/orders/${order.id}/fulfillments`,
|
||||
{
|
||||
location_id: stockLocation.id,
|
||||
items: [{ id: order.items[0].id, quantity: 1 }],
|
||||
},
|
||||
adminHeaders
|
||||
expect(newItem.tax_lines.length).toBeGreaterThan(0)
|
||||
const taxLine = newItem.tax_lines.find(
|
||||
(tl) => tl.code === "CADEFAULT"
|
||||
)
|
||||
expect(taxLine.description).toEqual("Taux par défaut CA")
|
||||
|
||||
const exchange = (
|
||||
await api.post(
|
||||
"/admin/exchanges",
|
||||
{ order_id: order.id, description: "Test exchange" },
|
||||
adminHeaders
|
||||
)
|
||||
).data.exchange
|
||||
|
||||
// Add inbound item (item being returned)
|
||||
await api.post(
|
||||
`/admin/exchanges/${exchange.id}/inbound/items`,
|
||||
{
|
||||
items: [{ id: order.items[0].id, quantity: 1 }],
|
||||
},
|
||||
adminHeaders
|
||||
const outboundShippingMethod = updatedOrder.shipping_methods.find(
|
||||
(sm) => sm.shipping_option_id === outboundShippingOption.id
|
||||
)
|
||||
|
||||
// Add outbound item (new item being sent)
|
||||
await api.post(
|
||||
`/admin/exchanges/${exchange.id}/outbound/items`,
|
||||
{
|
||||
items: [{ variant_id: product.variants[1].id, quantity: 1 }],
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
await api.post(
|
||||
`/admin/exchanges/${exchange.id}/outbound/shipping-method`,
|
||||
{ shipping_option_id: outboundShippingOption.id },
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
await api.post(
|
||||
`/admin/exchanges/${exchange.id}/request`,
|
||||
{},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
const updatedOrder = (
|
||||
await api.get(`/admin/orders/${order.id}`, adminHeaders)
|
||||
).data.order
|
||||
|
||||
const newItem = updatedOrder.items.find(
|
||||
(item: any) => item.variant_id === product.variants[1].id
|
||||
)
|
||||
|
||||
expect(newItem).toEqual(
|
||||
expect.objectContaining({
|
||||
product_title: "Medusa T-Shirt DE",
|
||||
product_description: "Ein bequemes Baumwoll-T-Shirt",
|
||||
variant_title: "Mittel",
|
||||
})
|
||||
expect(outboundShippingMethod.tax_lines.length).toBeGreaterThan(0)
|
||||
const shippingTaxLine = outboundShippingMethod.tax_lines.find(
|
||||
(tl) => tl.code === "CADEFAULT"
|
||||
)
|
||||
expect(shippingTaxLine.description).toEqual("Taux par défaut CA")
|
||||
})
|
||||
|
||||
it("should have original values when order has no locale", async () => {
|
||||
@@ -580,6 +554,21 @@ medusaIntegrationTestRunner({
|
||||
variant_title: "Medium",
|
||||
})
|
||||
)
|
||||
|
||||
expect(newItem.tax_lines.length).toBeGreaterThan(0)
|
||||
const taxLine = newItem.tax_lines.find(
|
||||
(tl) => tl.code === "CADEFAULT"
|
||||
)
|
||||
expect(taxLine.description).toEqual("CA Default Rate")
|
||||
|
||||
const outboundShippingMethod = updatedOrder.shipping_methods.find(
|
||||
(sm) => sm.shipping_option_id === outboundShippingOption.id
|
||||
)
|
||||
expect(outboundShippingMethod.tax_lines.length).toBeGreaterThan(0)
|
||||
const shippingTaxLine = outboundShippingMethod.tax_lines.find(
|
||||
(tl) => tl.code === "CADEFAULT"
|
||||
)
|
||||
expect(shippingTaxLine.description).toEqual("CA Default Rate")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user