mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add test case of persistalbe context for switch node
This commit is contained in:
parent
8663ec6880
commit
bd5e8ba961
@ -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,98 @@ 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 () {
|
||||
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 () {
|
||||
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:[]}];
|
||||
|
@ -119,7 +119,7 @@ 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");
|
||||
@ -134,7 +134,7 @@ describe('change Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.context().global.set("globalValue","changeMe","memory");
|
||||
changeNode1.context().global.set("globalValue","changeMe","memory1");
|
||||
changeNode1.receive({payload:""});
|
||||
});
|
||||
});
|
||||
@ -344,7 +344,7 @@ 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");
|
||||
@ -357,7 +357,7 @@ describe('change Node', function() {
|
||||
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:""});
|
||||
});
|
||||
});
|
||||
@ -383,7 +383,7 @@ 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");
|
||||
@ -396,7 +396,7 @@ describe('change Node', function() {
|
||||
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:""});
|
||||
});
|
||||
});
|
||||
@ -896,7 +896,7 @@ 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");
|
||||
@ -909,7 +909,7 @@ describe('change Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.context().flow.set("topic","ABC","memory", function (err) {
|
||||
changeNode1.context().flow.set("topic","ABC","memory1", function (err) {
|
||||
changeNode1.receive({payload:"abcABCabc"});
|
||||
});
|
||||
});
|
||||
@ -935,7 +935,7 @@ 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");
|
||||
@ -948,7 +948,7 @@ describe('change Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.context().global.set("topic","ABC","memory",function (err) {
|
||||
changeNode1.context().global.set("topic","ABC","memory1",function (err) {
|
||||
changeNode1.receive({payload:"abcABCabc"});
|
||||
});
|
||||
});
|
||||
@ -974,7 +974,7 @@ 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");
|
||||
@ -987,7 +987,7 @@ describe('change Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.context().global.set("topic",123,"memory",function (err) {
|
||||
changeNode1.context().global.set("topic",123,"memory1",function (err) {
|
||||
changeNode1.receive({payload:123});
|
||||
});
|
||||
});
|
||||
@ -1085,14 +1085,14 @@ 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) {
|
||||
helperNode1.context().global.get("payload","memory1", function (err, val) {
|
||||
val.should.equal("Goodbye World!");
|
||||
done();
|
||||
});
|
||||
@ -1100,7 +1100,7 @@ describe('change Node', function() {
|
||||
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:""});
|
||||
});
|
||||
});
|
||||
@ -1127,14 +1127,14 @@ 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) {
|
||||
helperNode1.context().flow.get("payload","memory1",function (err, val) {
|
||||
val.should.equal("Change456Me");
|
||||
val.should.be.a.String();
|
||||
done();
|
||||
@ -1143,7 +1143,7 @@ describe('change Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.context().flow.set("payload","Change123Me","memory",function (err) {
|
||||
changeNode1.context().flow.set("payload","Change123Me","memory1",function (err) {
|
||||
changeNode1.receive({payload:""});
|
||||
});
|
||||
});
|
||||
@ -1170,7 +1170,7 @@ 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");
|
||||
@ -1184,7 +1184,7 @@ describe('change Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.context().flow.set("payload","123","memory",function (err) {
|
||||
changeNode1.context().flow.set("payload","123","memory1",function (err) {
|
||||
changeNode1.receive({payload:""});
|
||||
});
|
||||
});
|
||||
@ -1210,14 +1210,14 @@ 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) {
|
||||
helperNode1.context().flow.get("payload","memory1",function (err, val) {
|
||||
val.should.equal("abc");
|
||||
done();
|
||||
});
|
||||
@ -1225,7 +1225,7 @@ describe('change Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.context().flow.set("payload",123,"memory",function (err) {
|
||||
changeNode1.context().flow.set("payload",123,"memory1",function (err) {
|
||||
changeNode1.receive({payload:""});
|
||||
});
|
||||
});
|
||||
@ -1251,14 +1251,14 @@ 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) {
|
||||
helperNode1.context().flow.get("payload","memory1",function (err, val) {
|
||||
val.should.equal("abc");
|
||||
done();
|
||||
});
|
||||
@ -1339,14 +1339,14 @@ 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) {
|
||||
changeNode1.context().global.get("globalValue","memory1",function(err,val) {
|
||||
should.equal(undefined);
|
||||
done();
|
||||
});
|
||||
@ -1354,7 +1354,7 @@ describe('change Node', function() {
|
||||
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:""});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user