And add some tests

This commit is contained in:
Dave Conway-Jones 2024-10-12 17:09:18 +01:00
parent 2eba754801
commit 61fd01b871
No known key found for this signature in database
GPG Key ID: 1DDB0E91A28C2643

View File

@ -111,8 +111,16 @@ describe('trigger node', function() {
try {
if (rval) {
msg.should.have.property("payload");
if (type == "date" && val == "1") {
should.deepEqual(Math.round(msg.payload/10000), Math.round(rval/10000));
}
else if (type == "date" && val == "iso") {
should.deepEqual(msg.payload.substr(0,11), rval.substr(0,11));
}
else {
should.deepEqual(msg.payload, rval);
}
}
else {
msg.should.have.property("payload", val);
}
@ -126,6 +134,7 @@ describe('trigger node', function() {
});
it('should output 2st value when triggered ('+type+')', function(done) {
if (type == "date" && val == "1") { val = "0"; }
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1:"foo", op1type:"str", op2:val, op2type:type, duration:"20", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
process.env[val] = rval;
@ -142,8 +151,16 @@ describe('trigger node', function() {
else {
if (rval) {
msg.should.have.property("payload");
if (type == "date" && val == "0") {
should.deepEqual(Math.round(msg.payload/10000), Math.round(rval/10000));
}
else if (type == "date" && val == "iso") {
should.deepEqual(msg.payload.substr(0,11), rval.substr(0,11));
}
else {
should.deepEqual(msg.payload, rval);
}
}
else {
msg.should.have.property("payload", val);
}
@ -166,6 +183,9 @@ describe('trigger node', function() {
var val_buf = "[1,2,3,4,5]";
basicTest("bin", val_buf, Buffer.from(JSON.parse(val_buf)));
basicTest("env", "NR-TEST", "env-val");
basicTest("date", "1", Date.now());
basicTest("date", "iso", (new Date()).toISOString());
// basicTest("date", "object", Date.now());
it('should output 1 then 0 when triggered (default)', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", duration:"20", wires:[["n2"]] },