feat: customer groups react hooks (#1153)

* fix: msw handlers for medusa-react storybook

* feat: add customer groups query hooks

* feat: add create/update customer groups hooks

* feat: add customer group batch  hooks

* feat: add test files, fix import

* add customer groups fixture

* add customer gorup mock endpoints

* add test cases

* add hook comments

* fix: typos

* fix: comments refactor

* fix: comment

Co-authored-by: fPolic <frane@medusajs.com>
This commit is contained in:
Frane Polić
2022-03-07 12:52:48 +01:00
committed by GitHub
co-authored by fPolic
parent a6f352d9f1
commit daf49bcaf3
11 changed files with 335 additions and 8 deletions
@@ -0,0 +1,59 @@
import { renderHook } from "@testing-library/react-hooks"
import {
useAdminCreateCustomerGroup,
useAdminUpdateCustomerGroup,
} from "../../../../src/"
import { fixtures } from "../../../../mocks/data"
import { createWrapper } from "../../../utils"
describe("useAdminCreateCustomerGroup hook", () => {
test("creates a customer group and returns it", async () => {
const group = {
name: "Group 1",
}
const { result, waitFor } = renderHook(
() => useAdminCreateCustomerGroup(),
{
wrapper: createWrapper(),
}
)
result.current.mutate(group)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.customer_group).toEqual(
expect.objectContaining(group)
)
})
describe("useAdminUpdateCustomerGroup hook", () => {
test("updates a customer group and returns it", async () => {
const group = {
name: "Changeed name",
}
const { result, waitFor } = renderHook(
() => useAdminUpdateCustomerGroup(fixtures.get("customer_group").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(group)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.customer_group).toEqual(
expect.objectContaining({
...fixtures.get("customer_group"),
...group,
})
)
})
})
})
@@ -0,0 +1,34 @@
import { renderHook } from "@testing-library/react-hooks"
import { useAdminCustomerGroup, useAdminCustomerGroups } from "../../../../src"
import { fixtures } from "../../../../mocks/data"
import { createWrapper } from "../../../utils"
describe("useAdminCustomerGroup hook", () => {
test("returns a customer group", async () => {
const group = fixtures.get("customer_group")
const { result, waitFor } = renderHook(
() => useAdminCustomerGroup(group.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.customer_group).toEqual(group)
})
test("returns a list of customer groups", async () => {
const groups = fixtures.list("customer_group")
const { result, waitFor } = renderHook(() => useAdminCustomerGroups(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.customer_groups).toEqual(groups)
})
})