feat(medusa): Nested Categories Admin List Endpoint (#2973)
* chore: added get route for admin categories API * chore: add tree method to mock repository * chore: added changeset to the PR * chore: rename id to productCategoryId in service * chore: switch cli option to string * chore: lint fixes, tests for parent category * chore: move Nested Categories behind feature flag * chore: use transformQuery hook in api * chore: add feature flag in migrations * chore: remove migration FF, fix FF name * chore: add free text search + count repo function * chore: added list endpoint for admin * chore: added changeset for feature * chore: address pr review comments * chore: change oas comment * chore: add nullable parent category filter + test
This commit is contained in:
@@ -111,4 +111,126 @@ describe("/admin/product-categories", () => {
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
})
|
||||
|
||||
describe("GET /admin/product-categories", () => {
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
productCategoryParent = await simpleProductCategoryFactory(dbConnection, {
|
||||
name: "Mens",
|
||||
handle: "mens",
|
||||
})
|
||||
|
||||
productCategory = await simpleProductCategoryFactory(dbConnection, {
|
||||
name: "sweater",
|
||||
handle: "sweater",
|
||||
parent_category: productCategoryParent,
|
||||
is_internal: true,
|
||||
})
|
||||
|
||||
productCategoryChild = await simpleProductCategoryFactory(dbConnection, {
|
||||
name: "cashmere",
|
||||
handle: "cashmere",
|
||||
parent_category: productCategory,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
return await db.teardown()
|
||||
})
|
||||
|
||||
it("gets list of product category with immediate children and parents", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/product-categories`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(3)
|
||||
expect(response.data.offset).toEqual(0)
|
||||
expect(response.data.limit).toEqual(100)
|
||||
expect(response.data.product_categories).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: productCategoryParent.id,
|
||||
parent_category: null,
|
||||
category_children: [
|
||||
expect.objectContaining({
|
||||
id: productCategory.id,
|
||||
})
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: productCategory.id,
|
||||
parent_category: expect.objectContaining({
|
||||
id: productCategoryParent.id,
|
||||
}),
|
||||
category_children: [
|
||||
expect.objectContaining({
|
||||
id: productCategoryChild.id,
|
||||
})
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: productCategoryChild.id,
|
||||
parent_category: expect.objectContaining({
|
||||
id: productCategory.id,
|
||||
}),
|
||||
category_children: [],
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("filters based on whitelisted attributes of the data model", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/product-categories?is_internal=true`,
|
||||
adminHeaders,
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.product_categories[0].id).toEqual(productCategory.id)
|
||||
})
|
||||
|
||||
it("filters based on free text on name and handle columns", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/product-categories?q=men`,
|
||||
adminHeaders,
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.product_categories[0].id).toEqual(productCategoryParent.id)
|
||||
})
|
||||
|
||||
it("filters based on parent category", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
`/admin/product-categories?parent_category_id=${productCategoryParent.id}`,
|
||||
adminHeaders,
|
||||
).catch(e => e)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.product_categories[0].id).toEqual(productCategory.id)
|
||||
|
||||
const nullCategoryResponse = await api.get(
|
||||
`/admin/product-categories?parent_category_id=null`,
|
||||
adminHeaders,
|
||||
).catch(e => e)
|
||||
|
||||
expect(nullCategoryResponse.status).toEqual(200)
|
||||
expect(nullCategoryResponse.data.count).toEqual(1)
|
||||
expect(nullCategoryResponse.data.product_categories[0].id).toEqual(productCategoryParent.id)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user