* feat: add `listCustomers` (by group) to `medusa-js` * feat: add `useAdminCustomerGroupCustomers` hook * fix: remove log * fix: import/export * fix: change query keys * wip: sublist query keys * fix: revert query factory changes * fix: add query as a param when building the "detail" key * fix: revert keys logic, use special case * fix: query path, change batch keys * change admin customer groups cache key generation * spread query params Co-authored-by: fPolic <frane@medusajs.com>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
import { renderHook } from "@testing-library/react-hooks"
|
|
|
|
import {
|
|
useAdminCustomerGroup,
|
|
useAdminCustomerGroupCustomers,
|
|
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)
|
|
})
|
|
|
|
test("returns a list of customers that belong to a group", async () => {
|
|
const groups = fixtures.list("customer_group")
|
|
const customers = fixtures.list("customer")
|
|
|
|
const { result, waitFor } = renderHook(
|
|
() => useAdminCustomerGroupCustomers(groups[0].id),
|
|
{
|
|
wrapper: createWrapper(),
|
|
}
|
|
)
|
|
|
|
await waitFor(() => result.current.isSuccess)
|
|
|
|
expect(result.current.response.status).toEqual(200)
|
|
expect(result.current.customers).toEqual(customers)
|
|
})
|
|
})
|