feat(medusa): Update OrderEdit (#2220)
This commit is contained in:
@@ -1687,6 +1687,15 @@ export const adminHandlers = [
|
||||
)
|
||||
}),
|
||||
|
||||
rest.post("/admin/order-edits/:id", (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
order_edit: { ...fixtures.get("order_edit"), ...(req.body as any) },
|
||||
})
|
||||
)
|
||||
}),
|
||||
|
||||
rest.delete("/admin/order-edits/:id", (req, res, ctx) => {
|
||||
const { id } = req.params
|
||||
return res(
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
|
||||
import {
|
||||
AdminOrderEditDeleteRes,
|
||||
AdminPostOrderEditsOrderEditReq,
|
||||
AdminOrderEditsRes,
|
||||
AdminPostOrderEditsReq,
|
||||
} from "@medusajs/medusa"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||
import { adminOrderEditsKeys } from "."
|
||||
|
||||
import { buildOptions } from "../../utils/buildOptions"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { adminOrderEditsKeys } from "."
|
||||
|
||||
export const useAdminCreateOrderEdit = (
|
||||
options?: UseMutationOptions<
|
||||
@@ -41,3 +44,25 @@ export const useAdminDeleteOrderEdit = (
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
export const useAdminUpdateOrderEdit = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<AdminOrderEditsRes>,
|
||||
Error,
|
||||
AdminPostOrderEditsOrderEditReq
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
(payload: AdminPostOrderEditsOrderEditReq) =>
|
||||
client.admin.orderEdits.update(id, payload),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[adminOrderEditsKeys.lists(), adminOrderEditsKeys.detail(id)],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
|
||||
import {
|
||||
useAdminCreateOrderEdit,
|
||||
useAdminUpdateOrderEdit,
|
||||
useAdminDeleteOrderEdit,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminDelete hook", () => {
|
||||
test("Deletes an order edit", async () => {
|
||||
@@ -27,6 +30,33 @@ describe("useAdminDelete hook", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminUpdateOrderEdit hook", () => {
|
||||
test("updates an order edit and returns it", async () => {
|
||||
const orderEdit = {
|
||||
internal_note: "changed note",
|
||||
}
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminUpdateOrderEdit(fixtures.get("order_edit").id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate(orderEdit)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.order_edit).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("order_edit"),
|
||||
...orderEdit,
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateOrderEdit hook", () => {
|
||||
test("Created an order edit", async () => {
|
||||
const { result, waitFor } = renderHook(() => useAdminCreateOrderEdit(), {
|
||||
|
||||
Reference in New Issue
Block a user