You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.4 KiB
56 lines
2.4 KiB
3 months ago
|
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");
|
||
|
});
|