-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.ts
98 lines (74 loc) · 2.69 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
88
89
90
91
92
93
94
95
96
97
98
import * as proxyquire from 'proxyquire';
import * as sinon from 'sinon';
// DOMUSTO
import DomustoPlugin from '../../domusto/DomustoPlugin';
import { Domusto } from '../../domusto/DomustoTypes';
describe('Plugin DomustoMarantz', () => {
let DomustoMarantzProxy;
let DomustoPluginProxy;
let broadcastSignalSpy;
let marantzPluginInstance;
before(() => {
broadcastSignalSpy = sinon.spy(DomustoPlugin.prototype, 'broadcastSignal');
let marantzAvrStub = sinon.stub().returns({
getState() {
return new Promise((resolve, reject) => {
resolve({
input: 'GAME',
power: true,
mute: false,
volume: '-30db',
surroundMode: 'MOVIE'
});
});
},
setPowerState(state) {
return new Promise((resolve, reject) => {
resolve(state);
});
}
});
DomustoMarantzProxy = proxyquire('./index', {
'marantz-avr': marantzAvrStub,
});
marantzPluginInstance = new DomustoMarantzProxy.default({
id: 'MARANTZ',
enabled: true,
dummyData: false,
debug: true,
settings: {
ip: '192.168.178.2',
pollInterval: 5 * 1000
}
});
});
after(() => {
broadcastSignalSpy.restore();
});
it('should execute refreshRecieverStatus from contructor', () => {
sinon.assert.called(broadcastSignalSpy);
});
it('should set the correct state when signal received', () => {
let signal: Domusto.Signal = {
pluginId: 'MARANTZ',
sender: Domusto.SignalSender.client,
deviceId: 'power',
data: {
state: 'on'
}
};
marantzPluginInstance.onSignalReceivedForPlugin(signal);
sinon.assert.calledWith(broadcastSignalSpy, 'power', { state: 'on' });
});
it('should broadcast update on refreshRecieverStatus', () => {
marantzPluginInstance.refreshReceiverStatus();
setTimeout(() => {
// console.log(broadcastSignalSpy.getCalls()[0].args);
sinon.assert.calledWith(broadcastSignalSpy, 'power', { state: 'on' });
sinon.assert.calledWith(broadcastSignalSpy, 'mute', { state: 'off' });
sinon.assert.calledWith(broadcastSignalSpy, 'surroundMode', { state: 'MOVIE' });
sinon.assert.calledWith(broadcastSignalSpy, 'input', { state: 'GAME' });
process.exit();
}, 100);
});
});