fix(medusa): Double tax issue on return refund amount (#4899)

Closes #4686 

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Josip Matić
2023-09-05 10:14:45 +02:00
committed by GitHub
parent 1e3c93a319
commit bb5ea9d5ca
6 changed files with 316 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ const { useDb } = require("../../../environment-helpers/use-db")
const {
simpleProductFactory,
simpleOrderFactory,
simpleShippingOptionFactory,
} = require("../../../factories")
const adminSeeder = require("../../../helpers/admin-seeder")
@@ -275,4 +276,62 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
])
)
})
it("creates a store return with tax inclusive shipping option", async () => {
await adminSeeder(dbConnection)
const order = await createReturnableOrder(dbConnection, {
includes_tax: true,
})
const returnOption = await simpleShippingOptionFactory(dbConnection, {
name: "Return method",
region_id: "test-region",
is_return: true,
price: 1000,
includes_tax: true,
})
const api = useApi()
const response = await api.post(
`/store/returns`,
{
order_id: order.id,
return_shipping: {
option_id: returnOption.id,
},
items: [
{
item_id: "test-item",
quantity: 1,
note: "TOO SMALL",
},
],
},
{
headers: {
authorization: "Bearer test_token",
},
}
)
expect(response.status).toEqual(200)
/*
* Region has default tax rate 12.5 but line item has tax rate 20
* therefore refund amount should be 1000 * 1.2 = 1200
* shipping method will have tax inclusive price of 1000
*/
expect(response.data.return.refund_amount).toEqual(200)
expect(response.data.return.items).toHaveLength(1)
expect(response.data.return.items).toEqual(
expect.arrayContaining([
expect.objectContaining({
item_id: "test-item",
quantity: 1,
note: "TOO SMALL",
}),
])
)
})
})

View File

@@ -189,6 +189,56 @@ describe("/admin/orders", () => {
)
})
test("creates a store return with tax exclusive shipping option", async () => {
await adminSeeder(dbConnection)
const order = await createReturnableOrder(dbConnection, { oldTaxes: false })
const returnOption = await simpleShippingOptionFactory(dbConnection, {
name: "Return method",
region_id: "test-region",
is_return: true,
price: 1000,
})
const api = useApi()
const response = await api.post(
`/store/returns`,
{
order_id: order.id,
return_shipping: {
option_id: returnOption.id,
},
items: [
{
item_id: "test-item",
quantity: 1,
note: "TOO SMALL",
},
],
},
adminHeaders
)
expect(response.status).toEqual(200)
/*
* Region has default tax rate 12.5 but line item has tax rate 20
* therefore refund amount should be 1000 * 1.2 = 1200
* shipping method will have 12.5 rate 1000 * 1.125 = 1125
*/
expect(response.data.return.refund_amount).toEqual(75)
expect(response.data.return.items).toHaveLength(1)
expect(response.data.return.items).toEqual(
expect.arrayContaining([
expect.objectContaining({
item_id: "test-item",
quantity: 1,
note: "TOO SMALL",
}),
])
)
})
test("creates a return w. discount", async () => {
await adminSeeder(dbConnection)
const order = await createReturnableOrder(dbConnection, {