fix(medusa): Deleted discount missing on order (#6837)

* Fix deleted discount missing on order

* Added integration test

* Added changeset
This commit is contained in:
pepijn-vanvlaanderen
2024-03-29 11:51:27 +01:00
committed by GitHub
parent 86f499de2f
commit 6113af0a66
3 changed files with 39 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
Fix deleted discount missing on order
@@ -2649,6 +2649,34 @@ describe("/admin/orders", () => {
})
)
})
it("retrieves an order should include a deleted discount", async () => {
const api = useApi()
await dbConnection.manager.query(
`UPDATE discount
set deleted_at = NOW()
WHERE id = 'test-discount';`
)
const order = await api.get(
`/admin/orders/${testOrderId}`,
adminReqConfig
)
expect(order.status).toEqual(200)
expect(order.data.order).toEqual(
expect.objectContaining({
id: "test-order",
discounts: expect.arrayContaining([
expect.objectContaining({
id: "test-discount",
deleted_at: expect.any(String),
}),
]),
})
)
})
})
describe("POST /orders/:id/refund", () => {
+6 -2
View File
@@ -10,6 +10,7 @@ import {
const ITEMS_REL_NAME = "items"
const REGION_REL_NAME = "region"
const DISCOUNTS_REL_NAME = "discounts"
export const OrderRepository = dataSource.getRepository(Order).extend({
async findWithRelations(
@@ -28,8 +29,11 @@ export const OrderRepository = dataSource.getRepository(Order).extend({
where: { id: In(entitiesIds) },
select: ["id"],
relations: rels,
withDeleted:
topLevel === ITEMS_REL_NAME || topLevel === REGION_REL_NAME,
withDeleted: [
ITEMS_REL_NAME,
REGION_REL_NAME,
DISCOUNTS_REL_NAME,
].includes(topLevel),
relationLoadStrategy: "join",
})
})