-
Notifications
You must be signed in to change notification settings - Fork 71.3k
/
treatmentnotify.test.js
76 lines (54 loc) · 2.72 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
var _ = require('lodash');
var should = require('should');
describe('treatmentnotify', function ( ) {
var treatmentnotify = require('../lib/plugins/treatmentnotify')();
var env = require('../env')();
var ctx = {};
ctx.data = require('../lib/data')(env, ctx);
ctx.notifications = require('../lib/notifications')(env, ctx);
var now = Date.now();
it('Request a snooze for a recent treatment and request an info notify', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 100}];
ctx.data.treatments = [{eventType: 'BG Check', glucose: '100', x: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
should.not.exist(ctx.notifications.findHighestAlarm());
should.exist(ctx.notifications.snoozedBy({level: ctx.notifications.levels.URGENT}));
_.first(ctx.notifications.findInfos()).level.should.equal(ctx.notifications.levels.INFO);
done();
});
it('Not Request a snooze for an older treatment and not request an info notification', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 100}];
ctx.data.treatments = [{x: Date.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: ctx.notifications.levels.URGENT}));
should.not.exist(_.first(ctx.notifications.findInfos()));
done();
});
it('Request a snooze for a recent calibration and request an info notify', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 100}];
ctx.data.mbgs = [{y: '100', x: Date.now()}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
should.not.exist(ctx.notifications.findHighestAlarm());
should.exist(ctx.notifications.snoozedBy({level: ctx.notifications.levels.URGENT}));
_.first(ctx.notifications.findInfos()).level.should.equal(ctx.notifications.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.data.sgvs = [{x: now, y: 100}];
ctx.data.mbgs = [{y: '100', x: Date.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: ctx.notifications.levels.URGENT}));
should.not.exist(_.first(ctx.notifications.findInfos()));
done();
});
});