Merge pull request #2226 from node-red/add-has_key-to-switch

Add "has key" rule to  switch node + tests
This commit is contained in:
Nick O'Leary
2019-07-30 23:06:44 +01:00
committed by GitHub
4 changed files with 39 additions and 4 deletions

View File

@@ -254,6 +254,16 @@ describe('switch Node', function() {
genericSwitchTest("gte", 3, true, true, 3, done);
});
it('should match if a payload has a required property', function(done) {
genericSwitchTest("hask", "a", true, true, {a:1}, done);
});
it('should not match if a payload does not have a required property', function(done) {
genericSwitchTest("hask", "a", true, false, {b:1}, done);
});
it('should not match if the key is not a string', function(done) {
genericSwitchTest("hask", 1, true, false, {a:1}, done);
});
it('should check if payload is between given values', function(done) {
twoFieldSwitchTest("btwn", "3", "5", true, true, 4, done);
});
@@ -519,7 +529,6 @@ describe('switch Node', function() {
singularSwitchTest("nempty", true, false, 0, done);
});
it('should check input against a previous value', function(done) {
var flow = [{id:"switchNode1",type:"switch",name:"switchNode",property:"payload",rules:[{ "t": "gt", "v": "", "vt": "prev" }],checkall:true,outputs:1,wires:[["helperNode1"]]},
{id:"helperNode1", type:"helper", wires:[]}];