fix: Add free text search on reservations (#9621)

This commit is contained in:
Oli Juhl
2024-10-17 10:21:24 +02:00
committed by GitHub
parent df78f6e871
commit 0be50059f2
3 changed files with 89 additions and 1 deletions

View File

@@ -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.*`,

View File

@@ -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(),

View File

@@ -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,
})