feat(medusa): Trim discount code on insert and retrieve (#2369)

This commit is contained in:
Oliver Windall Juhl authored and GitHub committed 2022-10-07 09:07:32 +02:00
1 parent 1c688ec499
commit d2b272fab6
5 files changed
+93 -11

No files matched your search

@@ -1,6 +1,6 @@
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
import DiscountService from "../discount"
import { FlagRouter } from "../../utils/flag-router"
import DiscountService from "../discount"
const featureFlagRouter = new FlagRouter({})
@@ -74,7 +74,7 @@ describe("DiscountService", () => {
expect(discountRepository.create).toHaveBeenCalledTimes(1)
expect(discountRepository.create).toHaveBeenCalledWith({
code: "TEST",
code: "test",
rule: expect.anything(),
regions: [{ id: IdMap.getId("france") }],
})
@@ -106,7 +106,7 @@ describe("DiscountService", () => {
expect(discountRepository.create).toHaveBeenCalledTimes(1)
expect(discountRepository.create).toHaveBeenCalledWith({
code: "TEST",
code: "test",
rule: expect.anything(),
regions: [{ id: IdMap.getId("france") }],
starts_at: new Date("03/14/2021"),
@@ -140,7 +140,7 @@ describe("DiscountService", () => {
expect(discountRepository.create).toHaveBeenCalledTimes(1)
expect(discountRepository.create).toHaveBeenCalledWith({
code: "TEST",
code: "test",
rule: expect.anything(),
regions: [{ id: IdMap.getId("france") }],
starts_at: new Date("03/14/2021"),
@@ -225,6 +225,17 @@ describe("DiscountService", () => {
},
})
})
it("successfully trims, uppdercases, and finds discount by code", async () => {
await discountService.retrieveByCode(" 10%Off ")
expect(discountRepository.findOne).toHaveBeenCalledTimes(1)
expect(discountRepository.findOne).toHaveBeenCalledWith({
where: {
code: "10%OFF",
is_dynamic: false,
},
})
})
})
describe("update", () => {