mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
update unit tests
This commit is contained in:
parent
46ace77cf4
commit
a185264244
@ -12,10 +12,6 @@ module.exports = function (RED) {
|
|||||||
this.on("input", function (msg) {
|
this.on("input", function (msg) {
|
||||||
var value = RED.util.getMessageProperty(msg, node.property);
|
var value = RED.util.getMessageProperty(msg, node.property);
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
if (msg.hasOwnProperty("overrides")) {
|
|
||||||
msg.extras = msg.overrides;
|
|
||||||
delete msg.overrides;
|
|
||||||
}
|
|
||||||
multilangSentiment(value, node.lang || msg.lang || 'en', { 'words': msg.words || null, 'tokens': msg.tokens || null }, function (err, result) {
|
multilangSentiment(value, node.lang || msg.lang || 'en', { 'words': msg.words || null, 'tokens': msg.tokens || null }, function (err, result) {
|
||||||
msg.sentiment = result;
|
msg.sentiment = result;
|
||||||
msg.sentiment.comparative = msg.sentiment.score / msg.sentiment.tokens.length; // temporarily addresses an issue in v2.0.0: https://github.com/marcellobarile/multilang-sentiment/issues/10
|
msg.sentiment.comparative = msg.sentiment.score / msg.sentiment.tokens.length; // temporarily addresses an issue in v2.0.0: https://github.com/marcellobarile/multilang-sentiment/issues/10
|
||||||
|
@ -173,8 +173,8 @@ describe('mlsentiment Node', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
var testString = 'sick, wicked';
|
var testString = 'sick, wicked';
|
||||||
var overrides = {'sick': 10, 'wicked': 10 };
|
var wordOverrides = { 'sick': 10, 'wicked': 10 };
|
||||||
jn1.receive({payload:testString,overrides:overrides});
|
jn1.receive({ payload: testString, words: wordOverrides });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -192,8 +192,46 @@ describe('mlsentiment Node', function() {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
var testString = 'sick, wicked';
|
var testString = 'sick, wicked';
|
||||||
var overrides = {'sick': 10, 'wicked': 10 };
|
var wordOverrides = { 'sick': 10, 'wicked': 10 };
|
||||||
jn1.receive({foo:testString,overrides:overrides});
|
jn1.receive({ foo: testString, words: wordOverrides });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow you to use custom tokens', function (done) {
|
||||||
|
var flow = [{ id: "jn1", type: "mlsentiment", 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(-3);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
var testString = '世界就是一个疯子的囚笼';
|
||||||
|
var tokenOverrides = ['世界', '就', '是', '一个', '疯子', '的', '囚笼'];
|
||||||
|
jn1.receive({ payload: testString, tokens: tokenOverrides });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow you to use custom tokens - alternative property', function (done) {
|
||||||
|
var flow = [{ id: "jn1", type: "mlsentiment", 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(-3);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
var testString = '世界就是一个疯子的囚笼';
|
||||||
|
var tokenOverrides = ['世界', '就', '是', '一个', '疯子', '的', '囚笼'];
|
||||||
|
jn1.receive({ foo: testString, tokens: tokenOverrides });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user