feat(medusa): remove created reservations on subsequent failure for cart completion (#3554)

**What**
- If cart completion fails after creating reservations, remove those reservations

**Why**
- To avoid hanging reservations if something fails at a later point
This commit is contained in:
Philip Korsholm
2023-03-29 19:03:53 +02:00
committed by GitHub
parent a7e3f2d343
commit 5fd74b38ae
7 changed files with 160 additions and 43 deletions

View File

@@ -2,17 +2,25 @@
exports[`/store/carts POST /store/carts/:id fails to complete cart with items inventory not/partially covered 1`] = `
Object {
"code": "insufficient_inventory",
"message": "Variant with id: test-variant-2 does not have the required inventory",
"type": "not_allowed",
"errors": Array [
Object {
"code": "insufficient_inventory",
"message": "Variant with id: test-variant-2 does not have the required inventory",
"type": "not_allowed",
},
],
}
`;
exports[`/store/carts POST /store/carts/:id fails to complete swap cart with items inventory not/partially covered 1`] = `
Object {
"code": "insufficient_inventory",
"message": "Variant with id: test-variant-2 does not have the required inventory",
"type": "not_allowed",
"errors": Array [
Object {
"code": "insufficient_inventory",
"message": "Variant with id: test-variant-2 does not have the required inventory",
"type": "not_allowed",
},
],
}
`;

View File

@@ -1948,7 +1948,7 @@ describe("/store/carts", () => {
await api.post(`/store/carts/test-cart-2/complete-cart`)
} catch (e) {
expect(e.response.data).toMatchSnapshot({
code: "insufficient_inventory",
errors: [{ code: "insufficient_inventory" }],
})
expect(e.response.status).toBe(409)
}
@@ -1984,7 +1984,7 @@ describe("/store/carts", () => {
await api.post(`/store/carts/swap-cart/complete-cart`)
} catch (e) {
expect(e.response.data).toMatchSnapshot({
code: "insufficient_inventory",
errors: [{ code: "insufficient_inventory" }],
})
expect(e.response.status).toBe(409)
}

View File

@@ -343,8 +343,8 @@ describe("/store/carts", () => {
})
expect(responseFail.status).toEqual(409)
expect(responseFail.data.type).toEqual("not_allowed")
expect(responseFail.data.code).toEqual(
expect(responseFail.data.errors[0].type).toEqual("not_allowed")
expect(responseFail.data.errors[0].code).toEqual(
MedusaError.Codes.INSUFFICIENT_INVENTORY
)