1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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
This commit is contained in:
Dave Conway-Jones 2018-06-14 20:00:42 +01:00
parent fef71f29c4
commit 6f5974f875
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 62 additions and 8 deletions

View File

@ -619,10 +619,13 @@ module.exports = function(RED) {
} else { } else {
if (!isNaN(propertyIndex)) { if (!isNaN(propertyIndex)) {
group.payload[propertyIndex] = property; group.payload[propertyIndex] = property;
} else {
group.payload.push(property);
}
group.currentCount++; group.currentCount++;
} else {
if (property !== undefined) {
group.payload.push(property);
group.currentCount++;
}
}
} }
// TODO: currently reuse the last received - add option to pick first received // TODO: currently reuse the last received - add option to pick first received
group.msg = msg; group.msg = msg;

View File

@ -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) { it('should join split strings back into a word', function(done) {
var flow = [{id:"n1", type:"join", mode:"auto", wires:[["n2"]]}, var flow = [{id:"n1", type:"join", mode:"auto", wires:[["n2"]]},
{id:"n2", type:"helper"}]; {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", var flow = [{id:"n1", type:"join", mode:"reduce",
reduceRight:false, reduceRight:false,
reduceExp:"$A+payload", 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", var flow = [{id:"n1", type:"join", mode:"reduce",
reduceRight:false, reduceRight:false,
reduceExp:"$A+$I", 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", var flow = [{id:"n1", type:"join", mode:"reduce",
reduceRight:false, reduceRight:false,
reduceExp:"$A+payload", 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", var flow = [{id:"n1", type:"join", mode:"reduce",
reduceRight:false, reduceRight:false,
reduceExp:"'(' & $A & '+' & payload & ')'", 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", var flow = [{id:"n1", type:"join", mode:"reduce",
reduceRight:true, reduceRight:true,
reduceExp:"'(' & $A & '+' & payload & ')'", 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", var flow = [{id:"n1", type:"join", mode:"reduce",
reduceRight:false, reduceRight:false,
reduceExp:"$append($A,[payload])", reduceExp:"$append($A,[payload])",