feat: customer group customers client endpoints (#1221)

* 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>
This commit is contained in:
Frane Polić
2022-03-23 20:07:13 +01:00
committed by GitHub
co-authored by fPolic
parent 932f4b29a8
commit b7f699654b
7 changed files with 102 additions and 10 deletions
@@ -1,6 +1,10 @@
import { renderHook } from "@testing-library/react-hooks"
import { useAdminCustomerGroup, useAdminCustomerGroups } from "../../../../src"
import {
useAdminCustomerGroup,
useAdminCustomerGroupCustomers,
useAdminCustomerGroups,
} from "../../../../src"
import { fixtures } from "../../../../mocks/data"
import { createWrapper } from "../../../utils"
@@ -31,4 +35,21 @@ describe("useAdminCustomerGroup hook", () => {
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)
})
})