Feat/add discount condition batch (#2430)
* feat(medusa): Allow to add items to a discount condition by batch + cleanup of discounts and discount conditions end points * style(medusa): cleanup catch and log * feat(medusa-react, medusa-js): Add support to add item batch to discount condition * cleanup * cleanup * rename items to resources * fix(medusa-js): url * Create fast-suns-repair.md * update naming * tests(integration): Update tests to reflect API changes * feat(medusa): Delete a condition should be idempotent on discount and condition * revert
This commit is contained in:
committed by
GitHub
parent
143f8543e5
commit
765a2cccda
@@ -2,6 +2,7 @@ import { DiscountConditionOperator } from "@medusajs/medusa"
|
||||
import { renderHook } from "@testing-library/react-hooks"
|
||||
import { fixtures } from "../../../../mocks/data"
|
||||
import {
|
||||
useAdminAddDiscountConditionResourceBatch,
|
||||
useAdminCreateDiscount,
|
||||
useAdminCreateDynamicDiscountCode,
|
||||
useAdminDeleteDiscount,
|
||||
@@ -15,6 +16,49 @@ import {
|
||||
} from "../../../../src/"
|
||||
import { createWrapper } from "../../../utils"
|
||||
|
||||
describe("useAdminAddDiscountConditionResourceBatch hook", () => {
|
||||
test("add items to a discount condition and return the discount", async () => {
|
||||
const resources = [
|
||||
{
|
||||
id: fixtures.get("product").id,
|
||||
},
|
||||
]
|
||||
const discountId = fixtures.get("discount").id
|
||||
const conditionId = fixtures.get("discount").rule.conditions[0].id
|
||||
|
||||
const { result, waitFor } = renderHook(
|
||||
() => useAdminAddDiscountConditionResourceBatch(discountId, conditionId),
|
||||
{
|
||||
wrapper: createWrapper(),
|
||||
}
|
||||
)
|
||||
|
||||
result.current.mutate({ resources })
|
||||
|
||||
await waitFor(() => result.current.isSuccess)
|
||||
|
||||
expect(result.current.data.response.status).toEqual(200)
|
||||
expect(result.current.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
...fixtures.get("discount"),
|
||||
rule: {
|
||||
...fixtures.get("discount").rule,
|
||||
conditions: [
|
||||
{
|
||||
...fixtures.get("discount").rule.conditions[0],
|
||||
products: [
|
||||
...(fixtures.get("discount").rule.conditions[0]?.products ??
|
||||
[]),
|
||||
{ id: fixtures.get("product").id },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("useAdminCreateDiscount hook", () => {
|
||||
test("creates a discount and returns it", async () => {
|
||||
const discount = {
|
||||
|
||||
Reference in New Issue
Block a user