fix: Add free text search on reservations (#9621)
This commit is contained in:
1 parent
df78f6e871
commit
0be50059f2
3 files changed
+89
-1
No files matched your search
@@ -4,7 +4,7 @@ import {
|
|||||||
createAdminUser,
|
createAdminUser,
|
||||||
} from "../../../../helpers/create-admin-user"
|
} from "../../../../helpers/create-admin-user"
|
||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(50000)
|
||||||
|
|
||||||
medusaIntegrationTestRunner({
|
medusaIntegrationTestRunner({
|
||||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
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 () => {
|
it("lists reservations with inventory_items", async () => {
|
||||||
const res = await api.get(
|
const res = await api.get(
|
||||||
`/admin/reservations?fields=%2binventory_item.*`,
|
`/admin/reservations?fields=%2binventory_item.*`,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export const AdminGetReservationsParams = createFindParams({
|
|||||||
offset: 0,
|
offset: 0,
|
||||||
}).merge(
|
}).merge(
|
||||||
z.object({
|
z.object({
|
||||||
|
q: z.string().optional(),
|
||||||
location_id: z.union([z.string(), z.array(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(),
|
inventory_item_id: z.union([z.string(), z.array(z.string())]).optional(),
|
||||||
line_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,
|
BigNumber,
|
||||||
DALUtils,
|
DALUtils,
|
||||||
MikroOrmBigNumberProperty,
|
MikroOrmBigNumberProperty,
|
||||||
|
Searchable,
|
||||||
createPsqlIndexStatementHelper,
|
createPsqlIndexStatementHelper,
|
||||||
generateEntityId,
|
generateEntityId,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
@@ -87,6 +88,7 @@ export class ReservationItem {
|
|||||||
@Property({ type: "text", nullable: true })
|
@Property({ type: "text", nullable: true })
|
||||||
external_id: string | null = null
|
external_id: string | null = null
|
||||||
|
|
||||||
|
@Searchable()
|
||||||
@Property({ type: "text", nullable: true })
|
@Property({ type: "text", nullable: true })
|
||||||
description: string | null = null
|
description: string | null = null
|
||||||
|
|
||||||
@@ -105,6 +107,7 @@ export class ReservationItem {
|
|||||||
})
|
})
|
||||||
inventory_item_id: string
|
inventory_item_id: string
|
||||||
|
|
||||||
|
@Searchable()
|
||||||
@ManyToOne(() => InventoryItem, {
|
@ManyToOne(() => InventoryItem, {
|
||||||
persist: false,
|
persist: false,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user