-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.ts
118 lines (98 loc) · 2.79 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as proxyquire from 'proxyquire';
import * as sinon from 'sinon';
// DOMUSTO
import DomustoPlugin from '../../domusto/DomustoPlugin';
import { Domusto } from '../../domusto/DomustoTypes';
describe('Plugin DomustoP1', () => {
let DomustoP1Proxy;
let DomustoPluginProxy;
let broadcastSignalSpy;
let p1PluginInstance;
before(() => {
broadcastSignalSpy = sinon.spy(DomustoPlugin.prototype, 'broadcastSignal');
let p1ReaderStub = sinon.stub().returns({
on: (eventName, eventFunction) => {
return true;
}
});
DomustoP1Proxy = proxyquire('./index', {
'p1-reader': p1ReaderStub,
});
p1PluginInstance = new DomustoP1Proxy.default({
id: 'P1',
enabled: true,
dummyData: false,
debug: true,
settings: {
port: '/dev/dummy',
emulator: false
}
});
});
after(() => {
broadcastSignalSpy.restore();
});
it('should broadcast update on new data', () => {
const dummyData = {
electricity: {
received: {
tariff1: {
reading: 23410,
unit: 'kWh'
},
tariff2: {
reading: 12145,
unit: 'kWh'
},
actual: {
reading: 5622,
unit: 'kW'
},
},
delivered: {
tariff1: {
reading: 45642,
unit: 'kWh'
},
tariff2: {
reading: 34534,
unit: 'kWh'
},
actual: {
reading: 2343,
unit: 'kW'
},
}
}
};
p1PluginInstance.updatePowerData(dummyData);
sinon.assert.calledWith(broadcastSignalSpy, 'received', {
tariff1: {
value: 23410,
unit: 'kWh'
},
tariff2: {
value: 12145,
unit: 'kWh'
},
actual: {
value: 5622,
unit: 'kW'
}
});
sinon.assert.calledWith(broadcastSignalSpy, 'delivered', {
tariff1: {
value: 45642,
unit: 'kWh'
},
tariff2: {
value: 34534,
unit: 'kWh'
},
actual: {
value: 2343,
unit: 'kW'
}
});
});
});