Adds dynamic coupon codes and segment plugin
This commit is contained in:
1 parent
ec6a538877
commit
3710f7f80a
41 files changed
+11784
-109
No files matched your search
@@ -1,5 +1,9 @@
|
||||
import DiscountService from "../discount"
|
||||
import { DiscountModelMock, discounts } from "../../models/__mocks__/discount"
|
||||
import {
|
||||
DynamicDiscountCodeModelMock,
|
||||
dynamicDiscounts,
|
||||
} from "../../models/__mocks__/dynamic-discount-code"
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import { ProductVariantServiceMock } from "../__mocks__/product-variant"
|
||||
import { RegionServiceMock } from "../__mocks__/region"
|
||||
@@ -61,6 +65,46 @@ describe("DiscountService", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("retrieveByCode", () => {
|
||||
let res
|
||||
const discountService = new DiscountService({
|
||||
discountModel: DiscountModelMock,
|
||||
dynamicDiscountCodeModel: DynamicDiscountCodeModelMock,
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("calls model layer findOne", async () => {
|
||||
res = await discountService.retrieveByCode("10%off")
|
||||
expect(DiscountModelMock.findOne).toHaveBeenCalledTimes(1)
|
||||
expect(DiscountModelMock.findOne).toHaveBeenCalledWith({
|
||||
code: "10%OFF",
|
||||
})
|
||||
expect(res).toEqual(discounts.total10Percent)
|
||||
})
|
||||
|
||||
it("finds dynamic code", async () => {
|
||||
res = await discountService.retrieveByCode("dynamicoff")
|
||||
expect(DiscountModelMock.findOne).toHaveBeenCalledTimes(2)
|
||||
expect(DiscountModelMock.findOne).toHaveBeenCalledWith({
|
||||
_id: IdMap.getId("dynamic"),
|
||||
})
|
||||
expect(DiscountModelMock.findOne).toHaveBeenCalledWith({
|
||||
code: "DYNAMICOFF",
|
||||
})
|
||||
expect(DynamicDiscountCodeModelMock.findOne).toHaveBeenCalledTimes(1)
|
||||
expect(DynamicDiscountCodeModelMock.findOne).toHaveBeenCalledWith({
|
||||
code: "DYNAMICOFF",
|
||||
})
|
||||
expect(res).toEqual({
|
||||
...discounts.dynamic,
|
||||
code: "DYNAMICOFF",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
const discountService = new DiscountService({
|
||||
discountModel: DiscountModelMock,
|
||||
|
||||
Reference in new issue
Block a user