const nm_assert = require("assert"); declare var describe; declare var it; _heimdall.init(); describe( "heimdall", () => { function datetimestring_to_timestamp(datetimestring) { return Math.floor((new Date(datetimestring)).getTime() / 1000); }; describe( "master.determine_due", () => { const cases = [ { "name": "regular interval hit", "input": { "check": { "active": true, "threshold": 1, "annoy": false, "schedule": { "regular_interval": 3600, "attentive_interval": 120, "reminding_interval": 86400, }, "notifications": [], "name": "test", "title": "Test", "kind": "BOGUS", "parameters": {}, "custom": null, }, "timestamp": "2023-01-15T12:30:00", "old_item_state": { "timestamp": "2023-01-15T11:00:00", "condition": _heimdall.enum_condition.ok, "count": 0, "last_notification_timestamp": "2023-01-15T10:00:00" } }, "output": true, }, { "name": "regular interval not hit", "input": { "check": { "active": true, "threshold": 1, "annoy": false, "schedule": { "regular_interval": 3600, "attentive_interval": 120, "reminding_interval": 86400, }, "notifications": [], "name": "test", "title": "Test", "kind": "BOGUS", "parameters": {}, "custom": null, }, "timestamp": "2023-01-15T11:30:00", "old_item_state": { "timestamp": "2023-01-15T11:00:00", "condition": _heimdall.enum_condition.ok, "count": 0, "last_notification_timestamp": "2023-01-15T10:00:00" } }, "output": false, }, ]; cases.forEach( case_ => { it( case_.name, () => { // execution const result : boolean = _heimdall.master.determine_due( case_.input["check"], datetimestring_to_timestamp(case_.input["timestamp"]), { "timestamp": datetimestring_to_timestamp(case_.input["old_item_state"]["timestamp"]), "condition": case_.input["old_item_state"]["condition"], "count": case_.input["old_item_state"]["count"], "last_notification_timestamp": datetimestring_to_timestamp(case_.input["old_item_state"]["last_notification_timestamp"]), } ); // assertions nm_assert.equal(result, case_.output); } ); } ); } ); } );