summaryrefslogtreecommitdiffstats
path: root/test/backend-test/monitor-conditions/test-expressions.js
blob: fc723a2444b6ecf959a89a921193e0ead6f1b92f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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");
});