Allow nested msg properties in msg/flow/global expressions (#2822)

* Allow nested msg properties in msg/flow/global expressions

* Remove typo in RED.utils

Co-authored-by: Nick O'Leary <knolleary@users.noreply.github.com>
This commit is contained in:
Nick O'Leary
2021-01-27 20:32:52 +00:00
committed by GitHub
parent 34ef055d7b
commit 438d51d26e
6 changed files with 342 additions and 31 deletions

View File

@@ -119,13 +119,17 @@ describe('switch Node', function() {
* @param done - callback when done
*/
function customFlowSwitchTest(flow, shouldReceive, sendPayload, done) {
customFlowMessageSwitchTest(flow,shouldReceive,{payload: sendPayload}, done);
}
function customFlowMessageSwitchTest(flow, shouldReceive, message, done) {
helper.load(switchNode, flow, function() {
var switchNode1 = helper.getNode("switchNode1");
var helperNode1 = helper.getNode("helperNode1");
helperNode1.on("input", function(msg) {
try {
if (shouldReceive === true) {
should.equal(msg.payload,sendPayload);
should.equal(msg,message);
done();
} else {
should.fail(null, null, "We should never get an input!");
@@ -134,7 +138,7 @@ describe('switch Node', function() {
done(err);
}
});
switchNode1.receive({payload:sendPayload});
switchNode1.receive(message);
if (shouldReceive === false) {
setTimeout(function() {
done();
@@ -425,6 +429,29 @@ describe('switch Node', function() {
});
});
it('should use a nested message property to compare value - matches', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload[msg.topic]",rules:[{"t":"eq","v":"bar"}],checkall:true,outputs:1,wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
customFlowMessageSwitchTest(flow, true, {topic:"foo",payload:{"foo":"bar"}}, done);
})
it('should use a nested message property to compare value - no match', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload[msg.topic]",rules:[{"t":"eq","v":"bar"}],checkall:true,outputs:1,wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
customFlowMessageSwitchTest(flow, false, {topic:"foo",payload:{"foo":"none"}}, done);
})
it('should use a nested message property to compare nested message property - matches', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload[msg.topic]",rules:[{"t":"eq","v":"payload[msg.topic2]",vt:"msg"}],checkall:true,outputs:1,wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
customFlowMessageSwitchTest(flow, true, {topic:"foo",topic2:"foo2",payload:{"foo":"bar","foo2":"bar"}}, done);
})
it('should use a nested message property to compare nested message property - no match', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload[msg.topic]",rules:[{"t":"eq","v":"payload[msg.topic2]",vt:"msg"}],checkall:true,outputs:1,wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];
customFlowMessageSwitchTest(flow, false, {topic:"foo",topic2:"foo2",payload:{"foo":"bar","foo2":"none"}}, 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"]]},
{id:"helperNode1", type:"helper", wires:[]}];