From 6f5974f87571c06d0624d8799bd95370381c9571 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Thu, 14 Jun 2018 20:00:42 +0100 Subject: [PATCH] Fix join node manual mode array msg.complete was adding an unwanted null to the array (if no payload) Added tests for msg.complete with array and object --- nodes/core/logic/17-split.js | 7 ++- test/nodes/core/logic/17-split_spec.js | 63 +++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/nodes/core/logic/17-split.js b/nodes/core/logic/17-split.js index 92b527d01..75ac7a4ce 100644 --- a/nodes/core/logic/17-split.js +++ b/nodes/core/logic/17-split.js @@ -619,10 +619,13 @@ module.exports = function(RED) { } else { if (!isNaN(propertyIndex)) { group.payload[propertyIndex] = property; + group.currentCount++; } else { - group.payload.push(property); + if (property !== undefined) { + group.payload.push(property); + group.currentCount++; + } } - group.currentCount++; } // TODO: currently reuse the last received - add option to pick first received group.msg = msg; diff --git a/test/nodes/core/logic/17-split_spec.js b/test/nodes/core/logic/17-split_spec.js index 9fed82cd4..70ea9b26e 100644 --- a/test/nodes/core/logic/17-split_spec.js +++ b/test/nodes/core/logic/17-split_spec.js @@ -818,6 +818,57 @@ describe('JOIN node', function() { }); }); + it('should manually join things into an array, send when told complete', function(done) { + var flow = [{id:"n1", type:"join", wires:[["n2"]], timeout:1, mode:"custom", build:"array"}, + {id:"n2", type:"helper"}]; + helper.load(joinNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n2.on("input", function(msg) { + try { + msg.should.have.property("payload"); + msg.payload.should.be.an.Array(); + msg.payload.length.should.equal(3); + msg.payload[0].should.equal(1); + msg.payload[1].should.equal(2); + msg.payload[2].should.equal(3); + done(); + } + catch(e) { done(e); } + }); + n1.receive({payload:1, topic:"A"}); + n1.receive({payload:2, topic:"B"}); + n1.receive({payload:3, topic:"C"}); + n1.receive({complete:true}); + }); + }); + + + it('should manually join things into an object, send when told complete', function(done) { + var flow = [{id:"n1", type:"join", wires:[["n2"]], timeout:1, mode:"custom", build:"object"}, + {id:"n2", type:"helper"}]; + helper.load(joinNode, flow, function() { + var n1 = helper.getNode("n1"); + var n2 = helper.getNode("n2"); + n2.on("input", function(msg) { + try { + msg.should.have.property("payload"); + msg.payload.should.be.an.Object(); + Object.keys(msg.payload).length.should.equal(3); + msg.payload.A.should.equal(1); + msg.payload.B.should.equal(2); + msg.payload.C.should.equal(3); + done(); + } + catch(e) { done(e); } + }); + n1.receive({payload:1, topic:"A"}); + n1.receive({payload:2, topic:"B"}); + n1.receive({payload:3, topic:"C"}); + n1.receive({complete:true}); + }); + }); + it('should join split strings back into a word', function(done) { var flow = [{id:"n1", type:"join", mode:"auto", wires:[["n2"]]}, {id:"n2", type:"helper"}]; @@ -861,7 +912,7 @@ describe('JOIN node', function() { }); }); - it('should redece messages', function(done) { + it('should reduce messages', function(done) { var flow = [{id:"n1", type:"join", mode:"reduce", reduceRight:false, reduceExp:"$A+payload", @@ -889,7 +940,7 @@ describe('JOIN node', function() { }); }); - it('should redece messages using $I', function(done) { + it('should reduce messages using $I', function(done) { var flow = [{id:"n1", type:"join", mode:"reduce", reduceRight:false, reduceExp:"$A+$I", @@ -917,7 +968,7 @@ describe('JOIN node', function() { }); }); - it('should redece messages with fixup', function(done) { + it('should reduce messages with fixup', function(done) { var flow = [{id:"n1", type:"join", mode:"reduce", reduceRight:false, reduceExp:"$A+payload", @@ -946,7 +997,7 @@ describe('JOIN node', function() { }); }); - it('should redece messages (left)', function(done) { + it('should reduce messages (left)', function(done) { var flow = [{id:"n1", type:"join", mode:"reduce", reduceRight:false, reduceExp:"'(' & $A & '+' & payload & ')'", @@ -975,7 +1026,7 @@ describe('JOIN node', function() { }); }); - it('should redece messages (right)', function(done) { + it('should reduce messages (right)', function(done) { var flow = [{id:"n1", type:"join", mode:"reduce", reduceRight:true, reduceExp:"'(' & $A & '+' & payload & ')'", @@ -1004,7 +1055,7 @@ describe('JOIN node', function() { }); }); - it('should redece messages with array result', function(done) { + it('should reduce messages with array result', function(done) { var flow = [{id:"n1", type:"join", mode:"reduce", reduceRight:false, reduceExp:"$append($A,[payload])",