feat: Add support for search to all endpoints (#7149)

* feat: Add search capability to api keys

* feat: Add support for searching to currency and customer endpoints

* fix: Clean up product search filters

* feat: Add search support to regions

* feat: Add search support to sales channels

* feat: Add search support to store module

* feat: Add search support to user module

* fix: Clean up inventory search

* feat: Add search support for payments

* fix: Add searchable attributes to stock location models

* feat: Add search support to tax

* feat: Add search support to promotions

* feat: Add search support for pricing, filtering cleanup

* fix: Further cleanups around search
This commit is contained in:
Stevche Radevski
2024-04-25 17:36:59 +02:00
committed by GitHub
parent d02905cefa
commit f03a822253
52 changed files with 640 additions and 64 deletions

View File

@@ -85,6 +85,43 @@ medusaIntegrationTestRunner({
expect(listedApiKeys.data.api_keys).toHaveLength(0)
})
it("should allow searching for api keys", async () => {
await api.post(
`/admin/api-keys`,
{
title: "Test Secret Key",
type: ApiKeyType.SECRET,
},
adminHeaders
)
await api.post(
`/admin/api-keys`,
{
title: "Test Publishable Key",
type: ApiKeyType.PUBLISHABLE,
},
adminHeaders
)
const listedSecretKeys = await api.get(
`/admin/api-keys?q=Secret`,
adminHeaders
)
const listedPublishableKeys = await api.get(
`/admin/api-keys?q=Publish`,
adminHeaders
)
expect(listedSecretKeys.data.api_keys).toHaveLength(1)
expect(listedSecretKeys.data.api_keys[0].title).toEqual(
"Test Secret Key"
)
expect(listedPublishableKeys.data.api_keys).toHaveLength(1)
expect(listedPublishableKeys.data.api_keys[0].title).toEqual(
"Test Publishable Key"
)
})
it("can use a secret api key for authentication", async () => {
const created = await api.post(
`/admin/api-keys`,

View File

@@ -1948,6 +1948,46 @@ medusaIntegrationTestRunner({
])
)
})
it("should allow searching of variants", async () => {
await breaking(
() => {},
async () => {
const newProduct = (
await api.post(
"/admin/products",
getProductFixture({
variants: [
{ title: "First variant", prices: [] },
{ title: "Second variant", prices: [] },
],
}),
adminHeaders
)
).data.product
const res = await api
.get(
`/admin/products/${newProduct.id}/variants?q=first`,
adminHeaders
)
.catch((err) => {
console.log(err)
})
expect(res.status).toEqual(200)
expect(res.data.variants).toHaveLength(1)
expect(res.data.variants).toEqual(
expect.arrayContaining([
expect.objectContaining({
title: "First variant",
product_id: newProduct.id,
}),
])
)
}
)
})
})
describe("updates a variant's default prices (ignores prices associated with a Price List)", () => {

View File

@@ -157,40 +157,30 @@ medusaIntegrationTestRunner({
})
it("should list the sales channel using filters", async () => {
const response = await breaking(
async () => {
return await api.get(`/admin/sales-channels?q=2`, adminReqConfig)
},
() => undefined
const response = await api.get(
`/admin/sales-channels?q=2`,
adminReqConfig
)
breaking(
() => {
expect(response.status).toEqual(200)
expect(response.data.sales_channels).toBeTruthy()
expect(response.data.sales_channels.length).toBe(1)
expect(response.data).toEqual({
count: 1,
limit: 20,
offset: 0,
sales_channels: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
name: salesChannel2.name,
description: salesChannel2.description,
is_disabled: false,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
})
},
() => {
// TODO: Free text search is not supported in the new sales channel API (yet)
expect(response).toBeUndefined()
}
)
expect(response.status).toEqual(200)
expect(response.data.sales_channels).toBeTruthy()
expect(response.data.sales_channels.length).toBe(1)
expect(response.data).toEqual({
count: 1,
limit: 20,
offset: 0,
sales_channels: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
name: salesChannel2.name,
description: salesChannel2.description,
is_disabled: false,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
})
})
it("should list the sales channel using properties filters", async () => {
@@ -219,6 +209,37 @@ medusaIntegrationTestRunner({
]),
})
})
it("should support searching of sales channels", async () => {
await breaking(
() => {},
async () => {
await api.post(
"/admin/sales-channels",
{ name: "first channel", description: "to fetch" },
adminReqConfig
)
await api.post(
"/admin/sales-channels",
{ name: "second channel", description: "not in response" },
adminReqConfig
)
const response = await api.get(
`/admin/sales-channels?q=fetch`,
adminReqConfig
)
expect(response.status).toEqual(200)
expect(response.data.sales_channels).toEqual([
expect.objectContaining({
name: "first channel",
}),
])
}
)
})
})
describe("POST /admin/sales-channels/:id", () => {

View File

@@ -50,7 +50,11 @@ medusaIntegrationTestRunner({
() =>
api
.get("/admin/stores", adminHeaders)
.then((r) => r.data.stores[0])
.then((r) =>
r.data.stores.find(
(s) => s.default_sales_channel_id === "sc_12345"
)
)
)
expect(store).toEqual(
@@ -245,6 +249,35 @@ medusaIntegrationTestRunner({
)
})
})
describe("GET /admin/store", () => {
it("supports searching of stores", async () => {
await breaking(
() => {},
async () => {
const service = container.resolve(ModuleRegistrationName.STORE)
const secondStore = await service.create({
name: "Second Store",
supported_currency_codes: ["eur"],
default_currency_code: "eur",
})
const response = await api.get(
"/admin/stores?q=second",
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.stores).toEqual([
expect.objectContaining({
id: secondStore.id,
name: "Second Store",
}),
])
}
)
})
})
})
},
})

View File

@@ -143,7 +143,6 @@ medusaIntegrationTestRunner({
)
})
// TODO: Free text search not supported in 2.0 yet
it("should list users that match the free text search", async () => {
const response = await api.get("/admin/users?q=member", adminHeaders)
@@ -159,7 +158,10 @@ medusaIntegrationTestRunner({
last_name: "user",
created_at: expect.any(String),
updated_at: expect.any(String),
role: "member",
...breaking(
() => ({ role: "member" }),
() => ({})
),
}),
])
)