Feat(medusa): cancel order edit (#2240)
**What** - cancel an order edit Fixes CORE-500
This commit is contained in:
1 parent
d138baf460
commit
1807bff029
12 files changed
+393
-16
No files matched your search
@@ -1695,6 +1695,15 @@ export const adminHandlers = [
|
||||
})
|
||||
)
|
||||
}),
|
||||
|
||||
rest.post("/admin/order-edits/:id/cancel", (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
order_edit: { ...fixtures.get("order_edit"), canceled_at: new Date(), status: 'canceled' },
|
||||
})
|
||||
)
|
||||
}),
|
||||
|
||||
rest.post("/admin/order-edits/:id/request", (req, res, ctx) => {
|
||||
return res(
|
||||
|
||||
@@ -106,3 +106,25 @@ export const useAdminRequestOrderEditConfirmation = (
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export const useAdminCancelOrderEdit = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
Response<AdminOrderEditsRes>,
|
||||
Error
|
||||
>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation(
|
||||
() =>
|
||||
client.admin.orderEdits.cancel(id),
|
||||
buildOptions(
|
||||
queryClient,
|
||||
[adminOrderEditsKeys.lists(), adminOrderEditsKeys.detail(id)],
|
||||
options
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
useAdminDeleteOrderEditItemChange,
|
||||
useAdminUpdateOrderEdit,
|
||||
useAdminRequestOrderEditConfirmation,
|
||||
useAdminCancelOrderEdit,
|
||||
} from "../../../../src/"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import { createWrapper } from "../../../utils"
|
||||
@@ -129,3 +130,27 @@ describe("useAdminRequestOrderEditConfirmation hook", () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCancelOrderEdit hook", () => {
|
||||
test("cancel an order edit", async () => {
|
||||
|
||||
const { result, waitFor } = renderHook(() => useAdminCancelOrderEdit(fixtures.get("order_edit").id), {
|
||||
wrapper: createWrapper(),
|
||||
})
|
||||
|
||||
result.current.mutate()
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data).toEqual(
|
||||
expect.objectContaining({
|
||||
order_edit: {
|
||||
...fixtures.get("order_edit"),
|
||||
canceled_at: expect.any(String),
|
||||
status: 'canceled'
|
||||
},
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user