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:
co-authored by
Oliver Windall Juhl
parent
47d075351f
commit
1817b810fc
@@ -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", () => {
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user