mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Merge branch '0.18' into projects
This commit is contained in:
@@ -75,6 +75,28 @@ describe('sentiment Node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a positive score for good words - alternative property', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",property:"foo",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property('sentiment');
|
||||
msg.sentiment.should.have.property('score');
|
||||
msg.sentiment.score.should.be.a.Number();
|
||||
msg.sentiment.score.should.be.above(10);
|
||||
done();
|
||||
} catch(err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
var testString = 'good, great, best, brilliant';
|
||||
jn1.receive({foo:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a negative score for bad words', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
@@ -93,6 +115,24 @@ describe('sentiment Node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should add a negative score for bad words - alternative property', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",property:"foo",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
msg.should.have.property('sentiment');
|
||||
msg.sentiment.should.have.property('score');
|
||||
msg.sentiment.score.should.be.a.Number();
|
||||
msg.sentiment.score.should.be.below(-10);
|
||||
done();
|
||||
});
|
||||
var testString = 'bad, horrible, negative, awful';
|
||||
jn1.receive({foo:testString});
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow you to override word scoring', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
@@ -112,4 +152,23 @@ describe('sentiment Node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow you to override word scoring - alternative property', function(done) {
|
||||
var flow = [{id:"jn1",type:"sentiment",property:"foo",wires:[["jn2"]]},
|
||||
{id:"jn2", type:"helper"}];
|
||||
helper.load(sentimentNode, flow, function() {
|
||||
var jn1 = helper.getNode("jn1");
|
||||
var jn2 = helper.getNode("jn2");
|
||||
jn2.on("input", function(msg) {
|
||||
msg.should.have.property('sentiment');
|
||||
msg.sentiment.should.have.property('score');
|
||||
msg.sentiment.score.should.be.a.Number();
|
||||
msg.sentiment.score.should.equal(20);
|
||||
done();
|
||||
});
|
||||
var testString = 'sick, wicked';
|
||||
var overrides = {'sick': 10, 'wicked': 10 };
|
||||
jn1.receive({foo:testString,overrides:overrides});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -29,7 +29,7 @@ describe('switch Node', function() {
|
||||
afterEach(function(done) {
|
||||
helper.unload();
|
||||
helper.stopServer(done);
|
||||
RED.settings.switchMaxKeptMsgsCount = 0;
|
||||
RED.settings.nodeMessageBufferMaxLength = 0;
|
||||
});
|
||||
|
||||
it('should be loaded with some defaults', function(done) {
|
||||
@@ -692,7 +692,7 @@ describe('switch Node', function() {
|
||||
];
|
||||
helper.load(switchNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
RED.settings.switchMaxKeptMsgsCount = 2;
|
||||
RED.settings.nodeMessageBufferMaxLength = 2;
|
||||
setTimeout(function() {
|
||||
var logEvents = helper.log().args.filter(function (evt) {
|
||||
return evt[0].type == "switch";
|
||||
|
@@ -270,7 +270,7 @@ describe('JOIN node', function() {
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
RED.settings.joinMaxKeptMsgsCount = 0;
|
||||
RED.settings.nodeMessageBufferMaxLength = 0;
|
||||
});
|
||||
|
||||
it('should be loaded', function(done) {
|
||||
@@ -731,197 +731,6 @@ describe('JOIN node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge messages with topics (single)', function(done) {
|
||||
var flow = [{id:"n1", type:"join", mode:"merge",
|
||||
topics:[{topic:"TA"}, {topic:"TB"}],
|
||||
wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(joinNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var count = 0;
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property("TA");
|
||||
msg.should.have.property("TB");
|
||||
msg.should.have.property("payload");
|
||||
msg.payload.should.be.an.Array();
|
||||
msg.payload.length.should.equal(2);
|
||||
count++;
|
||||
if (count === 1) {
|
||||
msg.TA.should.equal("a");
|
||||
msg.TB.should.equal("b");
|
||||
msg.payload[0].should.equal("a");
|
||||
msg.payload[1].should.equal("b");
|
||||
}
|
||||
if (count === 2) {
|
||||
msg.TA.should.equal("d");
|
||||
msg.TB.should.equal("c");
|
||||
msg.payload[0].should.equal("d");
|
||||
msg.payload[1].should.equal("c");
|
||||
done();
|
||||
}
|
||||
}
|
||||
catch(e) { done(e); }
|
||||
});
|
||||
n1.receive({payload:"a", topic:"TA"});
|
||||
n1.receive({payload:"b", topic:"TB"});
|
||||
n1.receive({payload:"c", topic:"TB"});
|
||||
n1.receive({payload:"d", topic:"TA"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge messages with topics (multiple)', function(done) {
|
||||
var flow = [{id:"n1", type:"join", mode:"merge",
|
||||
topics:[{topic:"TA"}, {topic:"TB"}, {topic:"TA"}],
|
||||
wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(joinNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var count = 0;
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property("TA");
|
||||
msg.TA.should.be.an.Array();
|
||||
msg.TA.length.should.equal(2);
|
||||
msg.should.have.property("TB");
|
||||
msg.should.have.property("payload");
|
||||
msg.payload.should.be.an.Array();
|
||||
msg.payload.length.should.equal(3);
|
||||
count++;
|
||||
if (count === 1) {
|
||||
msg.TA[0].should.equal("a");
|
||||
msg.TA[1].should.equal("d");
|
||||
msg.TB.should.equal("b");
|
||||
msg.payload[0].should.equal("a");
|
||||
msg.payload[1].should.equal("b");
|
||||
msg.payload[2].should.equal("d");
|
||||
}
|
||||
if (count === 2) {
|
||||
msg.TA[0].should.equal("e");
|
||||
msg.TA[1].should.equal("f");
|
||||
msg.TB.should.equal("c");
|
||||
msg.payload[0].should.equal("e");
|
||||
msg.payload[1].should.equal("c");
|
||||
msg.payload[2].should.equal("f");
|
||||
done();
|
||||
}
|
||||
}
|
||||
catch(e) { done(e); }
|
||||
});
|
||||
n1.receive({payload:"a", topic:"TA"});
|
||||
n1.receive({payload:"b", topic:"TB"});
|
||||
n1.receive({payload:"c", topic:"TB"});
|
||||
n1.receive({payload:"d", topic:"TA"});
|
||||
n1.receive({payload:"e", topic:"TA"});
|
||||
n1.receive({payload:"f", topic:"TA"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge messages with topics (single, send on new topic)', function(done) {
|
||||
var flow = [{id:"n1", type:"join", mode:"merge",
|
||||
topics:[{topic:"TA"}, {topic:"TB"}],
|
||||
mergeOnChange:true,
|
||||
wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(joinNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var count = 0;
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property("TA");
|
||||
msg.should.have.property("TB");
|
||||
msg.should.have.property("payload");
|
||||
msg.payload.should.be.an.Array();
|
||||
msg.payload.length.should.equal(2);
|
||||
count++;
|
||||
if (count === 1) {
|
||||
msg.TA.should.equal("a");
|
||||
msg.TB.should.equal("b");
|
||||
msg.payload[0].should.equal("a");
|
||||
msg.payload[1].should.equal("b");
|
||||
}
|
||||
if (count === 2) {
|
||||
msg.TA.should.equal("a");
|
||||
msg.TB.should.equal("c");
|
||||
msg.payload[0].should.equal("a");
|
||||
msg.payload[1].should.equal("c");
|
||||
}
|
||||
if (count === 3) {
|
||||
msg.TA.should.equal("d");
|
||||
msg.TB.should.equal("c");
|
||||
msg.payload[0].should.equal("d");
|
||||
msg.payload[1].should.equal("c");
|
||||
done();
|
||||
}
|
||||
}
|
||||
catch(e) { done(e); }
|
||||
});
|
||||
n1.receive({payload:"a", topic:"TA"});
|
||||
n1.receive({payload:"b", topic:"TB"});
|
||||
n1.receive({payload:"c", topic:"TB"});
|
||||
n1.receive({payload:"d", topic:"TA"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge messages with topics (multiple, send on new topic)', function(done) {
|
||||
var flow = [{id:"n1", type:"join", mode:"merge",
|
||||
topics:[{topic:"TA"}, {topic:"TB"}, {topic:"TA"}],
|
||||
mergeOnChange:true,
|
||||
wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(joinNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var count = 0;
|
||||
n2.on("input", function(msg) {
|
||||
try {
|
||||
msg.should.have.property("TA");
|
||||
msg.TA.should.be.an.Array();
|
||||
msg.TA.length.should.equal(2);
|
||||
msg.should.have.property("TB");
|
||||
msg.should.have.property("payload");
|
||||
msg.payload.should.be.an.Array();
|
||||
msg.payload.length.should.equal(3);
|
||||
count++;
|
||||
if (count === 1) {
|
||||
msg.TA[0].should.equal("a");
|
||||
msg.TA[1].should.equal("c");
|
||||
msg.TB.should.equal("b");
|
||||
msg.payload[0].should.equal("a");
|
||||
msg.payload[1].should.equal("b");
|
||||
msg.payload[2].should.equal("c");
|
||||
}
|
||||
if (count === 2) {
|
||||
msg.TA[0].should.equal("c");
|
||||
msg.TA[1].should.equal("d");
|
||||
msg.TB.should.equal("b");
|
||||
msg.payload[0].should.equal("c");
|
||||
msg.payload[1].should.equal("b");
|
||||
msg.payload[2].should.equal("d");
|
||||
}
|
||||
if (count === 3) {
|
||||
msg.TA[0].should.equal("c");
|
||||
msg.TA[1].should.equal("d");
|
||||
msg.TB.should.equal("e");
|
||||
msg.payload[0].should.equal("c");
|
||||
msg.payload[1].should.equal("e");
|
||||
msg.payload[2].should.equal("d");
|
||||
done();
|
||||
}
|
||||
}
|
||||
catch(e) { done(e); }
|
||||
});
|
||||
n1.receive({payload:"a", topic:"TA"});
|
||||
n1.receive({payload:"b", topic:"TB"});
|
||||
n1.receive({payload:"c", topic:"TA"});
|
||||
n1.receive({payload:"d", topic:"TA"});
|
||||
n1.receive({payload:"e", topic:"TB"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should redece messages', function(done) {
|
||||
var flow = [{id:"n1", type:"join", mode:"reduce",
|
||||
reduceRight:false,
|
||||
@@ -1065,31 +874,6 @@ describe('JOIN node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle too many pending messages for merge mode', function(done) {
|
||||
var flow = [{id:"n1", type:"join", mode:"merge",
|
||||
topics:[{topic:"TA"}, {topic:"TA"}, {topic:"TB"}],
|
||||
wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(joinNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
RED.settings.joinMaxKeptMsgsCount = 2;
|
||||
setTimeout(function() {
|
||||
var logEvents = helper.log().args.filter(function (evt) {
|
||||
return evt[0].type == "join";
|
||||
});
|
||||
var evt = logEvents[0][0];
|
||||
evt.should.have.property('id', "n1");
|
||||
evt.should.have.property('type', "join");
|
||||
evt.should.have.property('msg', "join.too-many");
|
||||
done();
|
||||
}, 150);
|
||||
n1.receive({payload:"a", topic:"TA"});
|
||||
n1.receive({payload:"b", topic:"TB"});
|
||||
n1.receive({payload:"c", topic:"TB"});
|
||||
n1.receive({payload:"d", topic:"TA"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle too many pending messages for reduce mode', function(done) {
|
||||
var flow = [{id:"n1", type:"join", mode:"reduce",
|
||||
reduceRight:false,
|
||||
@@ -1101,7 +885,7 @@ describe('JOIN node', function() {
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(joinNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
RED.settings.joinMaxKeptMsgsCount = 2;
|
||||
RED.settings.nodeMessageBufferMaxLength = 2;
|
||||
setTimeout(function() {
|
||||
var logEvents = helper.log().args.filter(function (evt) {
|
||||
return evt[0].type == "join";
|
||||
|
@@ -27,7 +27,7 @@ describe('SORT node', function() {
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
RED.settings.maxKeptMsgsCount = 0;
|
||||
RED.settings.nodeMessageBufferMaxLength = 0;
|
||||
});
|
||||
|
||||
it('should be loaded', function(done) {
|
||||
@@ -254,7 +254,7 @@ describe('SORT node', function() {
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(sortNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
RED.settings.maxKeptMsgsCount = 2;
|
||||
RED.settings.nodeMessageBufferMaxLength = 2;
|
||||
setTimeout(function() {
|
||||
var logEvents = helper.log().args.filter(function (evt) {
|
||||
return evt[0].type == "sort";
|
||||
|
@@ -28,7 +28,7 @@ describe('BATCH node', function() {
|
||||
|
||||
afterEach(function() {
|
||||
helper.unload();
|
||||
RED.settings.batchMaxKeptMsgsCount = 0;
|
||||
RED.settings.nodeMessageBufferMaxLength = 0;
|
||||
});
|
||||
|
||||
it('should be loaded with defaults', function(done) {
|
||||
@@ -81,7 +81,7 @@ describe('BATCH node', function() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function check_count(flow, results, done) {
|
||||
try {
|
||||
helper.load(batchNode, flow, function() {
|
||||
@@ -106,13 +106,13 @@ describe('BATCH node', function() {
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function check_interval(flow, results, delay, done) {
|
||||
helper.load(batchNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
check_data(n1, n2, results, done);
|
||||
delayed_send(n1, 0, 4, delay);
|
||||
delayed_send(n1, 0, 4, delay);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ describe('BATCH node', function() {
|
||||
describe('mode: count', function() {
|
||||
|
||||
it('should create seq. with count', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "count", count: 2, overwrap: 0, interval: 10, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "count", count: 2, overlap: 0, interval: 10, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
var results = [
|
||||
[0, 1],
|
||||
@@ -153,9 +153,9 @@ describe('BATCH node', function() {
|
||||
];
|
||||
check_count(flow, results, done);
|
||||
});
|
||||
|
||||
it('should create seq. with count and overwrap', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "count", count: 3, overwrap: 2, interval: 10, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
|
||||
it('should create seq. with count and overlap', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "count", count: 3, overlap: 2, interval: 10, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
var results = [
|
||||
[0, 1, 2],
|
||||
@@ -165,14 +165,14 @@ describe('BATCH node', function() {
|
||||
];
|
||||
check_count(flow, results, done);
|
||||
});
|
||||
|
||||
|
||||
it('should handle too many pending messages', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "count", count: 5, overwrap: 0, interval: 10, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "count", count: 5, overlap: 0, interval: 10, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(batchNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
RED.settings.batchMaxKeptMsgsCount = 2;
|
||||
RED.settings.nodeMessageBufferMaxLength = 2;
|
||||
setTimeout(function() {
|
||||
var logEvents = helper.log().args.filter(function (evt) {
|
||||
return evt[0].type == "batch";
|
||||
@@ -190,11 +190,11 @@ describe('BATCH node', function() {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('mode: interval', function() {
|
||||
|
||||
|
||||
it('should create seq. with interval', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overwrap: 0, interval: 1, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
var results = [
|
||||
[0, 1],
|
||||
@@ -204,7 +204,7 @@ describe('BATCH node', function() {
|
||||
});
|
||||
|
||||
it('should create seq. with interval (in float)', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overwrap: 0, interval: 0.5, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overlap: 0, interval: 0.5, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
var results = [
|
||||
[0, 1],
|
||||
@@ -214,32 +214,32 @@ describe('BATCH node', function() {
|
||||
});
|
||||
|
||||
it('should create seq. with interval & not send empty seq', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overwrap: 0, interval: 1, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
var results = [
|
||||
// 1300, 2600, 3900, 5200,
|
||||
// 1300, 2600, 3900, 5200,
|
||||
[0], [1], [2], [3]
|
||||
];
|
||||
check_interval(flow, results, 1300, done);
|
||||
});
|
||||
|
||||
it('should create seq. with interval & send empty seq', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overwrap: 0, interval: 1, allowEmptySequence: true, topics: [], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overlap: 0, interval: 1, allowEmptySequence: true, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
var results = [
|
||||
// 1300, 2600, 3900, 5200,
|
||||
// 1300, 2600, 3900, 5200,
|
||||
[null], [0], [1], [2], [null], [3]
|
||||
];
|
||||
check_interval(flow, results, 1300, done);
|
||||
});
|
||||
|
||||
it('should handle too many pending messages', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overwrap: 0, interval: 1, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "interval", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(batchNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
RED.settings.batchMaxKeptMsgsCount = 2;
|
||||
RED.settings.nodeMessageBufferMaxLength = 2;
|
||||
setTimeout(function() {
|
||||
var logEvents = helper.log().args.filter(function (evt) {
|
||||
return evt[0].type == "batch";
|
||||
@@ -257,11 +257,11 @@ describe('BATCH node', function() {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('mode: concat', function() {
|
||||
|
||||
it('should concat two seq. (series)', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overwrap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
var results = [
|
||||
[2, 3, 0, 1]
|
||||
@@ -276,7 +276,7 @@ describe('BATCH node', function() {
|
||||
});
|
||||
|
||||
it('should concat two seq. (mixed)', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overwrap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
var results = [
|
||||
[2, 3, 0, 1]
|
||||
@@ -291,7 +291,7 @@ describe('BATCH node', function() {
|
||||
});
|
||||
|
||||
it('should concat three seq.', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overwrap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}, {topic: "TC"}], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}, {topic: "TC"}], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
var results = [
|
||||
[2, 3, 0, 1, 4]
|
||||
@@ -307,12 +307,12 @@ describe('BATCH node', function() {
|
||||
});
|
||||
|
||||
it('should handle too many pending messages', function(done) {
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overwrap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}], wires:[["n2"]]},
|
||||
var flow = [{id:"n1", type:"batch", name: "BatchNode", mode: "concat", count: 0, overlap: 0, interval: 1, allowEmptySequence: false, topics: [{topic: "TA"}, {topic: "TB"}], wires:[["n2"]]},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(batchNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
RED.settings.batchMaxKeptMsgsCount = 2;
|
||||
RED.settings.nodeMessageBufferMaxLength = 2;
|
||||
setTimeout(function() {
|
||||
var logEvents = helper.log().args.filter(function (evt) {
|
||||
return evt[0].type == "batch";
|
||||
|
@@ -57,6 +57,26 @@ describe('XML node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a valid xml string to a javascript object - alternative property', function(done) {
|
||||
var flow = [{id:"n1",type:"xml",property:"foo",wires:[["n2"]],func:"return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(xmlNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('topic', 'bar');
|
||||
msg.foo.should.have.property('employees');
|
||||
msg.foo.employees.should.have.property('firstName');
|
||||
should.equal(msg.foo.employees.firstName[0], 'John');
|
||||
msg.foo.employees.should.have.property('lastName');
|
||||
should.equal(msg.foo.employees.lastName[0], 'Smith');
|
||||
done();
|
||||
});
|
||||
var string = '<employees><firstName>John</firstName><lastName>Smith</lastName></employees>';
|
||||
n1.receive({foo:string,topic: "bar"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a valid xml string to a javascript object with options', function(done) {
|
||||
var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
@@ -94,20 +114,20 @@ describe('XML node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a javascript object to an xml string with options', function(done) {
|
||||
var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"},
|
||||
it('should convert a javascript object to an xml string with options - alternative property', function(done) {
|
||||
var flow = [{id:"n1",type:"xml",property:"foo",wires:[["n2"]],func:"return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
helper.load(xmlNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
n2.on("input", function(msg) {
|
||||
msg.should.have.property('topic', 'bar');
|
||||
var index = msg.payload.indexOf('<employees>\n <firstName>John</firstName>\n <lastName>Smith</lastName>\n</employees>');
|
||||
var index = msg.foo.indexOf('<employees>\n <firstName>John</firstName>\n <lastName>Smith</lastName>\n</employees>');
|
||||
index.should.be.above(-1);
|
||||
done();
|
||||
});
|
||||
var obj = {"employees":{"firstName":["John"],"lastName":["Smith"] }};
|
||||
n1.receive({payload:obj, topic:"bar", options:{headless:true}});
|
||||
n1.receive({foo:obj, topic:"bar", options:{headless:true}});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -133,7 +153,7 @@ describe('XML node', function() {
|
||||
},200);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should log an error if asked to parse something thats not xml or js', function(done) {
|
||||
var flow = [{id:"n1",type:"xml",wires:[["n2"]],func:"return msg;"},
|
||||
{id:"n2", type:"helper"}];
|
||||
|
@@ -55,6 +55,24 @@ describe('YAML node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a valid yaml string to a javascript object - using another property', function(done) {
|
||||
var flow = [{id:"yn1",type:"yaml",property:"foo",wires:[["yn2"]],func:"return msg;"},
|
||||
{id:"yn2", type:"helper"}];
|
||||
helper.load(yamlNode, flow, function() {
|
||||
var yn1 = helper.getNode("yn1");
|
||||
var yn2 = helper.getNode("yn2");
|
||||
yn2.on("input", function(msg) {
|
||||
msg.should.have.property('topic', 'bar');
|
||||
msg.foo.should.have.property('employees');
|
||||
msg.foo.employees[0].should.have.property('firstName', 'John');
|
||||
msg.foo.employees[0].should.have.property('lastName', 'Smith');
|
||||
done();
|
||||
});
|
||||
var yamlString = "employees:\n - firstName: John\n lastName: Smith\n";
|
||||
yn1.receive({foo:yamlString,topic: "bar"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a javascript object to a yaml string', function(done) {
|
||||
var flow = [{id:"yn1",type:"yaml",wires:[["yn2"]],func:"return msg;"},
|
||||
{id:"yn2", type:"helper"}];
|
||||
@@ -70,6 +88,21 @@ describe('YAML node', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert a javascript object to a yaml string - using another property', function(done) {
|
||||
var flow = [{id:"yn1",type:"yaml",property:"foo",wires:[["yn2"]],func:"return msg;"},
|
||||
{id:"yn2", type:"helper"}];
|
||||
helper.load(yamlNode, flow, function() {
|
||||
var yn1 = helper.getNode("yn1");
|
||||
var yn2 = helper.getNode("yn2");
|
||||
yn2.on("input", function(msg) {
|
||||
should.equal(msg.foo, "employees:\n - firstName: John\n lastName: Smith\n");
|
||||
done();
|
||||
});
|
||||
var obj = {employees:[{firstName:"John", lastName:"Smith"}]};
|
||||
yn1.receive({foo:obj});
|
||||
});
|
||||
});
|
||||
|
||||
it('should convert an array to a yaml string', function(done) {
|
||||
var flow = [{id:"yn1",type:"yaml",wires:[["yn2"]],func:"return msg;"},
|
||||
{id:"yn2", type:"helper"}];
|
||||
|
Reference in New Issue
Block a user