mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix wrong test cases
This commit is contained in:
parent
bd5e8ba961
commit
6fc863a91e
@ -343,6 +343,7 @@ describe('switch Node', function() {
|
||||
"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) {
|
||||
@ -360,6 +361,7 @@ describe('switch Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle global context', function (done) {
|
||||
var flow = [{"id": "switchNode1", "type": "switch", "property": "foo", "propertyType": "global",
|
||||
@ -389,6 +391,7 @@ describe('switch Node', function() {
|
||||
"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) {
|
||||
@ -406,6 +409,7 @@ describe('switch Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"]]},
|
||||
@ -790,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");
|
||||
|
@ -122,11 +122,12 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(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) {
|
||||
changeNode1.context().global.get("globalValue", "memory1", function (err, val) {
|
||||
val.should.equal("changed");
|
||||
done();
|
||||
});
|
||||
@ -134,10 +135,12 @@ describe('change Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.context().global.set("globalValue","changeMe","memory1");
|
||||
changeNode1.context().global.set("globalValue","changeMe","memory1", function (err) {
|
||||
changeNode1.receive({payload:""});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"]]},
|
||||
@ -347,6 +350,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -362,6 +366,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"]]},
|
||||
@ -386,6 +391,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -401,6 +407,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"]]},
|
||||
@ -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"},
|
||||
{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");
|
||||
@ -579,13 +585,11 @@ describe('change Node', function() {
|
||||
changeNode1.receive({payload:"Hello World!"});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"},
|
||||
{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");
|
||||
@ -600,7 +604,6 @@ describe('change Node', function() {
|
||||
changeNode1.receive({payload:"Hello World!"});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"},
|
||||
@ -899,6 +902,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -914,6 +918,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"]]},
|
||||
@ -938,6 +943,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -953,6 +959,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"]]},
|
||||
@ -977,6 +984,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -992,6 +1000,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"]]},
|
||||
@ -1088,6 +1097,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -1105,6 +1115,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"},
|
||||
@ -1130,6 +1141,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -1148,6 +1160,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"},
|
||||
@ -1173,13 +1186,16 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(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();
|
||||
helperNode1.context().flow.get("payload","memory1",function (err, val) {
|
||||
val.should.be.a.Number();
|
||||
val.should.equal(456);
|
||||
done();
|
||||
});
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
@ -1189,6 +1205,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"},
|
||||
@ -1213,6 +1230,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -1230,6 +1248,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"},
|
||||
@ -1254,6 +1273,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -1266,11 +1286,12 @@ describe('change Node', function() {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
changeNode1.context().flow.set("payload",true,function (err) {
|
||||
changeNode1.context().flow.set("payload",true,"memory1",function (err) {
|
||||
changeNode1.receive({payload:""});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('env var', function() {
|
||||
before(function() {
|
||||
@ -1342,6 +1363,7 @@ describe('change Node', function() {
|
||||
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() {
|
||||
initContext(function () {
|
||||
var changeNode1 = helper.getNode("changeNode1");
|
||||
var helperNode1 = helper.getNode("helperNode1");
|
||||
helperNode1.on("input", function(msg) {
|
||||
@ -1359,6 +1381,7 @@ describe('change Node', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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"]]},
|
||||
|
Loading…
Reference in New Issue
Block a user