uptime-kuma/test/backend-test/monitor-conditions/test-expressions.js
Shaun 36f8be040d
Some checks are pending
Auto Test / auto-test (18, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (18, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, windows-latest) (push) Blocked by required conditions
Auto Test / auto-test (20.5, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (20.5, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (20.5, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (20.5, windows-latest) (push) Blocked by required conditions
Auto Test / armv7-simple-test (18, ARMv7) (push) Blocked by required conditions
Auto Test / armv7-simple-test (20, ARMv7) (push) Blocked by required conditions
Auto Test / check-linters (push) Waiting to run
Auto Test / e2e-test (push) Blocked by required conditions
CodeQL / Analyze (go) (push) Waiting to run
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
json-yaml-validate / json-yaml-validate (push) Waiting to run
Monitor Conditions (#5048)
2024-08-30 21:48:13 +02:00

56 lines
2.4 KiB
JavaScript

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");
});