feat(medusa-react): Add Collection batch (remove, add) endpoints (#1959)

This commit is contained in:
Richard Ward
2022-08-08 12:58:23 +02:00
committed by GitHub
parent a88bf3c76e
commit 2a723dcd4f
4 changed files with 143 additions and 0 deletions
@@ -2,6 +2,8 @@ import {
useAdminCreateCollection,
useAdminUpdateCollection,
useAdminDeleteCollection,
useAdminAddProductsToCollection,
useAdminRemoveProductsFromCollection,
} from "../../../../src/"
import { renderHook } from "@testing-library/react-hooks"
import { fixtures } from "../../../../mocks/data"
@@ -80,3 +82,57 @@ describe("useAdminDeleteCollection hook", () => {
)
})
})
describe("useAdminAddProductsToCollection hook", () => {
test("add products to a collection", async () => {
const update = {
product_ids: [fixtures.get("product").id],
}
const { result, waitFor } = renderHook(
() => useAdminAddProductsToCollection(fixtures.get("product_collection").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(update)
await waitFor(() => result.current.isSuccess)
expect(result.current.data?.response.status).toEqual(200)
expect(result.current.data?.collection).toEqual(
expect.objectContaining({
...fixtures.get("product_collection"),
products: [fixtures.get("product")],
})
)
})
})
describe("useAdminRemoveProductsFromCollection hook", () => {
test("remove products from a collection", async () => {
const remove = {
product_ids: [fixtures.get("product").id],
}
const { result, waitFor } = renderHook(
() => useAdminRemoveProductsFromCollection(fixtures.get("product_collection").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(remove)
await waitFor(() => result.current.isSuccess)
expect(result.current.data?.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
id: fixtures.get("product_collection").id,
object: "product-collection",
removed_products: remove.product_ids
})
)
})
})