diff options
Diffstat (limited to 'test/backend-test/monitor-conditions/test-expressions.js')
-rw-r--r-- | test/backend-test/monitor-conditions/test-expressions.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/backend-test/monitor-conditions/test-expressions.js b/test/backend-test/monitor-conditions/test-expressions.js new file mode 100644 index 0000000..fc723a2 --- /dev/null +++ b/test/backend-test/monitor-conditions/test-expressions.js @@ -0,0 +1,55 @@ +const test = require("node:test"); +const assert = require("node:assert"); +const { ConditionExpressionGroup, ConditionExpression } = require("../../../server/monitor-conditions/expression.js"); + +test("Test ConditionExpressionGroup.fromMonitor", async (t) => { + const monitor = { + conditions: JSON.stringify([ + { + "type": "expression", + "andOr": "and", + "operator": "contains", + "value": "foo", + "variable": "record" + }, + { + "type": "group", + "andOr": "and", + "children": [ + { + "type": "expression", + "andOr": "and", + "operator": "contains", + "value": "bar", + "variable": "record" + }, + { + "type": "group", + "andOr": "and", + "children": [ + { + "type": "expression", + "andOr": "and", + "operator": "contains", + "value": "car", + "variable": "record" + } + ] + }, + ] + }, + ]), + }; + const root = ConditionExpressionGroup.fromMonitor(monitor); + assert.strictEqual(true, root.children.length === 2); + assert.strictEqual(true, root.children[0] instanceof ConditionExpression); + assert.strictEqual(true, root.children[0].value === "foo"); + assert.strictEqual(true, root.children[1] instanceof ConditionExpressionGroup); + assert.strictEqual(true, root.children[1].children.length === 2); + assert.strictEqual(true, root.children[1].children[0] instanceof ConditionExpression); + assert.strictEqual(true, root.children[1].children[0].value === "bar"); + assert.strictEqual(true, root.children[1].children[1] instanceof ConditionExpressionGroup); + assert.strictEqual(true, root.children[1].children[1].children.length === 1); + assert.strictEqual(true, root.children[1].children[1].children[0] instanceof ConditionExpression); + assert.strictEqual(true, root.children[1].children[1].children[0].value === "car"); +}); |