-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.ts
87 lines (66 loc) · 2.28 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import DomustoPushBullet from './';
import * as proxyquire from 'proxyquire';
import * as sinon from 'sinon';
// DOMUSTO
import DomustoPlugin from '../../domusto/DomustoPlugin';
import { Domusto } from '../../domusto/DomustoInterfaces';
describe('Plugin DomustoPushBullet', () => {
let DomustoPushBulletProxy;
let DomustoPluginProxy;
let broadcastSignalSpy;
let sendNoteToAllSpy;
let noteSpy;
let PushBulletPluginInstance;
beforeEach(() => {
broadcastSignalSpy = sinon.spy(DomustoPlugin.prototype, 'broadcastSignal');
noteSpy = sinon.spy();
let PushBulletStub = sinon.stub().returns({
note: noteSpy
});
DomustoPushBulletProxy = proxyquire('./index', {
'pushbullet': PushBulletStub,
});
PushBulletPluginInstance = new DomustoPushBulletProxy.default({
id: 'PushBullet',
enabled: true,
dummyData: false,
debug: true,
settings: {
apiKeys: [
'v1Kls34hjsdhfs8f32h4dfghkdjJSDFj',
'9834jKDFJ92ijjkldfj2JDO29jkasdfj'
]
}
});
sendNoteToAllSpy = sinon.spy(PushBulletPluginInstance, 'sendNoteToAll');
});
afterEach(() => {
broadcastSignalSpy.restore();
});
it('should send a push message when signal received', () => {
let signal: Domusto.Signal = {
pluginId: 'PUSHBULLET',
sender: Domusto.SignalSender.client,
deviceId: 'note',
data: {
title: 'test message',
message: 'This is a test'
}
};
PushBulletPluginInstance.onSignalReceivedForPlugin(signal);
sinon.assert.calledWith(sendNoteToAllSpy, 'test message', 'This is a test');
});
it('should send a push message to all provided api keys', () => {
let signal: Domusto.Signal = {
pluginId: 'PUSHBULLET',
sender: Domusto.SignalSender.client,
deviceId: 'note',
data: {
title: 'test message',
message: 'This is a test'
}
};
PushBulletPluginInstance.onSignalReceivedForPlugin(signal);
sinon.assert.calledTwice(noteSpy);
});
});