mirror of https://github.com/Budibase/budibase.git
10 changed files with 40 additions and 95 deletions
@ -1,20 +0,0 @@ |
|||||
let filter = require("./steps/filter") |
|
||||
let delay = require("./steps/delay") |
|
||||
|
|
||||
let LOGIC_IMPLS = { |
|
||||
DELAY: delay.run, |
|
||||
FILTER: filter.run, |
|
||||
} |
|
||||
|
|
||||
let LOGIC_DEFINITIONS = { |
|
||||
DELAY: delay.definition, |
|
||||
FILTER: filter.definition, |
|
||||
} |
|
||||
|
|
||||
exports.getLogic = function (logicName) { |
|
||||
if (LOGIC_IMPLS[logicName] != null) { |
|
||||
return LOGIC_IMPLS[logicName] |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
exports.LOGIC_DEFINITIONS = LOGIC_DEFINITIONS |
|
||||
@ -1,48 +1,48 @@ |
|||||
const setup = require("./utilities") |
const setup = require("./utilities") |
||||
const { LogicConditions } = require("../steps/filter") |
const { FilterConditions } = require("../steps/filter") |
||||
|
|
||||
describe("test the filter logic", () => { |
describe("test the filter logic", () => { |
||||
async function checkFilter(field, condition, value, pass = true) { |
async function checkFilter(field, condition, value, pass = true) { |
||||
let res = await setup.runStep(setup.logic.FILTER.stepId, |
let res = await setup.runStep(setup.actions.FILTER.stepId, |
||||
{ field, condition, value } |
{ field, condition, value } |
||||
) |
) |
||||
expect(res.success).toEqual(pass) |
expect(res.success).toEqual(pass) |
||||
} |
} |
||||
|
|
||||
it("should be able test equality", async () => { |
it("should be able test equality", async () => { |
||||
await checkFilter("hello", LogicConditions.EQUAL, "hello", true) |
await checkFilter("hello", FilterConditions.EQUAL, "hello", true) |
||||
await checkFilter("hello", LogicConditions.EQUAL, "no", false) |
await checkFilter("hello", FilterConditions.EQUAL, "no", false) |
||||
}) |
}) |
||||
|
|
||||
it("should be able to test greater than", async () => { |
it("should be able to test greater than", async () => { |
||||
await checkFilter(10, LogicConditions.GREATER_THAN, 5, true) |
await checkFilter(10, FilterConditions.GREATER_THAN, 5, true) |
||||
await checkFilter(10, LogicConditions.GREATER_THAN, 15, false) |
await checkFilter(10, FilterConditions.GREATER_THAN, 15, false) |
||||
}) |
}) |
||||
|
|
||||
it("should be able to test less than", async () => { |
it("should be able to test less than", async () => { |
||||
await checkFilter(5, LogicConditions.LESS_THAN, 10, true) |
await checkFilter(5, FilterConditions.LESS_THAN, 10, true) |
||||
await checkFilter(15, LogicConditions.LESS_THAN, 10, false) |
await checkFilter(15, FilterConditions.LESS_THAN, 10, false) |
||||
}) |
}) |
||||
|
|
||||
it("should be able to in-equality", async () => { |
it("should be able to in-equality", async () => { |
||||
await checkFilter("hello", LogicConditions.NOT_EQUAL, "no", true) |
await checkFilter("hello", FilterConditions.NOT_EQUAL, "no", true) |
||||
await checkFilter(10, LogicConditions.NOT_EQUAL, 10, false) |
await checkFilter(10, FilterConditions.NOT_EQUAL, 10, false) |
||||
}) |
}) |
||||
|
|
||||
it("check number coercion", async () => { |
it("check number coercion", async () => { |
||||
await checkFilter("10", LogicConditions.GREATER_THAN, "5", true) |
await checkFilter("10", FilterConditions.GREATER_THAN, "5", true) |
||||
}) |
}) |
||||
|
|
||||
it("check date coercion", async () => { |
it("check date coercion", async () => { |
||||
await checkFilter( |
await checkFilter( |
||||
(new Date()).toISOString(), |
(new Date()).toISOString(), |
||||
LogicConditions.GREATER_THAN, |
FilterConditions.GREATER_THAN, |
||||
(new Date(-10000)).toISOString(), |
(new Date(-10000)).toISOString(), |
||||
true |
true |
||||
) |
) |
||||
}) |
}) |
||||
|
|
||||
it("check objects always false", async () => { |
it("check objects always false", async () => { |
||||
await checkFilter({}, LogicConditions.EQUAL, {}, false) |
await checkFilter({}, FilterConditions.EQUAL, {}, false) |
||||
}) |
}) |
||||
}) |
}) |
||||
Loading…
Reference in new issue