fix(promotion): eval conditions for rules are made accurate (#10915)

what:

- fixes eval conditions for promotion rules

RESOLVES CMRC-851
This commit is contained in:
Riqwan Thamir
2025-01-21 21:26:20 +00:00
committed by GitHub
parent cc73802ab3
commit 8119d9964b
6 changed files with 321 additions and 86 deletions
@@ -0,0 +1,84 @@
import { Modules } from "@medusajs/framework/utils"
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
import { evaluateRuleValueCondition } from "../../../../src/utils/validations/promotion-rule"
moduleIntegrationTestRunner({
moduleName: Modules.PROMOTION,
testSuite: () => {
describe("evaluateRuleValueCondition", () => {
const testFunc = evaluateRuleValueCondition
describe("eq", () => {
const operator = "eq"
it("should evaluate conditions accurately", async () => {
expect(testFunc(["2"], operator, [2])).toEqual(true)
expect(testFunc(["2"], operator, ["2"])).toEqual(true)
expect(testFunc(["2"], operator, ["22"])).toEqual(false)
})
})
describe("ne", () => {
const operator = "ne"
it("should evaluate conditions accurately", async () => {
expect(testFunc(["2"], operator, [2])).toEqual(false)
expect(testFunc(["2"], operator, ["2"])).toEqual(false)
expect(testFunc(["2"], operator, ["22"])).toEqual(true)
})
})
describe("gt", () => {
const operator = "gt"
it("should evaluate conditions accurately", async () => {
expect(testFunc(["2"], operator, [1])).toEqual(false)
expect(testFunc(["2"], operator, ["1"])).toEqual(false)
expect(testFunc(["2"], operator, [2])).toEqual(false)
expect(testFunc(["2"], operator, ["2"])).toEqual(false)
expect(testFunc(["2"], operator, ["22"])).toEqual(true)
expect(testFunc(["2"], operator, [22])).toEqual(true)
})
})
describe("gte", () => {
const operator = "gte"
it("should evaluate conditions accurately", async () => {
expect(testFunc(["2"], operator, [1])).toEqual(false)
expect(testFunc(["2"], operator, ["1"])).toEqual(false)
expect(testFunc(["2"], operator, [2])).toEqual(true)
expect(testFunc(["2"], operator, ["2"])).toEqual(true)
expect(testFunc(["2"], operator, ["22"])).toEqual(true)
expect(testFunc(["2"], operator, [22])).toEqual(true)
})
})
describe("lt", () => {
const operator = "lt"
it("should evaluate conditions accurately", async () => {
expect(testFunc([1], operator, ["2"])).toEqual(false)
expect(testFunc(["1"], operator, ["2"])).toEqual(false)
expect(testFunc([2], operator, ["2"])).toEqual(false)
expect(testFunc(["2"], operator, ["2"])).toEqual(false)
expect(testFunc(["22"], operator, ["2"])).toEqual(true)
expect(testFunc([22], operator, ["2"])).toEqual(true)
})
})
describe("lte", () => {
const operator = "lte"
it("should evaluate conditions accurately", async () => {
expect(testFunc([1], operator, ["2"])).toEqual(false)
expect(testFunc(["1"], operator, ["2"])).toEqual(false)
expect(testFunc([2], operator, ["2"])).toEqual(true)
expect(testFunc(["2"], operator, ["2"])).toEqual(true)
expect(testFunc(["22"], operator, ["2"])).toEqual(true)
expect(testFunc([22], operator, ["2"])).toEqual(true)
})
})
})
},
})