feat(medusa, medusa-js, medusa-react): Implement Sales Channel deletion (#1804)

This commit is contained in:
Adrien de Peretti authored and GitHub committed 2022-07-07 10:47:51 +02:00
1 parent 4d15e01c3e
commit 2d03634cfc
13 files changed
+368 -21

No files matched your search

+12 -1
View File
@@ -869,7 +869,7 @@ export const adminHandlers = [
discount_condition: {
...fixtures
.get("discount")
.rule.conditions.find((c) => c.id === req.params.conditionId),
.rule.conditions.find(c => c.id === req.params.conditionId),
},
})
)
@@ -1703,4 +1703,15 @@ export const adminHandlers = [
})
)
}),
rest.delete("/admin/sales-channels/:id", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
id: req.params.id,
object: "sales-channel",
deleted: true,
})
)
}),
]
@@ -2,6 +2,7 @@ import {
AdminPostSalesChannelsReq,
AdminSalesChannelsRes,
AdminPostSalesChannelsSalesChannelReq,
AdminSalesChannelsDeleteRes,
} from "@medusajs/medusa"
import { Response } from "@medusajs/medusa-js"
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
@@ -59,3 +60,30 @@ export const useAdminUpdateSalesChannel = (
)
)
}
/**
* Delete a sales channel
* @experimental This feature is under development and may change in the future.
* To use this feature please enable featureflag `sales_channels` in your medusa backend project.
* @param id
* @param options
*/
export const useAdminDeleteSalesChannel = (
id: string,
options?: UseMutationOptions<
Response<AdminSalesChannelsDeleteRes>,
Error,
void
>
) => {
const { client } = useMedusa()
const queryClient = useQueryClient()
return useMutation(
() => client.admin.salesChannels.delete(id),
buildOptions(
queryClient,
[adminSalesChannelsKeys.lists(), adminSalesChannelsKeys.detail(id)],
options
)
)
}
@@ -1,6 +1,10 @@
import { renderHook } from "@testing-library/react-hooks"
import { useAdminCreateSalesChannel, useAdminUpdateSalesChannel } from "../../../../src"
import {
useAdminDeleteSalesChannel,
useAdminCreateSalesChannel,
useAdminUpdateSalesChannel,
} from "../../../../src"
import { fixtures } from "../../../../mocks/data"
import { createWrapper } from "../../../utils"
@@ -30,7 +34,7 @@ describe("useAdminCreateSalesChannel hook", () => {
})
describe("useAdminUpdateSalesChannel hook", () => {
test("updates a store", async () => {
test("updates a sales channel", async () => {
const salesChannel = {
name: "medusa sales channel",
description: "main sales channel for medusa",
@@ -57,3 +61,26 @@ describe("useAdminUpdateSalesChannel hook", () => {
})
})
})
describe("useAdminDeleteSalesChannel hook", () => {
test("deletes a sales channel", async () => {
const id = fixtures.get("sales_channel").id
const { result, waitFor } = renderHook(
() => useAdminDeleteSalesChannel(id),
{ wrapper: createWrapper() }
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data).toEqual(
expect.objectContaining({
id,
object: "sales-channel",
deleted: true,
})
)
})
})