forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensorage.test.js
175 lines (140 loc) · 5.53 KB
/
sensorage.test.js
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
'use strict';
var should = require('should');
var times = require('../lib/times');
var levels = require('../lib/levels');
describe('sage', function ( ) {
var env = require('../env')();
var ctx = {};
ctx.ddata = require('../lib/data/ddata')();
ctx.notifications = require('../lib/notifications')(env, ctx);
ctx.language = require('../lib/language')();
var sage = require('../lib/plugins/sensorage')(ctx);
var sandbox = require('../lib/sandbox')();
function prepareSandbox ( ) {
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
return sbx;
}
it('set a pill to the current age since start with change', function (done) {
var data = {
sensorTreatments: [
{eventType: 'Sensor Change', notes: 'Foo', mills: Date.now() - times.days(2).msecs}
, {eventType: 'Sensor Start', notes: 'Bar', mills: Date.now() - times.days(1).msecs}
]
};
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
console.log(JSON.stringify(options));
options.value.should.equal('1d0h');
options.info[0].label.should.equal('Sensor Insert');
options.info[1].should.match({ label: 'Duration', value: '2 days 0 hours' });
options.info[2].should.match({ label: 'Notes', value: 'Foo' });
options.info[3].label.should.equal('Sensor Start');
options.info[4].should.match({ label: 'Duration', value: '1 days 0 hours' });
options.info[5].should.match({ label: 'Notes', value: 'Bar' });
done();
}
}
};
ctx.language = require('../lib/language')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
sage.setProperties(sbx);
sage.updateVisualisation(sbx);
});
it('set a pill to the current age since start without change', function (done) {
var data = {
sensorTreatments: [
{eventType: 'Sensor Start', notes: 'Bar', mills: Date.now() - times.days(3).msecs}
]
};
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
options.value.should.equal('3d0h');
options.info[0].label.should.equal('Sensor Start');
options.info[1].should.match({ label: 'Duration', value: '3 days 0 hours' });
options.info[2].should.match({ label: 'Notes', value: 'Bar' });
done();
}
}
};
ctx.language = require('../lib/language')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
sage.setProperties(sbx);
sage.updateVisualisation(sbx);
});
it('set a pill to the current age since change without start', function (done) {
var data = {
sensorTreatments: [
{eventType: 'Sensor Change', notes: 'Foo', mills: Date.now() - times.days(3).msecs}
]
};
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
options.value.should.equal('3d0h');
options.info[0].label.should.equal('Sensor Insert');
options.info[1].should.match({ label: 'Duration', value: '3 days 0 hours' });
options.info[2].should.match({ label: 'Notes', value: 'Foo' });
done();
}
}
};
ctx.language = require('../lib/language')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
sage.setProperties(sbx);
sage.updateVisualisation(sbx);
});
it('set a pill to the current age since change after start', function (done) {
var data = {
sensorTreatments: [
{eventType: 'Sensor Start', notes: 'Bar', mills: Date.now() - times.days(10).msecs}
, {eventType: 'Sensor Change', notes: 'Foo', mills: Date.now() - times.days(3).msecs}
]
};
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
options.value.should.equal('3d0h');
options.info.length.should.equal(3);
options.info[0].label.should.equal('Sensor Insert');
options.info[1].should.match({ label: 'Duration', value: '3 days 0 hours' });
options.info[2].should.match({ label: 'Notes', value: 'Foo' });
done();
}
}
};
ctx.language = require('../lib/language')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
sage.setProperties(sbx);
sage.updateVisualisation(sbx);
});
it('trigger an alarm when sensor is 6 days and 22 hours old', function (done) {
ctx.notifications.initRequests();
var before = Date.now() - times.days(6).msecs - times.hours(22).msecs;
ctx.ddata.sensorTreatments = [{eventType: 'Sensor Start', mills: before}];
var sbx = prepareSandbox();
sbx.extendedSettings = { 'enableAlerts': true };
sage.setProperties(sbx);
sage.checkNotifications(sbx);
var highest = ctx.notifications.findHighestAlarm('SAGE');
highest.level.should.equal(levels.URGENT);
highest.title.should.equal('Sensor age 6 days 22 hours');
done();
});
it('not trigger an alarm when sensor is 6 days and 23 hours old', function (done) {
ctx.notifications.initRequests();
var before = Date.now() - times.days(6).msecs - times.hours(23).msecs;
ctx.ddata.sensorTreatments = [{eventType: 'Sensor Start', mills: before}];
var sbx = prepareSandbox();
sbx.extendedSettings = { 'enableAlerts': true };
sage.setProperties(sbx);
sage.checkNotifications(sbx);
should.not.exist(ctx.notifications.findHighestAlarm('SAGE'));
done();
});
});