name:
src/test/js/execution/CodeExecutorGeneralCustomFormulaTest.ts
-rw-r--r--
1094
1import { assert } from "chai";
2import { it, describe } from "../testutils/TestUtils";
3import { runWithCustomFormulas } from "../testutils/TestUtils";
4
5describe("CodeExecutor - Custom Formula Test", function () {
6 it("should work without arguments", function () {
7 assert.equal(runWithCustomFormulas("CUSTOM()", { CUSTOM: () => 22 }), 22);
8 assert.equal(runWithCustomFormulas("ANOTHER()", { ANOTHER: () => true }), true);
9 });
10
11 it("should work with number arguments", function () {
12 assert.equal(
13 runWithCustomFormulas("MULTIPLY_AND_ADD_ONE(2, 4)", {
14 MULTIPLY_AND_ADD_ONE: (x: any, y: any) => x * y + 1,
15 }),
16 9
17 );
18 });
19
20 it("should work with string arguments", function () {
21 assert.equal(
22 runWithCustomFormulas("CUSTOM_CONCAT(2, 4)", {
23 CUSTOM_CONCAT: (x: any, y: any) => x.toString() + y.toString(),
24 }),
25 "24"
26 );
27 });
28
29 it("should work with boolean arguments", function () {
30 assert.equal(
31 runWithCustomFormulas("BOTH_YES(TRUE, TRUE)", { BOTH_YES: (x: any, y: any) => x && y }),
32 true
33 );
34 });
35});