1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +12:00
budibase/packages/server/src/automations/tests/filter.spec.js
2022-09-28 08:56:45 +01:00

50 lines
1.6 KiB
JavaScript

const setup = require("./utilities")
const { FilterConditions } = require("../steps/filter")
describe("test the filter logic", () => {
async function checkFilter(field, condition, value, pass = true) {
let res = await setup.runStep(setup.actions.FILTER.stepId,
{ field, condition, value }
)
expect(res.result).toEqual(pass)
expect(res.success).toEqual(true)
}
it("should be able test equality", async () => {
await checkFilter("hello", FilterConditions.EQUAL, "hello", true)
await checkFilter("hello", FilterConditions.EQUAL, "no", false)
})
it("should be able to test greater than", async () => {
await checkFilter(10, FilterConditions.GREATER_THAN, 5, true)
await checkFilter(10, FilterConditions.GREATER_THAN, 15, false)
})
it("should be able to test less than", async () => {
await checkFilter(5, FilterConditions.LESS_THAN, 10, true)
await checkFilter(15, FilterConditions.LESS_THAN, 10, false)
})
it("should be able to in-equality", async () => {
await checkFilter("hello", FilterConditions.NOT_EQUAL, "no", true)
await checkFilter(10, FilterConditions.NOT_EQUAL, 10, false)
})
it("check number coercion", async () => {
await checkFilter("10", FilterConditions.GREATER_THAN, "5", true)
})
it("check date coercion", async () => {
await checkFilter(
(new Date()).toISOString(),
FilterConditions.GREATER_THAN,
(new Date(-10000)).toISOString(),
true
)
})
it("check objects always false", async () => {
await checkFilter({}, FilterConditions.EQUAL, {}, false)
})
})