From b763e0b0cb0200bc4eaf0a5af50351e615499716 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Wed, 2 Oct 2019 09:52:26 +0100 Subject: [PATCH] Let switch node between rule work both ways round and add test --- .../node_modules/@node-red/nodes/core/function/10-switch.js | 2 +- test/nodes/core/function/10-switch_spec.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/function/10-switch.js b/packages/node_modules/@node-red/nodes/core/function/10-switch.js index 296851e14..1761853a6 100644 --- a/packages/node_modules/@node-red/nodes/core/function/10-switch.js +++ b/packages/node_modules/@node-red/nodes/core/function/10-switch.js @@ -24,7 +24,7 @@ module.exports = function(RED) { 'lte': function(a, b) { return a <= b; }, 'gt': function(a, b) { return a > b; }, 'gte': function(a, b) { return a >= b; }, - 'btwn': function(a, b, c) { return a >= b && a <= c; }, + 'btwn': function(a, b, c) { return (a >= b && a <= c) || (a <= b && a >= c); }, 'cont': function(a, b) { return (a + "").indexOf(b) != -1; }, 'regex': function(a, b, c, d) { return (a + "").match(new RegExp(b,d?'i':'')); }, 'true': function(a) { return a === true; }, diff --git a/test/nodes/core/function/10-switch_spec.js b/test/nodes/core/function/10-switch_spec.js index 3865bdb99..b431fcaaf 100644 --- a/test/nodes/core/function/10-switch_spec.js +++ b/test/nodes/core/function/10-switch_spec.js @@ -268,6 +268,10 @@ describe('switch Node', function() { twoFieldSwitchTest("btwn", "3", "5", true, true, 4, done); }); + it('should check if payload is between given values in "wrong" order', function(done) { + twoFieldSwitchTest("btwn", "5", "3", true, true, 4, done); + }); + it('should check if payload is between given string values', function(done) { twoFieldSwitchTest("btwn", "c", "e", true, true, "d", done); }); @@ -585,7 +589,7 @@ describe('switch Node', function() { done(err); } } else { - done(); + //done(); } }); switchNode1.receive({payload:0});