feat(medusa): Implement premises of order edit retrieval (#2183)
**What** - Implements the admin/store retrieval end point - Service implementation of the retrieve method - Service implementation of the computeLineItems method which aggregates the right line item based on the changes that are made - client - medusa-js api - medusa-react queries hooks **Tests** - Unit tests of the retrieval end points - Unit tests of the service retrieve method and computeLineItems - Integration tests for admin/store - client - medusa-js tests - medusa-react hooks tests FIXES CORE-492
This commit is contained in:
@@ -842,6 +842,34 @@
|
||||
"refunded_total": 0,
|
||||
"refundable_amount": 8200
|
||||
},
|
||||
"order_edit": {
|
||||
"id": "oe_01F0YET7XPCMF8RZ0Y151NZV2V",
|
||||
"order_id": "ord_01F0YET7XPCMF8RZ0Y151NZV2V",
|
||||
"internal_note": "internal note",
|
||||
"declined_reason": null,
|
||||
"declined_at": null,
|
||||
"declined_by": null,
|
||||
"canceled_at": null,
|
||||
"canceled_by": null,
|
||||
"requested_at": null,
|
||||
"requested_by": null,
|
||||
"created_at": "2021-03-16T21:24:35.871Z",
|
||||
"created_by_id": "admin_user",
|
||||
"confirmed_at": null,
|
||||
"confirmed_by": null
|
||||
},
|
||||
"store_order_edit": {
|
||||
"id": "oe_01F0YET7XPCMF8RZ0Y151NZV2B",
|
||||
"order_id": "ord_01F0YET7XPCMF8RZ0Y151NZV2V",
|
||||
"declined_reason": null,
|
||||
"declined_at": null,
|
||||
"declined_by": null,
|
||||
"canceled_at": null,
|
||||
"requested_at": null,
|
||||
"created_at": "2021-03-16T21:24:35.871Z",
|
||||
"confirmed_at": null,
|
||||
"confirmed_by": null
|
||||
},
|
||||
"return": {
|
||||
"id": "ret_01F0YET7XPCMF8RZ0Y151NZV2V",
|
||||
"status": "requested",
|
||||
|
||||
@@ -1653,6 +1653,28 @@ export const adminHandlers = [
|
||||
)
|
||||
}),
|
||||
|
||||
rest.get("/admin/order-edits/:id", (req, res, ctx) => {
|
||||
const { id } = req.params
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
order_edit: fixtures.get("order_edit"),
|
||||
id,
|
||||
})
|
||||
)
|
||||
}),
|
||||
|
||||
rest.get("/store/order-edits/:id", (req, res, ctx) => {
|
||||
const { id } = req.params
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
order_edit: fixtures.get("store_order_edit"),
|
||||
id,
|
||||
})
|
||||
)
|
||||
}),
|
||||
|
||||
rest.get("/admin/auth", (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
|
||||
@@ -12,6 +12,7 @@ export * from "./invites"
|
||||
export * from "./notes"
|
||||
export * from "./notifications"
|
||||
export * from "./orders"
|
||||
export * from "./order-edits"
|
||||
export * from "./price-lists"
|
||||
export * from "./product-tags"
|
||||
export * from "./product-types"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./queries"
|
||||
@@ -0,0 +1,28 @@
|
||||
import { AdminOrdersEditsRes } from "@medusajs/medusa"
|
||||
import { queryKeysFactory } from "../../utils"
|
||||
import { UseQueryOptionsWrapper } from "../../../types"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { useQuery } from "react-query"
|
||||
|
||||
const ADMIN_ORDER_EDITS_QUERY_KEY = `admin_order_edits` as const
|
||||
|
||||
export const adminOrderEditsKeys = queryKeysFactory(ADMIN_ORDER_EDITS_QUERY_KEY)
|
||||
type OrderEditQueryKeys = typeof adminOrderEditsKeys
|
||||
|
||||
export const useAdminOrderEdit = (
|
||||
id: string,
|
||||
options?: UseQueryOptionsWrapper<
|
||||
Response<AdminOrdersEditsRes>,
|
||||
Error,
|
||||
ReturnType<OrderEditQueryKeys["detail"]>
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const { data, ...rest } = useQuery(
|
||||
adminOrderEditsKeys.detail(id),
|
||||
() => client.admin.orderEdits.retrieve(id),
|
||||
options
|
||||
)
|
||||
return { ...data, ...rest } as const
|
||||
}
|
||||
@@ -6,6 +6,7 @@ export * from "./return-reasons/"
|
||||
export * from "./swaps/"
|
||||
export * from "./carts/"
|
||||
export * from "./orders/"
|
||||
export * from "./order-edits"
|
||||
export * from "./customers/"
|
||||
export * from "./returns/"
|
||||
export * from "./gift-cards/"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./queries"
|
||||
@@ -0,0 +1,32 @@
|
||||
import { queryKeysFactory } from "../../utils"
|
||||
import { StoreOrderEditsRes } from "@medusajs/medusa"
|
||||
import { useQuery } from "react-query"
|
||||
import { useMedusa } from "../../../contexts"
|
||||
import { UseQueryOptionsWrapper } from "../../../types"
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
|
||||
const ORDER_EDITS_QUERY_KEY = `orderEdit` as const
|
||||
|
||||
export const orderEditQueryKeys = queryKeysFactory<
|
||||
typeof ORDER_EDITS_QUERY_KEY
|
||||
>(ORDER_EDITS_QUERY_KEY)
|
||||
|
||||
type OrderQueryKey = typeof orderEditQueryKeys
|
||||
|
||||
export const useOrderEdit = (
|
||||
id: string,
|
||||
options?: UseQueryOptionsWrapper<
|
||||
Response<StoreOrderEditsRes>,
|
||||
Error,
|
||||
ReturnType<OrderQueryKey["detail"]>
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const { data, ...rest } = useQuery(
|
||||
orderEditQueryKeys.detail(id),
|
||||
() => client.orderEdits.retrieve(id),
|
||||
options
|
||||
)
|
||||
|
||||
return { ...data, ...rest } as const
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { useAdminOrderEdit } from "../../../../src"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminOrderEdit hook", () => {
|
||||
test("returns an order edit", async () => {
|
||||
const order_edit = fixtures.get("order_edit")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminOrderEdit(order_edit.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.order_edit).toEqual(order_edit)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,21 @@
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
import { useOrderEdit } from "../../../../src/hooks/store/order-edits"
|
||||
|
||||
describe("useOrderEdit hook", () => {
|
||||
test("returns an order", async () => {
|
||||
const store_order_edit = fixtures.get("store_order_edit")
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useOrderEdit(store_order_edit.id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.response.status).toEqual(200)
|
||||
expect(result.current.order_edit).toEqual(store_order_edit)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user