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

Merge pull request #1837 from node-red-hitachi/master-switch-change-test

Fix and add test cases for persistable context
This commit is contained in:
Nick O'Leary 2018-07-23 13:29:23 +01:00 committed by GitHub
commit 490c8dae75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 326 additions and 200 deletions

View File

@ -30,7 +30,10 @@ describe('switch Node', function() {
function initContext(done) { function initContext(done) {
Context.init({ Context.init({
contextStorage: { contextStorage: {
memory: { memory0: {
module: "memory"
},
memory1: {
module: "memory" module: "memory"
} }
} }
@ -41,7 +44,11 @@ describe('switch Node', function() {
} }
afterEach(function(done) { afterEach(function(done) {
helper.unload().then(function(){ helper.unload().then(function () {
return Context.clean({allNodes: {}});
}).then(function () {
return Context.close();
}).then(function () {
RED.settings.nodeMessageBufferMaxLength = 0; RED.settings.nodeMessageBufferMaxLength = 0;
helper.stopServer(done); helper.stopServer(done);
}); });
@ -308,6 +315,102 @@ describe('switch Node', function() {
genericSwitchTest("istype", "undefined", true, true, undefined, done); genericSwitchTest("istype", "undefined", true, true, undefined, done);
}); });
it('should handle flow context', function (done) {
var flow = [{"id": "switchNode1", "type": "switch", "property": "foo", "propertyType": "flow",
"rules": [{"t": "eq", "v": "bar", "vt": "flow"}],
"checkall": "true", "outputs": "1", "wires": [["helperNode1"]], "z": "flow"},
{"id": "helperNode1", "type": "helper", "wires": []}];
helper.load(switchNode, flow, function () {
var switchNode1 = helper.getNode("switchNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function (msg) {
try {
msg.payload.should.equal("value");
done();
} catch (err) {
done(err);
}
});
switchNode1.context().flow.set("foo", "flowValue");
switchNode1.context().flow.set("bar", "flowValue");
switchNode1.receive({payload: "value"});
});
});
it('should handle persistable flow context', function (done) {
var flow = [{"id": "switchNode1", "type": "switch", "property": "#:(memory1)::foo", "propertyType": "flow",
"rules": [{"t": "eq", "v": "#:(memory1)::bar", "vt": "flow"}],
"checkall": "true", "outputs": "1", "wires": [["helperNode1"]], "z": "flow"},
{"id": "helperNode1", "type": "helper", "wires": []}];
helper.load(switchNode, flow, function () {
initContext(function () {
var switchNode1 = helper.getNode("switchNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function (msg) {
try {
msg.payload.should.equal("value");
done();
} catch (err) {
done(err);
}
});
switchNode1.context().flow.set("foo", "flowValue", "memory1", function (err) {
switchNode1.context().flow.set("bar", "flowValue", "memory1", function (err) {
switchNode1.receive({payload: "value"});
});
});
});
});
});
it('should handle global context', function (done) {
var flow = [{"id": "switchNode1", "type": "switch", "property": "foo", "propertyType": "global",
"rules": [{"t": "eq", "v": "bar", "vt": "global"}],
"checkall": "true", "outputs": "1", "wires": [["helperNode1"]]},
{"id": "helperNode1", "type": "helper", "wires": []}];
helper.load(switchNode, flow, function () {
var switchNode1 = helper.getNode("switchNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function (msg) {
try {
msg.payload.should.equal("value");
done();
} catch (err) {
done(err);
}
});
switchNode1.context().global.set("foo", "globalValue");
switchNode1.context().global.set("bar", "globalValue");
switchNode1.receive({payload: "value"});
});
});
it('should handle persistable global context', function (done) {
var flow = [{"id": "switchNode1", "type": "switch", "property": "#:(memory1)::foo", "propertyType": "global",
"rules": [{"t": "eq", "v": "#:(memory1)::bar", "vt": "global"}],
"checkall": "true", "outputs": "1", "wires": [["helperNode1"]]},
{"id": "helperNode1", "type": "helper", "wires": []}];
helper.load(switchNode, flow, function () {
initContext(function () {
var switchNode1 = helper.getNode("switchNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function (msg) {
try {
msg.payload.should.equal("foo");
done();
} catch (err) {
done(err);
}
});
switchNode1.context().global.set("foo", "globalValue", "memory1", function (err) {
switchNode1.context().global.set("bar", "globalValue", "memory1", function (err) {
switchNode1.receive({payload: "foo"});
});
});
});
});
});
it('should match regex with ignore-case flag set true', function(done) { it('should match regex with ignore-case flag set true', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload",rules:[{"t":"regex","v":"onetwothree","case":true}],checkall:true,outputs:1,wires:[["helperNode1"]]}, var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload",rules:[{"t":"regex","v":"onetwothree","case":true}],checkall:true,outputs:1,wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
@ -691,15 +794,15 @@ describe('switch Node', function() {
}); });
it('should handle persistable flow and global contexts with JSONata expression', function(done) { it('should handle persistable flow and global contexts with JSONata expression', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"$abs($flowContext(\"payload\",\"memory\"))",propertyType:"jsonata",rules:[{"t":"btwn","v":"$flowContext(\"vt\",\"memory\")","vt":"jsonata","v2":"$globalContext(\"v2t\",\"memory\")","v2t":"jsonata"}],checkall:true,outputs:1,wires:[["helperNode1"]],z:"flow"}, var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"$abs($flowContext(\"payload\",\"memory1\"))",propertyType:"jsonata",rules:[{"t":"btwn","v":"$flowContext(\"vt\",\"memory1\")","vt":"jsonata","v2":"$globalContext(\"v2t\",\"memory1\")","v2t":"jsonata"}],checkall:true,outputs:1,wires:[["helperNode1"]],z:"flow"},
{id:"helperNode1", type:"helper", wires:[],z:"flow"}, {id:"helperNode1", type:"helper", wires:[],z:"flow"},
{id:"flow",type:"tab"}]; {id:"flow",type:"tab"}];
helper.load(switchNode, flow, function() { helper.load(switchNode, flow, function() {
initContext(function () { initContext(function () {
var switchNode1 = helper.getNode("switchNode1"); var switchNode1 = helper.getNode("switchNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
switchNode1.context().flow.set(["payload","vt"],[-7,6],"memory",function(){ switchNode1.context().flow.set(["payload","vt"],[-7,6],"memory1",function(){
switchNode1.context().global.set("v2t",8,"memory",function(){ switchNode1.context().global.set("v2t",8,"memory1",function(){
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
try { try {
should.equal(msg.payload,"pass"); should.equal(msg.payload,"pass");

View File

@ -119,14 +119,15 @@ describe('change Node', function() {
}); });
it('sets the value of persistable global context property', function(done) { it('sets the value of persistable global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t":"set","p":"#:(memory0)::globalValue","pt":"global","to":"changed","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t":"set","p":"#:(memory1)::globalValue","pt":"global","to":"changed","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
try { try {
changeNode1.context().global.get("globalValue", "meomry", function (err, val) { changeNode1.context().global.get("globalValue", "memory1", function (err, val) {
val.should.equal("changed"); val.should.equal("changed");
done(); done();
}); });
@ -134,10 +135,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().global.set("globalValue","changeMe","memory"); changeNode1.context().global.set("globalValue","changeMe","memory1", function (err) {
changeNode1.receive({payload:""}); changeNode1.receive({payload:""});
}); });
}); });
});
});
it('sets the value and type of the message property', function(done) { it('sets the value and type of the message property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "set", "p": "payload", "pt": "msg", "to": "12345", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "set", "p": "payload", "pt": "msg", "to": "12345", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]]},
@ -344,9 +347,10 @@ describe('change Node', function() {
}); });
it('changes the value to persistable flow context property', function(done) { it('changes the value to persistable flow context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"#:(memory0)::flowValue","tot":"flow"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"#:(memory1)::flowValue","tot":"flow"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
@ -357,11 +361,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().flow.set("flowValue","Hello World!","memory",function(err) { changeNode1.context().flow.set("flowValue","Hello World!","memory1",function(err) {
changeNode1.receive({payload:""}); changeNode1.receive({payload:""});
}); });
}); });
}); });
});
it('changes the value to global context property', function(done) { it('changes the value to global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"globalValue","tot":"global"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"globalValue","tot":"global"}],"name":"changeNode","wires":[["helperNode1"]]},
@ -383,9 +388,10 @@ describe('change Node', function() {
}); });
it('changes the value to persistable global context property', function(done) { it('changes the value to persistable global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"#:(memory0)::globalValue","tot":"global"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"#:(memory1)::globalValue","tot":"global"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
@ -396,11 +402,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().global.set("globalValue","Hello World!","memory", function (err) { changeNode1.context().global.set("globalValue","Hello World!","memory1", function (err) {
changeNode1.receive({payload:""}); changeNode1.receive({payload:""});
}); });
}); });
}); });
});
it('changes the value to a number', function(done) { it('changes the value to a number', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"123","tot":"num"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"123","tot":"num"}],"name":"changeNode","wires":[["helperNode1"]]},
@ -564,7 +571,6 @@ describe('change Node', function() {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"$flowContext(\"foo\")","tot":"jsonata"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"$flowContext(\"foo\")","tot":"jsonata"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"},{"id":"flow","type":"tab"}]; {id:"helperNode1", type:"helper", wires:[],"z":"flow"},{"id":"flow","type":"tab"}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
changeNode1.context().flow.set("foo","bar"); changeNode1.context().flow.set("foo","bar");
@ -579,13 +585,11 @@ describe('change Node', function() {
changeNode1.receive({payload:"Hello World!"}); changeNode1.receive({payload:"Hello World!"});
}); });
}); });
});
it('changes the value using global context with jsonata', function(done) { it('changes the value using global context with jsonata', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"$globalContext(\"foo\")","tot":"jsonata"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"$globalContext(\"foo\")","tot":"jsonata"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"},{"id":"flow","type":"tab"}]; {id:"helperNode1", type:"helper", wires:[],"z":"flow"},{"id":"flow","type":"tab"}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
changeNode1.context().global.set("foo","bar"); changeNode1.context().global.set("foo","bar");
@ -600,7 +604,6 @@ describe('change Node', function() {
changeNode1.receive({payload:"Hello World!"}); changeNode1.receive({payload:"Hello World!"});
}); });
}); });
});
it('changes the value using persistable flow context with jsonata', function(done) { it('changes the value using persistable flow context with jsonata', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"$flowContext(\"foo\",\"memory1\")","tot":"jsonata"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"set","p":"payload","to":"$flowContext(\"foo\",\"memory1\")","tot":"jsonata"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
@ -896,9 +899,10 @@ describe('change Node', function() {
}); });
it('changes the value using persistable flow context property', function(done) { it('changes the value using persistable flow context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"#:(memory0)::topic","to":"123","fromt":"flow","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"#:(memory1)::topic","to":"123","fromt":"flow","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
@ -909,11 +913,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().flow.set("topic","ABC","memory", function (err) { changeNode1.context().flow.set("topic","ABC","memory1", function (err) {
changeNode1.receive({payload:"abcABCabc"}); changeNode1.receive({payload:"abcABCabc"});
}); });
}); });
}); });
});
it('changes the value using global context property', function(done) { it('changes the value using global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"123","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"123","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
@ -935,9 +940,10 @@ describe('change Node', function() {
}); });
it('changes the value using persistable global context property', function(done) { it('changes the value using persistable global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"#:(memory0)::topic","to":"123","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"#:(memory1)::topic","to":"123","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
@ -948,11 +954,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().global.set("topic","ABC","memory",function (err) { changeNode1.context().global.set("topic","ABC","memory1",function (err) {
changeNode1.receive({payload:"abcABCabc"}); changeNode1.receive({payload:"abcABCabc"});
}); });
}); });
}); });
});
it('changes the number using global context property', function(done) { it('changes the number using global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"ABC","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"topic","to":"ABC","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
@ -974,9 +981,10 @@ describe('change Node', function() {
}); });
it('changes the number using persistable global context property', function(done) { it('changes the number using persistable global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"#:(memory0)::topic","to":"ABC","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"#:(memory1)::topic","to":"ABC","fromt":"global","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
@ -987,11 +995,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().global.set("topic",123,"memory",function (err) { changeNode1.context().global.set("topic",123,"memory1",function (err) {
changeNode1.receive({payload:123}); changeNode1.receive({payload:123});
}); });
}); });
}); });
});
it('changes the value using number - string payload', function(done) { it('changes the value using number - string payload', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"123","to":"456","fromt":"num","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"123","to":"456","fromt":"num","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
@ -1085,14 +1094,15 @@ describe('change Node', function() {
}); });
it('changes the value of the persistable global context', function(done) { it('changes the value of the persistable global context', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory0)::payload", "pt": "global", "from": "Hello", "fromt": "str", "to": "Goodbye", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory1)::payload", "pt": "global", "from": "Hello", "fromt": "str", "to": "Goodbye", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}]; {id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
try { try {
helperNode1.context().global.get("payload","memory", function (err, val) { helperNode1.context().global.get("payload","memory1", function (err, val) {
val.should.equal("Goodbye World!"); val.should.equal("Goodbye World!");
done(); done();
}); });
@ -1100,11 +1110,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().global.set("payload","Hello World!","memory",function (err) { changeNode1.context().global.set("payload","Hello World!","memory1",function (err) {
changeNode1.receive({payload:""}); changeNode1.receive({payload:""});
}); });
}); });
}); });
});
it('changes the value and doesnt change type of the flow context for partial match', function(done) { it('changes the value and doesnt change type of the flow context for partial match', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
@ -1127,14 +1138,15 @@ describe('change Node', function() {
}); });
it('changes the value and doesnt change type of the persistable flow context for partial match', function(done) { it('changes the value and doesnt change type of the persistable flow context for partial match', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory0)::payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory1)::payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}]; {id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
try { try {
helperNode1.context().flow.get("payload","memory",function (err, val) { helperNode1.context().flow.get("payload","memory1",function (err, val) {
val.should.equal("Change456Me"); val.should.equal("Change456Me");
val.should.be.a.String(); val.should.be.a.String();
done(); done();
@ -1143,11 +1155,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().flow.set("payload","Change123Me","memory",function (err) { changeNode1.context().flow.set("payload","Change123Me","memory1",function (err) {
changeNode1.receive({payload:""}); changeNode1.receive({payload:""});
}); });
}); });
}); });
});
it('changes the value and type of the flow context if a complete match', function(done) { it('changes the value and type of the flow context if a complete match', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
@ -1170,25 +1183,29 @@ describe('change Node', function() {
}); });
it('changes the value and type of the persistable flow context if a complete match', function(done) { it('changes the value and type of the persistable flow context if a complete match', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory0)::payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory1)::payload", "pt": "flow", "from": "123", "fromt": "str", "to": "456", "tot": "num" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}]; {id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
try { try {
helperNode1.context().flow.get("payload").should.equal(456); helperNode1.context().flow.get("payload","memory1",function (err, val) {
helperNode1.context().flow.get("payload").should.be.a.Number(); val.should.be.a.Number();
val.should.equal(456);
done(); done();
});
} catch(err) { } catch(err) {
done(err); done(err);
} }
}); });
changeNode1.context().flow.set("payload","123","memory",function (err) { changeNode1.context().flow.set("payload","123","memory1",function (err) {
changeNode1.receive({payload:""}); changeNode1.receive({payload:""});
}); });
}); });
}); });
});
it('changes the value using number - number flow context', function(done) { it('changes the value using number - number flow context', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "123", "fromt": "num", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "123", "fromt": "num", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
@ -1210,14 +1227,15 @@ describe('change Node', function() {
}); });
it('changes the value using number - number persistable flow context', function(done) { it('changes the value using number - number persistable flow context', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory0)::payload", "pt": "flow", "from": "123", "fromt": "num", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory1)::payload", "pt": "flow", "from": "123", "fromt": "num", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}]; {id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
try { try {
helperNode1.context().flow.get("payload","memory",function (err, val) { helperNode1.context().flow.get("payload","memory1",function (err, val) {
val.should.equal("abc"); val.should.equal("abc");
done(); done();
}); });
@ -1225,11 +1243,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().flow.set("payload",123,"memory",function (err) { changeNode1.context().flow.set("payload",123,"memory1",function (err) {
changeNode1.receive({payload:""}); changeNode1.receive({payload:""});
}); });
}); });
}); });
});
it('changes the value using boolean - boolean flow context', function(done) { it('changes the value using boolean - boolean flow context', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "true", "fromt": "bool", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "payload", "pt": "flow", "from": "true", "fromt": "bool", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
@ -1251,14 +1270,15 @@ describe('change Node', function() {
}); });
it('changes the value using boolean - boolean persistable flow context', function(done) { it('changes the value using boolean - boolean persistable flow context', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory0)::payload", "pt": "flow", "from": "true", "fromt": "bool", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "change", "p": "#:(memory1)::payload", "pt": "flow", "from": "true", "fromt": "bool", "to": "abc", "tot": "str" }],"reg":false,"name":"changeNode","wires":[["helperNode1"]],"z":"flow"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"}]; {id:"helperNode1", type:"helper", wires:[],"z":"flow"}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
try { try {
helperNode1.context().flow.get("payload","memory",function (err, val) { helperNode1.context().flow.get("payload","memory1",function (err, val) {
val.should.equal("abc"); val.should.equal("abc");
done(); done();
}); });
@ -1266,11 +1286,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().flow.set("payload",true,function (err) { changeNode1.context().flow.set("payload",true,"memory1",function (err) {
changeNode1.receive({payload:""}); changeNode1.receive({payload:""});
}); });
}); });
}); });
});
it('reports invalid fromValue', function(done) { it('reports invalid fromValue', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"null","fromt":"msg","to":"abc","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{"t":"change","p":"payload","from":"null","fromt":"msg","to":"abc","tot":"str"}],"name":"changeNode","wires":[["helperNode1"]]},
@ -1358,14 +1379,15 @@ describe('change Node', function() {
}); });
it('deletes the value of persistable global context property', function(done) { it('deletes the value of persistable global context property', function(done) {
var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "delete", "p": "#:(memory0)::globalValue", "pt": "global"}],"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change",rules:[{ "t": "delete", "p": "#:(memory1)::globalValue", "pt": "global"}],"name":"changeNode","wires":[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}]; {id:"helperNode1", type:"helper", wires:[]}];
helper.load(changeNode, flow, function() { helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1"); var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1"); var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) { helperNode1.on("input", function(msg) {
try { try {
changeNode1.context().global.get("globalValue","memory",function(err,val) { changeNode1.context().global.get("globalValue","memory1",function(err,val) {
should.equal(undefined); should.equal(undefined);
done(); done();
}); });
@ -1373,11 +1395,12 @@ describe('change Node', function() {
done(err); done(err);
} }
}); });
changeNode1.context().global.set("globalValue","Hello World!","memory",function (err) { changeNode1.context().global.set("globalValue","Hello World!","memory1",function (err) {
changeNode1.receive({payload:""}); changeNode1.receive({payload:""});
}); });
}); });
}); });
});
it('deletes the value of a multi-level message property', function(done) { it('deletes the value of a multi-level message property', function(done) {
var flow = [{"id":"changeNode1","type":"change","action":"delete","property":"foo.bar","from":"","to":"","reg":false,"name":"changeNode","wires":[["helperNode1"]]}, var flow = [{"id":"changeNode1","type":"change","action":"delete","property":"foo.bar","from":"","to":"","reg":false,"name":"changeNode","wires":[["helperNode1"]]},