mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
add property choice to xml, sentiment nodes
add tests
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});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -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