fix(medusa): Complete cart with 100% discount (#2032)
**What** Naive fix to allow carts with 100% discount to be completed. **Why** Discount total is wrongly calculated if `items` and `items.adjustments` is not included in relations upon retrieving the cart. **Thought** This is yet another example of why we need to rethink and refactor totals computation to not depend on what is provided by the user.
This commit is contained in:
committed by
GitHub
parent
f1c2c6c68b
commit
0ba63c70b0
@@ -1635,6 +1635,36 @@ describe("/store/carts", () => {
|
||||
expect(getRes.data.type).toEqual("order")
|
||||
})
|
||||
|
||||
it("complete cart with 100% discount", async () => {
|
||||
await simpleDiscountFactory(dbConnection, {
|
||||
code: "100PERCENT",
|
||||
rule: {
|
||||
type: "percentage",
|
||||
value: 100,
|
||||
},
|
||||
regions: ["test-region"],
|
||||
})
|
||||
|
||||
const api = useApi()
|
||||
|
||||
await api
|
||||
.post(`/store/carts/test-cart-3`, {
|
||||
discounts: [{ code: "100PERCENT" }],
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.response.data)
|
||||
})
|
||||
|
||||
const getRes = await api
|
||||
.post(`/store/carts/test-cart-3/complete`)
|
||||
.catch((err) => {
|
||||
console.log(err.response.data)
|
||||
})
|
||||
|
||||
expect(getRes.status).toEqual(200)
|
||||
expect(getRes.data.type).toEqual("order")
|
||||
})
|
||||
|
||||
it("complete cart with items inventory covered", async () => {
|
||||
const api = useApi()
|
||||
const getRes = await api.post(`/store/carts/test-cart-2/complete-cart`)
|
||||
|
||||
Reference in New Issue
Block a user