mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
lots of little node edits to clean up jsHint "errors"
This commit is contained in:
131
test/function/rbe/rbe_spec.js
Normal file
131
test/function/rbe/rbe_spec.js
Normal file
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Copyright 2015 IBM Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
var should = require("should");
|
||||
var helper = require('../../../test/helper.js');
|
||||
var testNode = require('../../../function/rbe/rbe.js');
|
||||
|
||||
describe('rbe node', function() {
|
||||
"use strict";
|
||||
|
||||
beforeEach(function(done) {
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
helper.unload().then(function() {
|
||||
helper.stopServer(done);
|
||||
});
|
||||
});
|
||||
|
||||
it("should be loaded with correct defaults", function(done) {
|
||||
var flow = [{"id":"n1", "type":"rbe", "name":"rbe1", "wires":[[]]}];
|
||||
helper.load(testNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
n1.should.have.property("name", "rbe1");
|
||||
n1.should.have.property("func", "rbe");
|
||||
n1.should.have.property("gap", 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should only send output if payload changes', function(done) {
|
||||
var flow = [{"id":"n1", "type":"rbe", func:"rbe", gap:0, wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(testNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var c = 0;
|
||||
n2.on("input", function(msg) {
|
||||
if (c === 0) {
|
||||
msg.should.have.a.property("payload", "a");
|
||||
c+=1;
|
||||
}
|
||||
else {
|
||||
msg.should.have.a.property("payload", "b");
|
||||
done();
|
||||
}
|
||||
});
|
||||
n1.emit("input", {payload:"a"});
|
||||
n1.emit("input", {payload:"a"});
|
||||
n1.emit("input", {payload:"a"});
|
||||
n1.emit("input", {payload:"a"});
|
||||
n1.emit("input", {payload:"a"});
|
||||
n1.emit("input", {payload:"b"});
|
||||
n1.emit("input", {payload:"b"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should only send output if more than x away from original value', function(done) {
|
||||
var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:10, wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(testNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var c = 0;
|
||||
n2.on("input", function(msg) {
|
||||
if (c === 0) {
|
||||
msg.should.have.a.property("payload", 0);
|
||||
}
|
||||
else if (c === 1) {
|
||||
msg.should.have.a.property("payload", 20);
|
||||
}
|
||||
else {
|
||||
msg.should.have.a.property("payload", "5 deg");
|
||||
done();
|
||||
}
|
||||
c += 1;
|
||||
});
|
||||
n1.emit("input", {payload:0});
|
||||
n1.emit("input", {payload:2});
|
||||
n1.emit("input", {payload:4});
|
||||
n1.emit("input", {payload:"6 deg"});
|
||||
n1.emit("input", {payload:8});
|
||||
n1.emit("input", {payload:20});
|
||||
n1.emit("input", {payload:15});
|
||||
n1.emit("input", {payload:"5 deg"});
|
||||
});
|
||||
});
|
||||
|
||||
it('should warn if no number found in gap mode', function(done) {
|
||||
var flow = [{"id":"n1", "type":"rbe", func:"gap", gap:10, wires:[["n2"]] },
|
||||
{id:"n2", type:"helper"} ];
|
||||
helper.load(testNode, flow, function() {
|
||||
var n1 = helper.getNode("n1");
|
||||
var n2 = helper.getNode("n2");
|
||||
var c = 0;
|
||||
n2.on("input", function(msg) {
|
||||
c += 1;
|
||||
});
|
||||
setTimeout( function() {
|
||||
c.should.equal(0);
|
||||
helper.log().called.should.be.true;
|
||||
var logEvents = helper.log().args.filter(function (evt) {
|
||||
return evt[0].type == "rbe";
|
||||
});
|
||||
logEvents.should.have.length(1);
|
||||
var msg = logEvents[0][0];
|
||||
msg.should.have.property('level', helper.log().WARN);
|
||||
msg.should.have.property('id', 'n1');
|
||||
msg.should.have.property('type', 'rbe');
|
||||
msg.should.have.property('msg', 'no number found in payload');
|
||||
done();
|
||||
},50);
|
||||
n1.emit("input", {payload:"banana"});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
@@ -605,179 +605,178 @@ describe('pushbullet node', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('tickle', function() {
|
||||
it('note', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
describe('tickle', function() {
|
||||
it('note', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "note");
|
||||
msg.should.have.property("payload", "body");
|
||||
msg.should.have.property("topic", "title");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('note'));
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "note");
|
||||
msg.should.have.property("payload", "body");
|
||||
msg.should.have.property("topic", "title");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('note'));
|
||||
});
|
||||
});
|
||||
|
||||
it('link', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
it('link', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "link");
|
||||
msg.should.have.property("payload", "url");
|
||||
msg.should.have.property("topic", "title");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('link'));
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "link");
|
||||
msg.should.have.property("payload", "url");
|
||||
msg.should.have.property("topic", "title");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('link'));
|
||||
});
|
||||
});
|
||||
|
||||
it('address', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
it('address', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "address");
|
||||
msg.should.have.property("payload", "address");
|
||||
msg.should.have.property("topic", "title");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('address'));
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "address");
|
||||
msg.should.have.property("payload", "address");
|
||||
msg.should.have.property("topic", "title");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('address'));
|
||||
});
|
||||
});
|
||||
|
||||
it('file', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
it('file', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "file");
|
||||
msg.should.have.property("payload", "fileurl");
|
||||
msg.should.have.property("topic", "filename");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('file'));
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "file");
|
||||
msg.should.have.property("payload", "fileurl");
|
||||
msg.should.have.property("topic", "filename");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('file'));
|
||||
});
|
||||
});
|
||||
|
||||
it('list', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
it('list', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "list");
|
||||
msg.should.have.property("topic", "title");
|
||||
msg.should.have.property("payload").with.length(3);
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('list'));
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "list");
|
||||
msg.should.have.property("topic", "title");
|
||||
msg.should.have.property("payload").with.length(3);
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('list'));
|
||||
});
|
||||
});
|
||||
|
||||
it('delete', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
it('delete', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "delete");
|
||||
msg.should.have.property("payload", "pjgzwwocCCy");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('delete'));
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "delete");
|
||||
msg.should.have.property("payload", "pjgzwwocCCy");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
func.yields(false, getPushReply('delete'));
|
||||
});
|
||||
});
|
||||
|
||||
it('dismissed', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
it('dismissed', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "dismissal");
|
||||
msg.should.have.property("payload", "xXxXxXxXxXxsjArqXRsaZM");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var rep = getPushReply('note');
|
||||
rep.pushes[0].dismissed = true;
|
||||
func.yields(false, rep);
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
msg.should.have.property("pushtype", "dismissal");
|
||||
msg.should.have.property("payload", "xXxXxXxXxXxsjArqXRsaZM");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var rep = getPushReply('note');
|
||||
rep.pushes[0].dismissed = true;
|
||||
func.yields(false, rep);
|
||||
});
|
||||
});
|
||||
|
||||
it('filter', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
it('filter', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet in", config: "n1", wires: [["n3"]]},
|
||||
{id:"n3", type:"helper"}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2:{filters:['a', 'b']}}, function() {
|
||||
var counter = sinon.spy();
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
counter();
|
||||
});
|
||||
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var msg0 = getPushReply('link'); msg0.pushes[0].source_device_iden = 'a';
|
||||
func.onCall(0).yields(false, msg0);
|
||||
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var msg1 = getPushReply('link'); msg1.pushes[0].source_device_iden = 'b';
|
||||
func.onCall(1).yields(false, msg1);
|
||||
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var msg2 = getPushReply('link'); msg2.pushes[0].source_device_iden = 'c';
|
||||
func.onCall(2).yields(false, msg2);
|
||||
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var msg3 = getPushReply('link');
|
||||
delete msg3.pushes[0].source_device_iden;
|
||||
delete msg3.pushes[0].target_device_iden;
|
||||
func.onCall(3).yields(false, msg3);
|
||||
|
||||
setTimeout(function() {
|
||||
counter.callCount.should.equal(3);
|
||||
done();
|
||||
}, 100);
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2:{filters:['a', 'b']}}, function() {
|
||||
var counter = sinon.spy();
|
||||
helper.getNode("n3").on("input", function(msg) {
|
||||
counter();
|
||||
});
|
||||
});
|
||||
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var msg0 = getPushReply('link'); msg0.pushes[0].source_device_iden = 'a';
|
||||
func.onCall(0).yields(false, msg0);
|
||||
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var msg1 = getPushReply('link'); msg1.pushes[0].source_device_iden = 'b';
|
||||
func.onCall(1).yields(false, msg1);
|
||||
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var msg2 = getPushReply('link'); msg2.pushes[0].source_device_iden = 'c';
|
||||
func.onCall(2).yields(false, msg2);
|
||||
|
||||
currentPB.streamEmitter.emit("message", {type: "tickle", subtype: "push"});
|
||||
var msg3 = getPushReply('link');
|
||||
delete msg3.pushes[0].source_device_iden;
|
||||
delete msg3.pushes[0].target_device_iden;
|
||||
func.onCall(3).yields(false, msg3);
|
||||
|
||||
setTimeout(function() {
|
||||
counter.callCount.should.equal(3);
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user