* add: medusa admin hooks + tests * fix: remove unneeded props * fix: deps * fix: deps * fix: deps * fix: failing tests * fix: failing tests * fix: query key * add: yarn workspaces * fix: linting medusa-react * fix: add prepare script * fix: buildOptions * fix: useAdminShippingOptions query * fix: use qs instead for query params (#1019) * fix: formatting * debug: ci pipeline * debug: log node_modules structure * debug: use lerna bootstrap * debug: update node version * debug: print pkgs in workspace * debug: print pkgs in workspace * debug: print pkgs in workspace * debug: print pkgs in workspace * debug: add explicit build step * fix: jsdoc * debug: run build step * debug: fix build errors * debug: add build step to integration tests * fix: failing test * cleanup Co-authored-by: Sebastian Rindom <seb@medusajs.com> Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
130 lines
3.1 KiB
TypeScript
130 lines
3.1 KiB
TypeScript
import {
|
|
useAdminCreateUser,
|
|
useAdminUpdateUser,
|
|
useAdminDeleteUser,
|
|
useAdminResetPassword,
|
|
useAdminSendResetPasswordToken,
|
|
} from "../../../../src/"
|
|
import { renderHook } from "@testing-library/react-hooks"
|
|
import { fixtures } from "../../../../mocks/data"
|
|
import { createWrapper } from "../../../utils"
|
|
|
|
describe("useAdminCreateUser hook", () => {
|
|
test("creates a user and returns it", async () => {
|
|
const user = {
|
|
email: "lebron@james.com",
|
|
first_name: "Lebron",
|
|
last_name: "James",
|
|
role: "admin" as const,
|
|
password: "test-password",
|
|
}
|
|
|
|
const { result, waitFor } = renderHook(() => useAdminCreateUser(), {
|
|
wrapper: createWrapper(),
|
|
})
|
|
|
|
result.current.mutate(user)
|
|
|
|
await waitFor(() => result.current.isSuccess)
|
|
|
|
expect(result.current.data.response.status).toEqual(200)
|
|
expect(result.current.data.user).toEqual(
|
|
expect.objectContaining({
|
|
...fixtures.get("user"),
|
|
...user,
|
|
})
|
|
)
|
|
})
|
|
})
|
|
|
|
describe("useAdminUpdateUser hook", () => {
|
|
test("updates a user and returns it", async () => {
|
|
const id = fixtures.get("user").id
|
|
const user = {
|
|
first_name: "Zack",
|
|
last_name: "Medusa",
|
|
}
|
|
|
|
const { result, waitFor } = renderHook(() => useAdminUpdateUser(id), {
|
|
wrapper: createWrapper(),
|
|
})
|
|
|
|
result.current.mutate(user)
|
|
|
|
await waitFor(() => result.current.isSuccess)
|
|
|
|
expect(result.current.data.response.status).toEqual(200)
|
|
expect(result.current.data.user).toEqual(
|
|
expect.objectContaining({
|
|
...fixtures.get("user"),
|
|
...user,
|
|
})
|
|
)
|
|
})
|
|
})
|
|
|
|
describe("useAdminDeleteUser hook", () => {
|
|
test("deletes a user", async () => {
|
|
const id = fixtures.get("user").id
|
|
|
|
const { result, waitFor } = renderHook(() => useAdminDeleteUser(id), {
|
|
wrapper: createWrapper(),
|
|
})
|
|
|
|
result.current.mutate()
|
|
|
|
await waitFor(() => result.current.isSuccess)
|
|
|
|
expect(result.current.data.response.status).toEqual(200)
|
|
expect(result.current.data).toEqual(
|
|
expect.objectContaining({
|
|
id,
|
|
deleted: true,
|
|
})
|
|
)
|
|
})
|
|
})
|
|
|
|
describe("useAdminSendResetPasswordToken hook", () => {
|
|
test("sends a token to reset the password", async () => {
|
|
const payload = {
|
|
email: "admin@user.com",
|
|
}
|
|
|
|
const { result, waitFor } = renderHook(
|
|
() => useAdminSendResetPasswordToken(),
|
|
{
|
|
wrapper: createWrapper(),
|
|
}
|
|
)
|
|
|
|
result.current.mutate(payload)
|
|
|
|
await waitFor(() => result.current.isSuccess)
|
|
|
|
expect(result.current.data.response.status).toEqual(200)
|
|
})
|
|
})
|
|
|
|
describe("useAdminResetPassword hook", () => {
|
|
test("reset the password", async () => {
|
|
const payload = {
|
|
token: "test-token",
|
|
password: "new-password",
|
|
}
|
|
|
|
const { result, waitFor } = renderHook(() => useAdminResetPassword(), {
|
|
wrapper: createWrapper(),
|
|
})
|
|
|
|
result.current.mutate(payload)
|
|
|
|
await waitFor(() => result.current.isSuccess)
|
|
|
|
expect(result.current.data.response.status).toEqual(200)
|
|
expect(result.current.data.user).toEqual(
|
|
expect.objectContaining(fixtures.get("user"))
|
|
)
|
|
})
|
|
})
|