fix: Add free text search on reservations (#9621)
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
||||
createAdminUser,
|
||||
} from "../../../../helpers/create-admin-user"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
jest.setTimeout(50000)
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
@@ -329,6 +329,90 @@ medusaIntegrationTestRunner({
|
||||
)
|
||||
})
|
||||
|
||||
it("lists reservation items with free text search on SKU on inventory item", async () => {
|
||||
const reservationsRes = await api
|
||||
.get(`/admin/reservations?q=second`, adminHeaders)
|
||||
.catch(console.warn)
|
||||
|
||||
expect(reservationsRes.data.reservations.length).toBe(1)
|
||||
expect(reservationsRes.data.reservations).toEqual([
|
||||
{
|
||||
id: reservation2.id,
|
||||
created_at: expect.any(String),
|
||||
description: "test description",
|
||||
inventory_item: {
|
||||
created_at: expect.any(String),
|
||||
description: null,
|
||||
height: null,
|
||||
hs_code: "hs001",
|
||||
id: inventoryItem2.id,
|
||||
length: null,
|
||||
material: null,
|
||||
metadata: null,
|
||||
mid_code: null,
|
||||
origin_country: "UK",
|
||||
requires_shipping: true,
|
||||
reserved_quantity: 1,
|
||||
sku: "second",
|
||||
stocked_quantity: 100,
|
||||
thumbnail: null,
|
||||
title: null,
|
||||
updated_at: expect.any(String),
|
||||
weight: null,
|
||||
width: null,
|
||||
},
|
||||
inventory_item_id: inventoryItem2.id,
|
||||
line_item_id: "line-item-id-2",
|
||||
location_id: stockLocation1.id,
|
||||
metadata: null,
|
||||
quantity: 1,
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("lists reservation items with free text search on descroption", async () => {
|
||||
const reservationsRes = await api
|
||||
.get(`/admin/reservations?q=test`, adminHeaders)
|
||||
.catch(console.warn)
|
||||
|
||||
expect(reservationsRes.data.reservations.length).toBe(1)
|
||||
expect(reservationsRes.data.reservations).toEqual([
|
||||
{
|
||||
id: reservation2.id,
|
||||
created_at: expect.any(String),
|
||||
description: "test description",
|
||||
inventory_item: {
|
||||
created_at: expect.any(String),
|
||||
description: null,
|
||||
height: null,
|
||||
hs_code: "hs001",
|
||||
id: inventoryItem2.id,
|
||||
length: null,
|
||||
material: null,
|
||||
metadata: null,
|
||||
mid_code: null,
|
||||
origin_country: "UK",
|
||||
requires_shipping: true,
|
||||
reserved_quantity: 1,
|
||||
sku: "second",
|
||||
stocked_quantity: 100,
|
||||
thumbnail: null,
|
||||
title: null,
|
||||
updated_at: expect.any(String),
|
||||
weight: null,
|
||||
width: null,
|
||||
},
|
||||
inventory_item_id: inventoryItem2.id,
|
||||
line_item_id: "line-item-id-2",
|
||||
location_id: stockLocation1.id,
|
||||
metadata: null,
|
||||
quantity: 1,
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("lists reservations with inventory_items", async () => {
|
||||
const res = await api.get(
|
||||
`/admin/reservations?fields=%2binventory_item.*`,
|
||||
|
||||
@@ -18,6 +18,7 @@ export const AdminGetReservationsParams = createFindParams({
|
||||
offset: 0,
|
||||
}).merge(
|
||||
z.object({
|
||||
q: z.string().optional(),
|
||||
location_id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
inventory_item_id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
line_item_id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
BigNumber,
|
||||
DALUtils,
|
||||
MikroOrmBigNumberProperty,
|
||||
Searchable,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/framework/utils"
|
||||
@@ -87,6 +88,7 @@ export class ReservationItem {
|
||||
@Property({ type: "text", nullable: true })
|
||||
external_id: string | null = null
|
||||
|
||||
@Searchable()
|
||||
@Property({ type: "text", nullable: true })
|
||||
description: string | null = null
|
||||
|
||||
@@ -105,6 +107,7 @@ export class ReservationItem {
|
||||
})
|
||||
inventory_item_id: string
|
||||
|
||||
@Searchable()
|
||||
@ManyToOne(() => InventoryItem, {
|
||||
persist: false,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user