mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Merge pull request #95 from dsundberg/pushbullet-enhance
Thanks @dsundberg. Updated pushbullet node with all push types, added new "pushbullet in" t...
This commit is contained in:
779
test/social/pushbullet/57-pushbullet_spec.js
Normal file
779
test/social/pushbullet/57-pushbullet_spec.js
Normal file
@@ -0,0 +1,779 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
/*jshint expr: true*/
|
||||
|
||||
var sinon = require('sinon');
|
||||
var should = require("should");
|
||||
var proxyquire = require("proxyquire");
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
var data = require("./data");
|
||||
var path = require("path");
|
||||
|
||||
// Mute "Starting/Stopping flows to stdout"
|
||||
var util = require('util');
|
||||
var flows = proxyquire('../../../.node-red/red/nodes/flows.js', {
|
||||
util: {
|
||||
log: function(msg) {
|
||||
if(!/ing flows/.test(msg)) {
|
||||
util.log(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var helper = require('../../../.node-red/test/nodes/helper.js');
|
||||
|
||||
var currentPB = null;
|
||||
var pushbulletStub = function() {
|
||||
var self = this;
|
||||
currentPB = this;
|
||||
|
||||
this.streamEmitter = new EventEmitter();
|
||||
this.streamObj = {
|
||||
on: function(key, cb){ self.streamEmitter.on(key, cb);},
|
||||
close: function(){},
|
||||
connect: function(){}
|
||||
}
|
||||
|
||||
// funcs
|
||||
this.me = function(cb){ cb(null, data.me); };
|
||||
this.history = function(opts, cb){ cb(null, getPushReply('note')); };
|
||||
this.devices = function(){};
|
||||
|
||||
// pushes
|
||||
this.note = function(){};
|
||||
this.file = function(){};
|
||||
this.link = function(){};
|
||||
this.list = function(){};
|
||||
this.address = function(){};
|
||||
this.push = function(){};
|
||||
|
||||
// websocket
|
||||
this.stream = function() {
|
||||
return this.streamObj;
|
||||
};
|
||||
|
||||
// modifiers
|
||||
this.deletePush = function(){};
|
||||
this.updatePush = function(){};
|
||||
|
||||
};
|
||||
|
||||
function getReply() {
|
||||
return JSON.parse(JSON.stringify(data.base));
|
||||
}
|
||||
|
||||
function getPushReply(name) {
|
||||
var r = JSON.parse(JSON.stringify(data.base));
|
||||
r.pushes.push(JSON.parse(JSON.stringify(data[name])))
|
||||
return r;
|
||||
}
|
||||
|
||||
var pushbulletNode = proxyquire("../../../social/pushbullet/57-pushbullet.js", {
|
||||
"pushbullet": function(apikey) {
|
||||
currentPB.apikey = apikey;
|
||||
return currentPB;
|
||||
}
|
||||
});
|
||||
|
||||
describe('pushbullet node', function() {
|
||||
|
||||
beforeEach(function(done) {
|
||||
currentPB = new pushbulletStub();
|
||||
helper.startServer(done);
|
||||
});
|
||||
|
||||
afterEach(function(done) {
|
||||
helper.unload();
|
||||
helper.stopServer(done);
|
||||
});
|
||||
|
||||
describe('loading and settings', function() {
|
||||
it('loads', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1"}];
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('gets user info', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1"}];
|
||||
var func = sinon.stub(currentPB, "me");
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
func.yield(false, data.me);
|
||||
helper.getNode("n1").me.then(function(me) {
|
||||
me.should.have.property("email", "john.doe@noma.il");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('gets user info, fail', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1"},
|
||||
{id:"n3", type:"pushbullet in", config: "n1"}];
|
||||
var func = sinon.spy(currentPB, "me");
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
var warn1 = sinon.spy(helper.getNode("n2"), "error");
|
||||
var warn2 = sinon.spy(helper.getNode("n3"), "error");
|
||||
func.yield(true, null);
|
||||
func.callCount.should.be.above(0);
|
||||
warn1.callCount.should.be.above(0);
|
||||
warn2.callCount.should.be.above(0);
|
||||
//helper.getNode("n1").me.should.have.property("email", "john.doe@noma.il");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('list devices', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1"}];
|
||||
var func = sinon.stub(currentPB, "devices");
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
helper.request().get("/pushbullet/n1/devices").end(function(err, res) {
|
||||
var devs = JSON.parse(res.text);
|
||||
devs.should.have.length(2);
|
||||
done();
|
||||
});
|
||||
|
||||
var ret = getReply();
|
||||
ret.devices = data.devices;
|
||||
func.yields(false, ret);
|
||||
});
|
||||
});
|
||||
|
||||
it('gets last modified', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1"}];
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
func.yield(false, getPushReply('modified'));
|
||||
helper.getNode("n1").last.then(function(last) {
|
||||
last.should.equal(1234);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('gets last modified with no history', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1"}];
|
||||
var func = sinon.stub(currentPB, "history");
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
func.yield(false, getReply());
|
||||
helper.getNode("n1").last.then(function(last) {
|
||||
last.should.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('backward compatiblity', function() {
|
||||
it('should be valid', function(done) {
|
||||
var flow = [{"id": "n1", "type": "pushbullet", "chan": "", "title": "topic"},
|
||||
{id:"n3", type:"helper", wires: [["n1"]]}];
|
||||
helper.load(pushbulletNode, flow, {n1:{pushkey:"key", deviceid: "dev"}}, function() {
|
||||
var func = sinon.spy(currentPB, "note");
|
||||
helper.getNode("n3").send({
|
||||
payload: "my note",
|
||||
});
|
||||
sinon.assert.calledWith(func, "dev", "topic", "my note");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('defaults and msg optionals', function() {
|
||||
it('defaults', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}];
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
var func = sinon.spy(currentPB, "note");
|
||||
helper.getNode("n3").send({
|
||||
payload: "my note",
|
||||
});
|
||||
helper.getNode("n1").me.then(function(){
|
||||
sinon.assert.calledWith(func, "john.doe@noma.il", "Node-RED", "my note");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('no overrides', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "note", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "note");
|
||||
helper.getNode("n3").send({
|
||||
payload: "my note",
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", "title", "my note");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('channel', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "note", title: "title", chan: "mychannel"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "note");
|
||||
helper.getNode("n3").send({
|
||||
payload: "my note",
|
||||
});
|
||||
sinon.assert.calledWith(func, {channel_tag: "mychannel"}, "title", "my note");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('channel from msg', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "note", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "note");
|
||||
helper.getNode("n3").send({
|
||||
payload: "my note",
|
||||
channel: "mychannel"
|
||||
});
|
||||
sinon.assert.calledWith(func, {channel_tag: "mychannel"}, "title", "my note");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('all optionals but defined in node', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "link", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "push");
|
||||
helper.getNode("n3").send({
|
||||
deviceid: "over1",
|
||||
topic: "over2",
|
||||
pushtype: "note",
|
||||
payload: "payload"
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", {type: "link", body: undefined, title:"title", url: "payload"});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('all optionals', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "", title: ""},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "_msg_"}}, function() {
|
||||
var func = sinon.spy(currentPB, "push");
|
||||
helper.getNode("n3").send({
|
||||
deviceid: "over1",
|
||||
topic: "over2",
|
||||
payload: "over3",
|
||||
pushtype: "link"
|
||||
});
|
||||
sinon.assert.calledWith(func, "over1", {type: "link", body: undefined, title: "over2", url: "over3"});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('output', function() {
|
||||
it('note', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "note", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "note");
|
||||
helper.getNode("n3").send({
|
||||
payload: "my note",
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", "title", "my note");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('link', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "link", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "push");
|
||||
helper.getNode("n3").send({
|
||||
payload: "http://link",
|
||||
message: "message"
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", {type: "link", title: "title", url: "http://link", body: "message"});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('list', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "list", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "list");
|
||||
helper.getNode("n3").send({
|
||||
payload: ["a", "b", "c"],
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", "title");
|
||||
func.getCall(0).args[2].should.have.length(3);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('list string', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "list", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "list");
|
||||
helper.getNode("n3").send({
|
||||
payload: '["a", "b", "c"]',
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", "title");
|
||||
func.getCall(0).args[2].should.have.length(3);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('address', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "address", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "address");
|
||||
helper.getNode("n3").send({
|
||||
payload: "My Street 4",
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", "title", "My Street 4");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('file', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "file", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "file");
|
||||
var fn = path.join(__dirname, "data.js")
|
||||
helper.getNode("n3").send({
|
||||
payload: fn,
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", fn, "title");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fail if file don\'t exist', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "file", title: "title"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "file");
|
||||
var errfn = sinon.spy(helper.getNode("n2"), "error");
|
||||
helper.getNode("n3").send({
|
||||
payload: "hello",
|
||||
});
|
||||
func.called.should.fail;
|
||||
errfn.callCount.should.be.above(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('raw', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "push");
|
||||
helper.getNode("n3").send({
|
||||
pushtype: '_raw_',
|
||||
raw: {type: 'note', title: 'title', body: 'this is the note'}
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", {type: 'note', title: 'title', body: 'this is the note'});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('raw update', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}, n2: {deviceid: "id"}}, function() {
|
||||
var func = sinon.spy(currentPB, "updatePush");
|
||||
helper.getNode("n3").send({
|
||||
pushtype: '_rawupdate_',
|
||||
raw: {items: [{checked:false, text: 'a'}]},
|
||||
data: {iden: 'id'}
|
||||
});
|
||||
sinon.assert.calledWith(func, "id", {items: [{checked:false, text: 'a'}]});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('actions', function() {
|
||||
it('delete', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "delete"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
var func = sinon.spy(currentPB, "deletePush");
|
||||
helper.getNode("n3").send({
|
||||
payload: "my note",
|
||||
data: { iden: "delid"}
|
||||
});
|
||||
sinon.assert.calledWith(func, "delid");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('dismiss', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "dismissal"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
var func = sinon.spy(currentPB, "updatePush");
|
||||
helper.getNode("n3").send({
|
||||
payload: "my note",
|
||||
data: { iden: "delid", dismissed: false }
|
||||
});
|
||||
sinon.assert.calledWith(func, "delid");
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('update list', function(done) {
|
||||
var flow = [{id:"n1", type:"pushbullet-config"},
|
||||
{id:"n2", type:"pushbullet", config: "n1", pushtype: "updatelist"},
|
||||
{id:"n3", type:"helper", wires: [["n2"]]}
|
||||
];
|
||||
|
||||
helper.load(pushbulletNode, flow, {n1:{apikey:"invalid"}}, function() {
|
||||
var func = sinon.spy(currentPB, "updatePush");
|
||||
helper.getNode("n3").send({
|
||||
payload: [{}, {}, {}],
|
||||
data: { iden: "delid", type: "list" }
|
||||
});
|
||||
sinon.assert.calledWith(func, "delid");
|
||||
func.getCall(0).args[1].items.should.have.length(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('input', function() {
|
||||
it('handles stream push', 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) {
|
||||
done();
|
||||
});
|
||||
currentPB.streamEmitter.emit("message", {type: "push", push: {type: "clip", body: "clipboard"}})
|
||||
});
|
||||
});
|
||||
|
||||
it('handles status', 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() {
|
||||
var func = sinon.spy(helper.getNode("n2"), 'status');
|
||||
currentPB.streamEmitter.emit("connect");
|
||||
currentPB.streamEmitter.emit("close");
|
||||
currentPB.streamEmitter.emit("error");
|
||||
func.callCount.should.equal(3);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('clipboard', 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", "clip");
|
||||
msg.should.have.property("payload", "hello");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
currentPB.streamEmitter.emit("message", {type: "push", push: {type: "clip", body: "hello"}});
|
||||
});
|
||||
});
|
||||
|
||||
it('mirror', 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", "mirror");
|
||||
msg.should.have.property("payload", "If you see this on your computer, mirroring is working!\n");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
currentPB.streamEmitter.emit("message", {type: "push", push: data.mirror});
|
||||
});
|
||||
});
|
||||
|
||||
it('dismissal', 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", "pjgzwwocCCy");
|
||||
msg.should.have.property("data");
|
||||
done();
|
||||
});
|
||||
currentPB.streamEmitter.emit("message", {type: "push", push: data.dismissal});
|
||||
});
|
||||
});
|
||||
|
||||
it('unknown type', 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() {
|
||||
var err = sinon.spy(helper.getNode("n1"), "error");
|
||||
currentPB.streamEmitter.emit("message", {type: "push", push: {type: "push", push: {type: "unknown", data: "test"}}});
|
||||
err.called.should.be.ok;
|
||||
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"}];
|
||||
|
||||
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"}];
|
||||
|
||||
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"}];
|
||||
|
||||
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"}];
|
||||
|
||||
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"}];
|
||||
|
||||
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"}];
|
||||
|
||||
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"}];
|
||||
|
||||
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"}];
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
221
test/social/pushbullet/data.js
Normal file
221
test/social/pushbullet/data.js
Normal file
@@ -0,0 +1,221 @@
|
||||
module.exports = {
|
||||
base: {
|
||||
"accounts": [],
|
||||
"aliases": [],
|
||||
"channels": [],
|
||||
"clients": [],
|
||||
"contacts": [],
|
||||
"devices": [],
|
||||
"grants": [],
|
||||
"pushes": [],
|
||||
"subscriptions": []
|
||||
},
|
||||
modified: {
|
||||
"active": true,
|
||||
"iden": "xXxXxXxXxXxsjArqXRsaZM",
|
||||
"created": 1421834169.9435499,
|
||||
"modified": 1234,
|
||||
"type": "note",
|
||||
"dismissed": false,
|
||||
"sender_iden": "xXxXxXxXxXx",
|
||||
"sender_email": "john.doe@noma.il",
|
||||
"sender_email_normalized": "johndoe@noma.il",
|
||||
"sender_name": "John Doe",
|
||||
"receiver_iden": "xXxXxXxXxXx",
|
||||
"receiver_email": "john.doe@noma.il",
|
||||
"receiver_email_normalized": "johndoe@noma.il",
|
||||
"title": "title",
|
||||
"body": "body"
|
||||
},
|
||||
devices: [
|
||||
{
|
||||
"active": true,
|
||||
"iden": "xXxXxXxXxXxsjAnBdJA0yG",
|
||||
"created": 1418045447.298193,
|
||||
"modified": 1420698259.7963278,
|
||||
"type": "chrome",
|
||||
"kind": "chrome",
|
||||
"nickname": "Chrome",
|
||||
"manufacturer": "Google",
|
||||
"model": "Chrome",
|
||||
"app_version": 157,
|
||||
"pushable": true
|
||||
},
|
||||
{
|
||||
"active": true,
|
||||
"iden": "xXxXxXxXxXxsjAiVsKnSTs",
|
||||
"created": 1418045076.665757,
|
||||
"modified": 1418047786.564935,
|
||||
"type": "ios",
|
||||
"kind": "ios",
|
||||
"nickname": "myphone",
|
||||
"manufacturer": "Apple",
|
||||
"model": "iPhone 5s (Global)",
|
||||
"app_version": 3671,
|
||||
"push_token": "production",
|
||||
"pushable": true
|
||||
}
|
||||
],
|
||||
me: {
|
||||
"iden": "xXxXxXxXxXx",
|
||||
"created": 1418045075.2908669,
|
||||
"modified": 1418504323.166974,
|
||||
"email": "john.doe@noma.il",
|
||||
"email_normalized": "johndoe@noma.il",
|
||||
"name": "John Doe",
|
||||
"image_url": "https://photo.jpg",
|
||||
"google_userinfo": {
|
||||
"name": "John Doe"
|
||||
},
|
||||
"preferences": {
|
||||
"onboarding": {
|
||||
"app": false,
|
||||
"extension": false,
|
||||
"friends": true
|
||||
},
|
||||
"social": false
|
||||
}
|
||||
},
|
||||
note: {
|
||||
"active": true,
|
||||
"iden": "xXxXxXxXxXxsjArqXRsaZM",
|
||||
"created": 1421834169.9435499,
|
||||
"modified": 1421850263.303394,
|
||||
"type": "note",
|
||||
"dismissed": false,
|
||||
"sender_iden": "xXxXxXxXxXx",
|
||||
"sender_email": "john.doe@noma.il",
|
||||
"sender_email_normalized": "johndoe@noma.il",
|
||||
"sender_name": "John Doe",
|
||||
"receiver_iden": "xXxXxXxXxXx",
|
||||
"receiver_email": "john.doe@noma.il",
|
||||
"receiver_email_normalized": "johndoe@noma.il",
|
||||
"title": "title",
|
||||
"body": "body"
|
||||
},
|
||||
link: {
|
||||
"active": true,
|
||||
"iden": "xXxXxXxXxXxsjxQymYT0qy",
|
||||
"created": 1421834198.374012,
|
||||
"modified": 1421850263.181358,
|
||||
"type": "link",
|
||||
"dismissed": false,
|
||||
"sender_iden": "xXxXxXxXxXx",
|
||||
"sender_email": "john.doe@noma.il",
|
||||
"sender_email_normalized": "johndoe@noma.il",
|
||||
"sender_name": "John Doe",
|
||||
"receiver_iden": "xXxXxXxXxXx",
|
||||
"receiver_email": "john.doe@noma.il",
|
||||
"receiver_email_normalized": "johndoe@noma.il",
|
||||
"title": "title",
|
||||
"url": "url"
|
||||
},
|
||||
file: {
|
||||
"active": true,
|
||||
"iden": "xXxXxXxXxXxsjAjKAwqc5k",
|
||||
"created": 1421842821.5911932,
|
||||
"modified": 1421850262.446063,
|
||||
"type": "file",
|
||||
"dismissed": false,
|
||||
"sender_iden": "xXxXxXxXxXx",
|
||||
"sender_email": "john.doe@noma.il",
|
||||
"sender_email_normalized": "johndoe@noma.il",
|
||||
"sender_name": "John Doe",
|
||||
"receiver_iden": "xXxXxXxXxXx",
|
||||
"receiver_email": "john.doe@noma.il",
|
||||
"receiver_email_normalized": "johndoe@noma.il",
|
||||
"body": "title",
|
||||
"file_name": "filename",
|
||||
"file_type": "text/plain",
|
||||
"file_url": "fileurl"
|
||||
},
|
||||
address: {
|
||||
"active": true,
|
||||
"iden": "xXxXxXxXxXxsjAlHSjtjcO",
|
||||
"created": 1421834217.764878,
|
||||
"modified": 1421850261.531033,
|
||||
"type": "address",
|
||||
"dismissed": false,
|
||||
"sender_iden": "xXxXxXxXxXx",
|
||||
"sender_email": "john.doe@noma.il",
|
||||
"sender_email_normalized": "johndoe@noma.il",
|
||||
"sender_name": "John Doe",
|
||||
"receiver_iden": "xXxXxXxXxXx",
|
||||
"receiver_email": "john.doe@noma.il",
|
||||
"receiver_email_normalized": "johndoe@noma.il",
|
||||
"name": "title",
|
||||
"address": "address"
|
||||
},
|
||||
list: {
|
||||
"active": true,
|
||||
"iden": "xXxXxXxXxXxsjAdWmbcF3Y",
|
||||
"created": 1421834433.677966,
|
||||
"modified": 1421834444.256159,
|
||||
"type": "list",
|
||||
"dismissed": false,
|
||||
"sender_iden": "xXxXxXxXxXx",
|
||||
"sender_email": "john.doe@noma.il",
|
||||
"sender_email_normalized": "johndoe@noma.il",
|
||||
"sender_name": "John Doe",
|
||||
"receiver_iden": "xXxXxXxXxXx",
|
||||
"receiver_email": "john.doe@noma.il",
|
||||
"receiver_email_normalized": "johndoe@noma.il",
|
||||
"title": "title",
|
||||
"items": [
|
||||
{
|
||||
"checked": true,
|
||||
"text": "a"
|
||||
},
|
||||
{
|
||||
"checked": true,
|
||||
"text": "b"
|
||||
},
|
||||
{
|
||||
"checked": false,
|
||||
"text": "c"
|
||||
}
|
||||
]
|
||||
},
|
||||
mirror: {
|
||||
"type": "mirror",
|
||||
"iden": "pjgzwwn3YPQ",
|
||||
"source_device_iden": "ubddjAzSDVLgrI",
|
||||
"package_name": "com.pushbullet.android",
|
||||
"application_name": "Pushbullet",
|
||||
"notification_id": "-8",
|
||||
"notification_tag": null,
|
||||
"dismissable": true,
|
||||
"title": "Mirroring test",
|
||||
"body": "If you see this on your computer, mirroring is working!\n",
|
||||
"icon": "iVBORw0KGgoAAAANSUhEBgUzC42AAAADNElEQVRo\ng==\n",
|
||||
"created": 1399350964.1649699,
|
||||
"sender_iden": "ubd",
|
||||
"sender_email": "ryan@pushbullet.com",
|
||||
"sender_email_normalized": "ryan@pushbullet.com",
|
||||
"receiver_iden": "ubd",
|
||||
"receiver_email": "ryan@pushbullet.com",
|
||||
"receiver_email_normalized": "ryan@pushbullet.com"
|
||||
},
|
||||
dismissal: {
|
||||
"type": "dismissal",
|
||||
"iden": "pjgzwwocCCy",
|
||||
"source_device_iden": "ubddjAzSDVLgrI",
|
||||
"package_name": "com.pushbullet.android",
|
||||
"notification_id": "-8",
|
||||
"notification_tag":null,
|
||||
"created":1399350966.22458,
|
||||
"sender_iden": "ubd",
|
||||
"sender_email": "ryan@pushbullet.com",
|
||||
"sender_email_normalized": "ryan@pushbullet.com",
|
||||
"receiver_iden": "ubd",
|
||||
"receiver_email": "ryan@pushbullet.com",
|
||||
"receiver_email_normalized": "ryan@pushbullet.com"
|
||||
},
|
||||
"delete": {
|
||||
"active": false,
|
||||
"iden": "pjgzwwocCCy",
|
||||
"created": 1422525494.4456809,
|
||||
"modified": 1422526124.538504,
|
||||
"dismissed": false
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user