Skip to content

Commit fea64dd

Browse files
authored
Fix query filter (#14836)
1 parent e796bab commit fea64dd

File tree

3 files changed

+86
-4
lines changed

3 files changed

+86
-4
lines changed

.changeset/modern-tires-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/core-flows": patch
3+
---
4+
5+
fix(core-flows): ensure reason ids is an array in `validateReturnReasons` util

integration-tests/http/__tests__/returns/returns.spec.ts

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,36 @@ import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
22
import {
33
ContainerRegistrationKeys,
44
Modules,
5+
ReturnStatus,
56
RuleOperator,
67
} from "@medusajs/utils"
78
import {
89
adminHeaders,
910
createAdminUser,
11+
generatePublishableKey,
12+
generateStoreHeaders,
1013
} from "../../../helpers/create-admin-user"
1114

1215
jest.setTimeout(60000)
1316

1417
medusaIntegrationTestRunner({
1518
testSuite: ({ dbConnection, getContainer, api }) => {
16-
let order, order2
19+
let order, order2, storeOrder
1720
let returnShippingOption
1821
let shippingProfile
1922
let fulfillmentSet
20-
let returnReason
23+
let returnReason, returnReasonTwo
2124
let inventoryItem
2225
let location
26+
let storeHeaders
2327

2428
beforeEach(async () => {
2529
const container = getContainer()
2630
await createAdminUser(dbConnection, adminHeaders, container)
2731

32+
const publishableKey = await generatePublishableKey(container)
33+
storeHeaders = generateStoreHeaders({ publishableKey })
34+
2835
shippingProfile = (
2936
await api.post(
3037
`/admin/shipping-profiles`,
@@ -73,6 +80,18 @@ medusaIntegrationTestRunner({
7380
)
7481
).data.return_reason
7582

83+
returnReasonTwo = (
84+
await api.post(
85+
"/admin/return-reasons",
86+
{
87+
value: "return-reason-test-two",
88+
label: "Test return reason two",
89+
description: "This is the reason description!!!",
90+
},
91+
adminHeaders
92+
)
93+
).data.return_reason
94+
7695
const orderModule = container.resolve(Modules.ORDER)
7796

7897
order = await orderModule.createOrders({
@@ -313,7 +332,7 @@ medusaIntegrationTestRunner({
313332
)
314333
})
315334

316-
describe("Returns lifecycle", () => {
335+
describe("Admin Returns lifecycle", () => {
317336
it("Full flow with 2 orders", async () => {
318337
let result = await api.post(
319338
"/admin/returns",
@@ -1346,5 +1365,63 @@ medusaIntegrationTestRunner({
13461365
})
13471366
})
13481367
})
1368+
1369+
describe("Store Returns lifecycle", () => {
1370+
it("should request a return", async () => {
1371+
const createdReturn = (
1372+
await api.post(
1373+
"/store/returns",
1374+
{
1375+
order_id: order.id,
1376+
items: [
1377+
{
1378+
id: order.items[0].id,
1379+
quantity: 1,
1380+
reason_id: returnReason.id,
1381+
},
1382+
{
1383+
id: order.items[0].id,
1384+
quantity: 1,
1385+
reason_id: returnReasonTwo.id,
1386+
},
1387+
],
1388+
return_shipping: {
1389+
option_id: returnShippingOption.id,
1390+
},
1391+
},
1392+
storeHeaders
1393+
)
1394+
).data.return
1395+
1396+
expect(createdReturn).toEqual(
1397+
expect.objectContaining({
1398+
id: expect.any(String),
1399+
order_id: order.id,
1400+
status: ReturnStatus.REQUESTED,
1401+
items: expect.arrayContaining([
1402+
expect.objectContaining({
1403+
id: expect.any(String),
1404+
item_id: order.items[0].id,
1405+
quantity: 1,
1406+
reason_id: returnReason.id,
1407+
}),
1408+
expect.objectContaining({
1409+
id: expect.any(String),
1410+
item_id: order.items[0].id,
1411+
quantity: 1,
1412+
reason_id: returnReasonTwo.id,
1413+
}),
1414+
]),
1415+
shipping_methods: expect.arrayContaining([
1416+
expect.objectContaining({
1417+
id: expect.any(String),
1418+
shipping_option_id: returnShippingOption.id,
1419+
name: returnShippingOption.name,
1420+
}),
1421+
]),
1422+
})
1423+
)
1424+
})
1425+
})
13491426
},
13501427
})

packages/core/core-flows/src/order/utils/validate-return-reason.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function validateReturnReasons(
3030
"parent_return_reason",
3131
"return_reason_children.id",
3232
],
33-
variables: { id: [inputItems.map((item) => item.reason_id)], limit: null },
33+
variables: { id: inputItems.map((item) => item.reason_id), limit: null },
3434
})
3535

3636
const returnReasons = await remoteQuery(remoteQueryObject)

0 commit comments

Comments
 (0)