fix(medusa): Remove unsupported Discount endpoints (#1367)
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import { adminDiscountKeys } from "./queries"
|
||||
import { buildOptions } from "../../utils/buildOptions"
|
||||
import {
|
||||
AdminDiscountsDeleteRes,
|
||||
AdminDiscountsRes,
|
||||
@@ -10,6 +8,8 @@ import {
|
||||
import { Response } from "@medusajs/medusa-js"
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from "react-query"
|
||||
import { useMedusa } from "../../../contexts/medusa"
|
||||
import { buildOptions } from "../../utils/buildOptions"
|
||||
import { adminDiscountKeys } from "./queries"
|
||||
|
||||
export const useAdminCreateDiscount = (
|
||||
options?: UseMutationOptions<
|
||||
@@ -79,32 +79,6 @@ export const useAdminDiscountRemoveRegion = (
|
||||
)
|
||||
}
|
||||
|
||||
export const useAdminDiscountAddValidProduct = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<Response<AdminDiscountsRes>, Error, string>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation(
|
||||
(productId: string) =>
|
||||
client.admin.discounts.addValidProduct(id, productId),
|
||||
buildOptions(queryClient, adminDiscountKeys.detail(id), options)
|
||||
)
|
||||
}
|
||||
|
||||
export const useAdminDiscountRemoveValidProduct = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<Response<AdminDiscountsRes>, Error, string>
|
||||
) => {
|
||||
const { client } = useMedusa()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation(
|
||||
(productId: string) =>
|
||||
client.admin.discounts.removeValidProduct(id, productId),
|
||||
buildOptions(queryClient, adminDiscountKeys.detail(id), options)
|
||||
)
|
||||
}
|
||||
|
||||
export const useAdminCreateDynamicDiscountCode = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import {
|
||||
useAdminCreateDiscount,
|
||||
useAdminUpdateDiscount,
|
||||
useAdminDeleteDiscount,
|
||||
useAdminDiscountAddRegion,
|
||||
useAdminDiscountAddValidProduct,
|
||||
useAdminDiscountRemoveRegion,
|
||||
useAdminDiscountRemoveValidProduct,
|
||||
useAdminCreateDynamicDiscountCode,
|
||||
useAdminDeleteDynamicDiscountCode,
|
||||
} from "../../../../src/"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import {
|
||||
useAdminCreateDiscount,
|
||||
useAdminCreateDynamicDiscountCode,
|
||||
useAdminDeleteDiscount,
|
||||
useAdminDeleteDynamicDiscountCode,
|
||||
useAdminDiscountAddRegion,
|
||||
useAdminDiscountRemoveRegion,
|
||||
useAdminUpdateDiscount,
|
||||
} from "../../../../src/"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminCreateDiscount hook", () => {
|
||||
@@ -115,28 +113,6 @@ describe("useAdminDiscountAddRegion hook", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDiscountAddValidProduct hook", () => {
|
||||
test("adds a product to the discount", async () => {
|
||||
const id = fixtures.get("discount").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDiscountAddValidProduct(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-product")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining(fixtures.get("discount"))
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateDynamicDiscountCode hook", () => {
|
||||
test("creates a dynamic discount code", async () => {
|
||||
const discount = {
|
||||
@@ -187,28 +163,6 @@ describe("useAdminDiscountRemoveRegion hook", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDiscountRemoveValidProduct hook", () => {
|
||||
test("adds a product to the discount", async () => {
|
||||
const id = fixtures.get("discount").id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminDiscountRemoveValidProduct(id),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate("test-product")
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining(fixtures.get("discount"))
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminDeleteDynamicDiscountCode hook", () => {
|
||||
test("creates a dynamic discount code", async () => {
|
||||
const id = fixtures.get("discount").id
|
||||
|
||||
Reference in New Issue
Block a user