1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #1809 from node-red-hitachi/0.19-fix-tests-for-trigger-node

Add multiple persistable store tests for trigger node
This commit is contained in:
Nick O'Leary 2018-07-14 22:39:05 +01:00 committed by GitHub
commit 5a0a7b907b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,17 +24,24 @@ var RED = require("../../../../red/red.js");
describe('trigger node', function() { describe('trigger node', function() {
beforeEach(function(done) { beforeEach(function(done) {
helper.startServer(done);
});
function initContext(done) {
Context.init({ Context.init({
contextStorage: { contextStorage: {
memory: { memory0: {
module: "memory"
},
memory1: {
module: "memory" module: "memory"
} }
} }
}); });
Context.load().then(function () { Context.load().then(function () {
helper.startServer(done); done();
});
}); });
}
afterEach(function(done) { afterEach(function(done) {
helper.unload().then(function () { helper.unload().then(function () {
@ -329,10 +336,11 @@ describe('trigger node', function() {
}); });
it('should be able to return things from persistable flow and global context variables', function (done) { it('should be able to return things from persistable flow and global context variables', function (done) {
var flow = [{"id": "n1", "type": "trigger", "name": "triggerNode", "op1": "#:(memory)::foo", "op1type": "flow", var flow = [{"id": "n1", "type": "trigger", "name": "triggerNode", "op1": "#:(memory0)::foo", "op1type": "flow",
"op2": "#:(memory)::bar", "op2type": "global", "duration": "20", "wires": [["n2"]], "z": "flow" }, "op2": "#:(memory0)::bar", "op2type": "global", "duration": "20", "wires": [["n2"]], "z": "flow" },
{"id": "n2", "type": "helper"}]; {"id": "n2", "type": "helper"}];
helper.load(triggerNode, flow, function () { helper.load(triggerNode, flow, function () {
initContext(function () {
var n1 = helper.getNode("n1"); var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2"); var n2 = helper.getNode("n2");
var c = 0; var c = 0;
@ -349,11 +357,136 @@ describe('trigger node', function() {
done(err); done(err);
} }
}); });
n1.context().flow.set("foo", "foo"); var context = n1.context();
n1.context().global.set("bar", "bar"); var flow = context.flow;
var global = context.global;
flow.set("foo", "foo", "memory0", function (err) {
global.set("bar", "bar", "memory0", function (err) {
n1.emit("input", { payload: null }); n1.emit("input", { payload: null });
}); });
}); });
});
});
});
it('should be able to return things from multiple persistable global context variables', function (done) {
var flow = [{"id": "n1", "z": "flow", "type": "trigger",
"duration": "20", "wires": [["n2"]],
"op1": "#:(memory0)::val", "op1type": "global",
"op2": "#:(memory1)::val", "op2type": "global"
},
{"id": "n2", "type": "helper"}];
helper.load(triggerNode, flow, function () {
initContext(function () {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var count = 0;
n2.on("input", function (msg) {
try {
if (count === 0) {
msg.should.have.a.property("payload", "foo");
}
else {
msg.should.have.a.property("payload", "bar");
}
count++;
if (count === 1) {
done();
}
}
catch (err) {
done(err);
}
});
var global = n1.context().global;
global.set("val", "foo", "memory0", function (err) {
global.set("val", "bar", "memory1", function (err) {
n1.emit("input", { payload: null });
});
});
});
});
});
it('should be able to return things from multiple persistable flow context variables', function (done) {
var flow = [{"id": "n1", "z": "flow", "type": "trigger",
"duration": "20", "wires": [["n2"]],
"op1": "#:(memory0)::val", "op1type": "flow",
"op2": "#:(memory1)::val", "op2type": "flow"
},
{"id": "n2", "type": "helper"}];
helper.load(triggerNode, flow, function () {
initContext(function () {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var count = 0;
n2.on("input", function (msg) {
try {
if (count === 0) {
msg.should.have.a.property("payload", "foo");
}
else {
msg.should.have.a.property("payload", "bar");
}
count++;
if (count === 1) {
done();
}
}
catch (err) {
done(err);
}
});
var flow = n1.context().flow;
flow.set("val", "foo", "memory0", function (err) {
flow.set("val", "bar", "memory1", function (err) {
n1.emit("input", { payload: null });
});
});
});
});
});
it('should be able to return things from multiple persistable flow & global context variables', function (done) {
var flow = [{"id": "n1", "z": "flow", "type": "trigger",
"duration": "20", "wires": [["n2"]],
"op1": "#:(memory0)::val", "op1type": "flow",
"op2": "#:(memory1)::val", "op2type": "global"
},
{"id": "n2", "type": "helper"}];
helper.load(triggerNode, flow, function () {
initContext(function () {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
var count = 0;
n2.on("input", function (msg) {
try {
if (count === 0) {
msg.should.have.a.property("payload", "foo");
}
else {
msg.should.have.a.property("payload", "bar");
}
count++;
if (count === 1) {
done();
}
}
catch (err) {
done(err);
}
});
var context = n1.context();
var flow = context.flow;
var global = context.flow;
flow.set("val", "foo", "memory0", function (err) {
global.set("val", "bar", "memory1", function (err) {
n1.emit("input", { payload: null });
});
});
});
});
});
it('should be able to not output anything on first trigger', function(done) { it('should be able to not output anything on first trigger', function(done) {
var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"nul", op1:"true",op2:"false",op2type:"val",duration:"30", wires:[["n2"]] }, var flow = [{"id":"n1", "type":"trigger", "name":"triggerNode", op1type:"nul", op1:"true",op2:"false",op2type:"val",duration:"30", wires:[["n2"]] },