feat: V2 batch update products in categories (#7125)

* wip

* wip

* fix: batch category update

* update tet

* fix type

---------

Co-authored-by: Stevche Radevski <sradevski@live.com>
This commit is contained in:
Oli Juhl
2024-04-23 17:17:25 +02:00
committed by GitHub
parent 2446151420
commit 10e120062b
13 changed files with 269 additions and 25 deletions

View File

@@ -1221,6 +1221,7 @@ medusaIntegrationTestRunner({
})
})
// TODO: Remove in V2, endpoint changed
describe("POST /admin/product-categories/:id/products/batch", () => {
beforeEach(async () => {
productCategory = await simpleProductCategoryFactory(dbConnection, {
@@ -1335,6 +1336,7 @@ medusaIntegrationTestRunner({
})
})
// TODO: Remove in v2, endpoint changed
describe("DELETE /admin/product-categories/:id/products/batch", () => {
let testProduct1, testProduct2
@@ -1455,5 +1457,56 @@ medusaIntegrationTestRunner({
})
})
})
// Skipping because the test is for V2 only
describe.skip("POST /admin/product-categories/:id/products", () => {
beforeEach(async () => {
productCategory = await productModuleService.createCategory({
name: "category parent",
description: "category parent",
parent_category_id: null,
})
})
it("successfully updates a product category", async () => {
const product1Response = await api.post(
"/admin/products",
{
title: "product 1",
categories: [{ id: productCategory.id }],
},
adminHeaders
)
const product2Response = await api.post(
"/admin/products",
{
title: "product 2",
},
adminHeaders
)
const categoryResponse = await api.post(
`/admin/product-categories/${productCategory.id}/products`,
{
remove: [product1Response.data.product.id],
add: [product2Response.data.product.id],
},
adminHeaders
)
const productsInCategoryResponse = await api.get(
`/admin/products?category_id[]=${productCategory.id}`,
adminHeaders
)
expect(categoryResponse.status).toEqual(200)
expect(productsInCategoryResponse.data.products).toEqual([
expect.objectContaining({
id: product2Response.data.product.id,
}),
])
})
})
},
})