feat(medusa, medusa-js, medusa-react): Implement store complete order… (#2275)
**What** Allow a customer to complete a requested order edit. **Test** - Unit tests complete flow - Unit tests medusa react - Integration tests of order edit completion FIXES CORE-501
This commit is contained in:
@@ -73,7 +73,23 @@ export const storeHandlers = [
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
order_edit: {...fixtures.get("order_edit"), declined_reason: req.body.declined_reason, status: 'declined'},
|
||||
order_edit: {
|
||||
...fixtures.get("store_order_edit"),
|
||||
declined_reason: (req.body as any).declined_reason,
|
||||
status: "declined",
|
||||
},
|
||||
})
|
||||
)
|
||||
}),
|
||||
|
||||
rest.post("/store/order-edits/:id/complete", (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
order_edit: {
|
||||
...fixtures.get("store_order_edit"),
|
||||
status: "confirmed",
|
||||
},
|
||||
})
|
||||
)
|
||||
}),
|
||||
|
||||
@@ -2,8 +2,8 @@ import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
|
||||
import {
|
||||
StoreOrderEditsRes,
|
||||
StorePostOrderEditsOrderEditDecline,
|
||||
StoreOrderEditsRes
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
import { buildOptions } from "../../utils/buildOptions"
|
||||
@@ -31,3 +31,20 @@ export const useDeclineOrderEdit = (
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export const useCompleteOrderEdit = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<Response<StoreOrderEditsRes>, Error>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
() => client.orderEdits.complete(id),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[orderEditQueryKeys.lists(), orderEditQueryKeys.detail(id)],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { useDeclineOrderEdit } from "../../../../src/"
|
||||
import { useCompleteOrderEdit, useDeclineOrderEdit } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useCreateLineItem hook", () => {
|
||||
test("creates a line item", async () => {
|
||||
describe("useDeclineOrderEdit hook", () => {
|
||||
test("decline an order edit", async () => {
|
||||
const declineBody = {
|
||||
declined_reason: "Wrong color",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useDeclineOrderEdit("test-cart"),
|
||||
() => useDeclineOrderEdit("store_order_edit"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
@@ -28,3 +28,25 @@ describe("useCreateLineItem hook", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useCompleteOrderEdit hook", () => {
|
||||
test("complete an order edit", async () => {
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useCompleteOrderEdit("store_order_edit"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order_edit).toEqual(
|
||||
expect.objectContaining({
|
||||
status: "confirmed",
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user