feat(medusa): Nested Categories Admin Update Endpoint (#2986)
What: Introduces an admin endpoint that allows a user to update a product category Why: This is part of a greater goal of allowing products to be added to multiple categories. How: - Creates a route on the admin scope to update category - Creates a method in product category services to update a category RESOLVES CORE-956
This commit is contained in:
@@ -18,6 +18,7 @@ describe("/admin/product-categories", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
let productCategory = null
|
||||
let productCategory2 = null
|
||||
let productCategoryChild = null
|
||||
let productCategoryParent = null
|
||||
let productCategoryChild2 = null
|
||||
@@ -370,4 +371,95 @@ describe("/admin/product-categories", () => {
|
||||
expect(errorFetchingDeleted.response.status).toEqual(404)
|
||||
})
|
||||
})
|
||||
|
||||
describe("POST /admin/product-categories/:id", () => {
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
productCategory = await simpleProductCategoryFactory(dbConnection, {
|
||||
name: "skinny jeans",
|
||||
handle: "skinny-jeans",
|
||||
})
|
||||
|
||||
productCategory2 = await simpleProductCategoryFactory(dbConnection, {
|
||||
name: "sweater",
|
||||
handle: "sweater",
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
return await db.teardown()
|
||||
})
|
||||
|
||||
it("throws an error if invalid ID is sent", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const error = await api.post(
|
||||
`/admin/product-categories/not-found-id`,
|
||||
{
|
||||
name: 'testing'
|
||||
},
|
||||
adminHeaders
|
||||
).catch(e => e)
|
||||
|
||||
expect(error.response.status).toEqual(404)
|
||||
expect(error.response.data.type).toEqual("not_found")
|
||||
expect(error.response.data.message).toEqual(
|
||||
"ProductCategory with id: not-found-id was not found"
|
||||
)
|
||||
})
|
||||
|
||||
it("throws an error if invalid attribute is sent", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const error = await api.post(
|
||||
`/admin/product-categories/${productCategory.id}`,
|
||||
{
|
||||
invalid_property: 'string'
|
||||
},
|
||||
adminHeaders
|
||||
).catch(e => e)
|
||||
|
||||
expect(error.response.status).toEqual(400)
|
||||
expect(error.response.data.type).toEqual("invalid_data")
|
||||
expect(error.response.data.message).toEqual(
|
||||
"property invalid_property should not exist"
|
||||
)
|
||||
})
|
||||
|
||||
it("successfully updates a product category", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.post(
|
||||
`/admin/product-categories/${productCategory.id}`,
|
||||
{
|
||||
name: "test",
|
||||
handle: "test",
|
||||
is_internal: true,
|
||||
is_active: true,
|
||||
parent_category_id: productCategory2.id,
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
product_category: expect.objectContaining({
|
||||
name: "test",
|
||||
handle: "test",
|
||||
is_internal: true,
|
||||
is_active: true,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
parent_category: expect.objectContaining({
|
||||
id: productCategory2.id,
|
||||
}),
|
||||
category_children: []
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user