forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtreatmentnotify.test.js
128 lines (92 loc) · 4.56 KB
/
treatmentnotify.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
var _ = require('lodash');
var should = require('should');
var levels = require('../lib/levels');
describe('treatmentnotify', function ( ) {
var env = require('../lib/server/env')();
var ctx = {};
ctx.ddata = require('../lib/data/ddata')();
ctx.notifications = require('../lib/notifications')(env, ctx);
ctx.levels = levels;
ctx.language = require('../lib/language')().set('en');
var treatmentnotify = require('../lib/plugins/treatmentnotify')(ctx);
var now = Date.now();
it('Request a snooze for a recent treatment and request an info notify', function (done) {
ctx.notifications.initRequests();
ctx.ddata.sgvs = [{mills: now, mgdl: 100}];
ctx.ddata.treatments = [{eventType: 'BG Check', glucose: '100', mills: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
should.not.exist(ctx.notifications.findHighestAlarm());
should.exist(ctx.notifications.snoozedBy({level: levels.URGENT}));
_.first(ctx.notifications.findUnSnoozeable()).level.should.equal(levels.INFO);
done();
});
it('Not Request a snooze for an older treatment and not request an info notification', function (done) {
ctx.notifications.initRequests();
ctx.ddata.sgvs = [{mills: now, mgdl: 100}];
ctx.ddata.treatments = [{mills: now - (15 * 60 * 1000)}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
should.not.exist(ctx.notifications.findHighestAlarm());
should.exist(ctx.notifications.snoozedBy({level: levels.URGENT}));
should.not.exist(_.first(ctx.notifications.findUnSnoozeable()));
done();
});
it('Request a snooze for a recent calibration and request an info notify', function (done) {
ctx.notifications.initRequests();
ctx.ddata.sgvs = [{mills: now, mgdl: 100}];
ctx.ddata.mbgs = [{mgdl: '100', mills: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
should.not.exist(ctx.notifications.findHighestAlarm());
should.exist(ctx.notifications.snoozedBy({level: levels.URGENT}));
_.first(ctx.notifications.findUnSnoozeable()).level.should.equal(levels.INFO);
done();
});
it('Not Request a snooze for an older calibration treatment and not request an info notification', function (done) {
ctx.notifications.initRequests();
ctx.ddata.sgvs = [{mills: now, mgdl: 100}];
ctx.ddata.mbgs = [{mgdl: '100', mills: now - (15 * 60 * 1000)}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
should.not.exist(ctx.notifications.findHighestAlarm());
should.exist(ctx.notifications.snoozedBy({level: levels.URGENT}));
should.not.exist(_.first(ctx.notifications.findUnSnoozeable()));
done();
});
it('Request a notification for an announcement even there is an active snooze', function (done) {
ctx.notifications.initRequests();
ctx.ddata.treatments = [{mills: now, mgdl: 40, eventType: 'Announcement', isAnnouncement: true, notes: 'This not an alarm'}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
var fakeSnooze = {
level: levels.URGENT
, title: 'Snoozing alarms for the test'
, message: 'testing...'
, lengthMills: 60000
};
sbx.notifications.requestSnooze(fakeSnooze);
treatmentnotify.checkNotifications(sbx);
var announcement = _.first(ctx.notifications.findUnSnoozeable());
should.exist(announcement);
announcement.title.should.equal('Urgent Announcement');
announcement.level.should.equal(levels.URGENT);
announcement.pushoverSound.should.equal('persistent');
should.deepEqual(ctx.notifications.findHighestAlarm('Announcement'), announcement);
ctx.notifications.snoozedBy(announcement).should.equal(false);
done();
});
it('Request a notification for a non-error announcement', function (done) {
ctx.notifications.initRequests();
ctx.ddata.treatments = [{mills: now, mgdl: 100, eventType: 'Announcement', isAnnouncement: true, notes: 'This not an alarm'}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
var announcement = _.first(ctx.notifications.findUnSnoozeable());
should.exist(announcement);
announcement.title.should.equal('Announcement');
announcement.level.should.equal(levels.INFO);
should.not.exist(announcement.pushoverSound);
should.not.exist(ctx.notifications.findHighestAlarm());
ctx.notifications.snoozedBy(announcement).should.equal(false);
done();
});
});