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) {
Context.init({
contextStorage: {
memory: {
memory0: {
module: "memory"
},
memory1: {
module: "memory"
}
}
@ -41,7 +44,11 @@ describe('switch Node', function() {
}
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;
helper.stopServer(done);
});
@ -308,6 +315,102 @@ describe('switch Node', function() {
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) {
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:[]}];
@ -691,15 +794,15 @@ describe('switch Node', function() {
});
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:"flow",type:"tab"}];
helper.load(switchNode, flow, function() {
initContext(function () {
var switchNode1 = helper.getNode("switchNode1");
var helperNode1 = helper.getNode("helperNode1");
switchNode1.context().flow.set(["payload","vt"],[-7,6],"memory",function(){
switchNode1.context().global.set("v2t",8,"memory",function(){
switchNode1.context().flow.set(["payload","vt"],[-7,6],"memory1",function(){
switchNode1.context().global.set("v2t",8,"memory1",function(){
helperNode1.on("input", function(msg) {
try {
should.equal(msg.payload,"pass");

View File

@ -119,23 +119,26 @@ describe('change Node', function() {
});
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:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
changeNode1.context().global.get("globalValue", "meomry", function (err, val) {
val.should.equal("changed");
done();
});
} catch(err) {
done(err);
}
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
changeNode1.context().global.get("globalValue", "memory1", function (err, val) {
val.should.equal("changed");
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("globalValue","changeMe","memory1", function (err) {
changeNode1.receive({payload:""});
});
});
changeNode1.context().global.set("globalValue","changeMe","memory");
changeNode1.receive({payload:""});
});
});
@ -344,21 +347,23 @@ describe('change Node', function() {
});
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:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("Hello World!");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("flowValue","Hello World!","memory",function(err) {
changeNode1.receive({payload:""});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("Hello World!");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("flowValue","Hello World!","memory1",function(err) {
changeNode1.receive({payload:""});
});
});
});
});
@ -383,21 +388,23 @@ describe('change Node', function() {
});
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:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("Hello World!");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("globalValue","Hello World!","memory", function (err) {
changeNode1.receive({payload:""});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("Hello World!");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("globalValue","Hello World!","memory1", function (err) {
changeNode1.receive({payload:""});
});
});
});
});
@ -564,20 +571,18 @@ 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"},
{id:"helperNode1", type:"helper", wires:[],"z":"flow"},{"id":"flow","type":"tab"}];
helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
changeNode1.context().flow.set("foo","bar");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("bar");
done();
} catch(err) {
done(err);
}
});
changeNode1.receive({payload:"Hello World!"});
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
changeNode1.context().flow.set("foo","bar");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("bar");
done();
} catch(err) {
done(err);
}
});
changeNode1.receive({payload:"Hello World!"});
});
});
@ -585,20 +590,18 @@ describe('change Node', function() {
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"}];
helper.load(changeNode, flow, function() {
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
changeNode1.context().global.set("foo","bar");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("bar");
done();
} catch(err) {
done(err);
}
});
changeNode1.receive({payload:"Hello World!"});
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
changeNode1.context().global.set("foo","bar");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.eql("bar");
done();
} catch(err) {
done(err);
}
});
changeNode1.receive({payload:"Hello World!"});
});
});
@ -896,21 +899,23 @@ describe('change Node', function() {
});
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:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("abc123abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("topic","ABC","memory", function (err) {
changeNode1.receive({payload:"abcABCabc"});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("abc123abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("topic","ABC","memory1", function (err) {
changeNode1.receive({payload:"abcABCabc"});
});
});
});
});
@ -935,21 +940,23 @@ describe('change Node', function() {
});
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:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("abc123abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("topic","ABC","memory",function (err) {
changeNode1.receive({payload:"abcABCabc"});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("abc123abc");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("topic","ABC","memory1",function (err) {
changeNode1.receive({payload:"abcABCabc"});
});
});
});
});
@ -974,21 +981,23 @@ describe('change Node', function() {
});
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:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("ABC");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("topic",123,"memory",function (err) {
changeNode1.receive({payload:123});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
msg.payload.should.equal("ABC");
done();
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("topic",123,"memory1",function (err) {
changeNode1.receive({payload:123});
});
});
});
});
@ -1085,23 +1094,25 @@ describe('change Node', function() {
});
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"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().global.get("payload","memory", function (err, val) {
val.should.equal("Goodbye World!");
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("payload","Hello World!","memory",function (err) {
changeNode1.receive({payload:""});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().global.get("payload","memory1", function (err, val) {
val.should.equal("Goodbye World!");
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("payload","Hello World!","memory1",function (err) {
changeNode1.receive({payload:""});
});
});
});
});
@ -1127,24 +1138,26 @@ describe('change Node', function() {
});
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"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload","memory",function (err, val) {
val.should.equal("Change456Me");
val.should.be.a.String();
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload","Change123Me","memory",function (err) {
changeNode1.receive({payload:""});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload","memory1",function (err, val) {
val.should.equal("Change456Me");
val.should.be.a.String();
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload","Change123Me","memory1",function (err) {
changeNode1.receive({payload:""});
});
});
});
});
@ -1170,22 +1183,26 @@ describe('change Node', function() {
});
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"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload").should.equal(456);
helperNode1.context().flow.get("payload").should.be.a.Number();
done();
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload","123","memory",function (err) {
changeNode1.receive({payload:""});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload","memory1",function (err, val) {
val.should.be.a.Number();
val.should.equal(456);
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload","123","memory1",function (err) {
changeNode1.receive({payload:""});
});
});
});
});
@ -1210,23 +1227,25 @@ describe('change Node', function() {
});
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"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload","memory",function (err, val) {
val.should.equal("abc");
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload",123,"memory",function (err) {
changeNode1.receive({payload:""});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload","memory1",function (err, val) {
val.should.equal("abc");
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload",123,"memory1",function (err) {
changeNode1.receive({payload:""});
});
});
});
});
@ -1251,23 +1270,25 @@ describe('change Node', function() {
});
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"}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload","memory",function (err, val) {
val.should.equal("abc");
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload",true,function (err) {
changeNode1.receive({payload:""});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
helperNode1.context().flow.get("payload","memory1",function (err, val) {
val.should.equal("abc");
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().flow.set("payload",true,"memory1",function (err) {
changeNode1.receive({payload:""});
});
});
});
});
@ -1358,23 +1379,25 @@ describe('change Node', function() {
});
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:[]}];
helper.load(changeNode, flow, function() {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
changeNode1.context().global.get("globalValue","memory",function(err,val) {
should.equal(undefined);
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("globalValue","Hello World!","memory",function (err) {
changeNode1.receive({payload:""});
initContext(function () {
var changeNode1 = helper.getNode("changeNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
changeNode1.context().global.get("globalValue","memory1",function(err,val) {
should.equal(undefined);
done();
});
} catch(err) {
done(err);
}
});
changeNode1.context().global.set("globalValue","Hello World!","memory1",function (err) {
changeNode1.receive({payload:""});
});
});
});
});