mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
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:
@@ -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:[]}];
|
||||
|
Reference in New Issue
Block a user