Feat/decline order edit (#2234)
**What** - Decline an order edit from a store endpoint - Refactor totals setting to a service method Fixes CORE-502
This commit is contained in:
@@ -69,6 +69,15 @@ export const storeHandlers = [
|
||||
)
|
||||
}),
|
||||
|
||||
rest.post("/store/order-edits/:id/decline", (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
order_edit: {...fixtures.get("order_edit"), declined_reason: req.body.declined_reason, status: 'declined'},
|
||||
})
|
||||
)
|
||||
}),
|
||||
|
||||
rest.get("/store/orders/:id", (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from "./queries"
|
||||
export * from './mutations'
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
|
||||
import {
|
||||
StorePostOrderEditsOrderEditDecline,
|
||||
StoreOrderEditsRes
|
||||
} from "@medusajs/medusa"
|
||||
|
||||
import { buildOptions } from "../../utils/buildOptions"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { orderEditQueryKeys } from "."
|
||||
|
||||
export const useDeclineOrderEdit = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<StoreOrderEditsRes>,
|
||||
Error,
|
||||
StorePostOrderEditsOrderEditDecline
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
(payload: StorePostOrderEditsOrderEditDecline) =>
|
||||
client.orderEdits.decline(id, payload),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[orderEditQueryKeys.lists(), orderEditQueryKeys.detail(id)],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { useDeclineOrderEdit } from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useCreateLineItem hook", () => {
|
||||
test("creates a line item", async () => {
|
||||
const declineBody = {
|
||||
declined_reason: "Wrong color",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useDeclineOrderEdit("test-cart"),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(declineBody)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order_edit).toEqual(
|
||||
expect.objectContaining({
|
||||
status: "declined",
|
||||
...declineBody,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user