mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-24 23:35:46 -04:00
Monitor Conditions (#5048)
This commit is contained in:
parent
032ac161f7
commit
36f8be040d
21 changed files with 1526 additions and 35 deletions
55
test/backend-test/monitor-conditions/test-expressions.js
Normal file
55
test/backend-test/monitor-conditions/test-expressions.js
Normal file
|
@ -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");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue