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 09:38:59 +00:00
committed by GitHub
co-authored by Oliver Windall Juhl
parent 47d075351f
commit 1817b810fc
5 changed files with 84 additions and 40 deletions
@@ -647,6 +647,17 @@ describe("OrderService", () => {
payment_status: "paid",
status: "pending",
})
case IdMap.getId("refunded-order"):
return Promise.resolve({
fulfillment_status: "fulfilled",
payment_status: "refunded",
refunds: [
{
order_id: IdMap.getId("refunded-order"),
},
],
status: "pending",
})
default:
return Promise.resolve({
fulfillment_status: "not_fulfilled",
@@ -729,6 +740,12 @@ describe("OrderService", () => {
],
})
})
it("fails if order has refunds", async () => {
await expect(
orderService.cancel(IdMap.getId("refunded-order"))
).rejects.toThrow("Order with refund(s) cannot be canceled")
})
})
describe("capturePayment", () => {
+5 -4
View File
@@ -37,18 +37,18 @@ import {
DiscountService,
DraftOrderService,
EventBusService,
FulfillmentService,
FulfillmentProviderService,
FulfillmentService,
GiftCardService,
ProductVariantInventoryService,
LineItemService,
NewTotalsService,
PaymentProviderService,
ProductVariantInventoryService,
RegionService,
ShippingOptionService,
ShippingProfileService,
TotalsService,
NewTotalsService,
TaxProviderService,
TotalsService,
} from "."
export const ORDER_CART_ALREADY_EXISTS_ERROR = "Order from cart already exists"
@@ -1102,6 +1102,7 @@ class OrderService extends TransactionBaseService {
return await this.atomicPhase_(async (manager) => {
const order = await this.retrieve(orderId, {
relations: [
"refunds",
"fulfillments",
"payments",
"returns",