fix(medusa): Cancel order missing refunds relation (#2976)

**What**

The order cancelation does not include the refunds relation. It means that the check of the length of the refund is never true and therefore no errors are thrown if the order contains the refunds.

**How**

Add the refunds relation and tests

FIXES CORE-976

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2023-01-10 10:38:59 +01:00
committed by GitHub
parent 47d075351f
commit 1817b810fc
5 changed files with 84 additions and 40 deletions

View File

@@ -288,6 +288,48 @@ describe("/admin/orders", () => {
await db.teardown()
})
it("cancels an order with refund should fail", async () => {
const api = useApi()
const refundOrder = await simpleOrderFactory(dbConnection, {
id: "refunded-order",
customer_id: "test-customer",
email: "test@email.com",
fulfillment_status: "not_fulfilled",
payment_status: "refunded",
billing_address: {
id: "test-billing-address",
first_name: "lebron",
},
shipping_address: {
id: "test-shipping-address",
first_name: "lebron",
country_code: "us",
},
region_id: "test-region",
currency_code: "usd",
tax_rate: 0,
discounts: [],
payments: [],
items: [],
refunds: [
{
amount: 1000,
reason: "return",
},
],
})
const err = await api
.post(`/admin/orders/${refundOrder.id}/cancel`, {}, adminReqConfig)
.catch((e) => e)
expect(err.response.status).toEqual(400)
expect(err.response.data.message).toEqual(
"Order with refund(s) cannot be canceled"
)
})
it("cancels an order and increments inventory_quantity", async () => {
const api = useApi()