fix(medusa): List products by type_id (#2427)
**What** - Fixes `GET /products` in both admin and store API so they no longer accept the param `type?: string`, but instead accept `type_id?: string[]` **Why** - Filtering by type would never return any products as `ptyp_:id` !== `ProductType`. **Testing** - Added an integration test for each endpoint. Closes CORE-695
This commit is contained in:
committed by
GitHub
parent
05f921711f
commit
211720f24c
@@ -168,6 +168,30 @@ describe("/admin/products", () => {
|
||||
}
|
||||
})
|
||||
|
||||
it("returns a list of products where type_id is test-type", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/products?type_id[]=test-type", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(5)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
type_id: "test-type",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("doesn't expand collection and types", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
@@ -195,6 +195,24 @@ describe("/store/products", () => {
|
||||
}
|
||||
})
|
||||
|
||||
it("works when filtering by type_id", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.get(
|
||||
`/store/products?type_id[]=test-type&fields=id,title,type_id`
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(5)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
type_id: "test-type",
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("returns only published products", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user