fix: ensures no duplicate tax lines when completing cart (#1262)
* fix: ensures that no duplicate tax lines are created when completing cart
This commit is contained in:
@@ -197,6 +197,111 @@ describe("Order Taxes", () => {
|
||||
expect(response.data.order.total).toEqual(2300)
|
||||
})
|
||||
|
||||
test("completing cart with failure doesn't duplicate", async () => {
|
||||
const product1 = await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
variants: [
|
||||
{
|
||||
id: "test-variant",
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
|
||||
const product2 = await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
variants: [
|
||||
{
|
||||
id: "test-variant-2",
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
|
||||
const region = await simpleRegionFactory(dbConnection, {
|
||||
name: "Test region",
|
||||
tax_rate: 12,
|
||||
})
|
||||
|
||||
await simpleProductTaxRateFactory(dbConnection, {
|
||||
product_id: product1.id,
|
||||
rate: {
|
||||
region_id: region.id,
|
||||
rate: 25,
|
||||
},
|
||||
})
|
||||
|
||||
await simpleProductTaxRateFactory(dbConnection, {
|
||||
product_id: product2.id,
|
||||
rate: {
|
||||
region_id: region.id,
|
||||
rate: 20,
|
||||
},
|
||||
})
|
||||
|
||||
const cart = await simpleCartFactory(
|
||||
dbConnection,
|
||||
{
|
||||
region: region.id,
|
||||
email: "test@testson.com",
|
||||
line_items: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
unit_price: 100,
|
||||
},
|
||||
{
|
||||
variant_id: "test-variant-2",
|
||||
unit_price: 50,
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
|
||||
const api = useApi()
|
||||
|
||||
await api.post(`/store/carts/${cart.id}`, {
|
||||
email: "test@testson.com",
|
||||
})
|
||||
|
||||
const failedComplete = await api
|
||||
.post(`/store/carts/${cart.id}/complete`)
|
||||
.catch((err) => err.response)
|
||||
|
||||
expect(failedComplete.status).toEqual(400)
|
||||
expect(failedComplete.data.message).toEqual(
|
||||
"You cannot complete a cart without a payment session."
|
||||
)
|
||||
|
||||
await api.post(`/store/carts/${cart.id}/payment-sessions`)
|
||||
const response = await api.post(`/store/carts/${cart.id}/complete`)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
expect(response.data.type).toEqual("order")
|
||||
expect(response.data.data.tax_total).toEqual(35)
|
||||
expect(response.data.data.total).toEqual(185)
|
||||
|
||||
expect(
|
||||
response.data.data.items.flatMap((li) => li.tax_lines).length
|
||||
).toEqual(2)
|
||||
|
||||
expect(response.data.data.items[0].tax_lines).toEqual([
|
||||
expect.objectContaining({
|
||||
rate: 25,
|
||||
}),
|
||||
])
|
||||
expect(response.data.data.items[1].tax_lines).toEqual([
|
||||
expect.objectContaining({
|
||||
rate: 20,
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("completing cart creates tax lines", async () => {
|
||||
const product1 = await simpleProductFactory(
|
||||
dbConnection,
|
||||
|
||||
Reference in New Issue
Block a user