feat(medusa): Claim customer orders (#2710)

This commit is contained in:
Philip Korsholm
2022-12-08 17:48:49 +01:00
committed by GitHub
parent 86f9455d00
commit a6243618fe
36 changed files with 872 additions and 107 deletions
@@ -121,6 +121,14 @@ export const storeHandlers = [
)
}),
rest.post("/store/orders/customer/confirm", (req, res, ctx) => {
return res(ctx.status(200))
}),
rest.post("/store/orders/batch/customer/token", (req, res, ctx) => {
return res(ctx.status(200))
}),
rest.get("/store/return-reasons/", (req, res, ctx) => {
return res(
ctx.status(200),
@@ -1 +1,2 @@
export * from "./queries"
export * from "./mutations"
@@ -0,0 +1,44 @@
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
import { Response } from "@medusajs/medusa-js"
import {
StorePostCustomersCustomerAcceptClaimReq,
StorePostCustomersCustomerOrderClaimReq,
} from "@medusajs/medusa"
import { buildOptions } from "../../utils/buildOptions"
import { useMedusa } from "../../../contexts"
import { orderKeys } from "."
export const useRequestOrderAccess = (
options?: UseMutationOptions<
Response<{}>,
Error,
StorePostCustomersCustomerOrderClaimReq
>
) => {
const { client } = useMedusa()
const queryClient = useQueryClient()
return useMutation(
(payload: StorePostCustomersCustomerOrderClaimReq) =>
client.orders.requestCustomerOrders(payload),
buildOptions(queryClient, [orderKeys.all], options)
)
}
export const useGrantOrderAccess = (
options?: UseMutationOptions<
Response<{}>,
Error,
StorePostCustomersCustomerAcceptClaimReq
>
) => {
const { client } = useMedusa()
const queryClient = useQueryClient()
return useMutation(
(payload: StorePostCustomersCustomerAcceptClaimReq) =>
client.orders.confirmRequest(payload),
buildOptions(queryClient, [orderKeys.all], options)
)
}
@@ -0,0 +1,31 @@
import { useRequestOrderAccess, useGrantOrderAccess } from "../../../../src/"
import { renderHook } from "@testing-library/react-hooks"
import { createWrapper } from "../../../utils"
describe("useGrantOrderAccess hook", () => {
test("Grant access to token", async () => {
const { result, waitFor } = renderHook(() => useGrantOrderAccess(), {
wrapper: createWrapper(),
})
result.current.mutate({ token: "store_order_edit" })
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
})
})
describe("useRequestOrderAccess hook", () => {
test("Requests access to ids", async () => {
const { result, waitFor } = renderHook(() => useRequestOrderAccess(), {
wrapper: createWrapper(),
})
result.current.mutate({ order_ids: [""] })
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
})
})