forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcannulaage.test.js
96 lines (76 loc) · 2.64 KB
/
cannulaage.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
'use strict';
require('should');
const helper = require('./inithelper')();
const levels = helper.ctx.levels;
describe('cage', function ( ) {
var env = require('../lib/server/env')();
var ctx = helper.getctx();
ctx.ddata = require('../lib/data/ddata')();
ctx.notifications = require('../lib/notifications')(env, ctx);
var cage = require('../lib/plugins/cannulaage')(ctx);
var sandbox = require('../lib/sandbox')(ctx);
function prepareSandbox ( ) {
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
sbx.offerProperty('iob', function () {
return {iob: 0};
});
return sbx;
}
it('set a pill to the current cannula age', function (done) {
var data = {
sitechangeTreatments: [
{eventType: 'Site Change', notes: 'Foo', mills: Date.now() - 48 * 60 * 60000}
, {eventType: 'Site Change', notes: 'Bar', mills: Date.now() - 24 * 60 * 60000}
]
};
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
options.value.should.equal('24h');
options.info[1].value.should.equal('Bar');
done();
}
}
};
ctx.language = require('../lib/language')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
cage.setProperties(sbx);
cage.updateVisualisation(sbx);
});
it('set a pill to the current cannula age', function (done) {
var data = {
sitechangeTreatments: [
{eventType: 'Site Change', notes: 'Foo', mills: Date.now() - 48 * 60 * 60000}
, {eventType: 'Site Change', notes: '', mills: Date.now() - 59 * 60000}
]
};
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
options.value.should.equal('0h');
options.info.length.should.equal(1);
done();
}
}
};
ctx.language = require('../lib/language')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
cage.setProperties(sbx);
cage.updateVisualisation(sbx);
});
it('trigger a warning when cannula is 48 hours old', function (done) {
ctx.notifications.initRequests();
var before = Date.now() - (48 * 60 * 60 * 1000);
ctx.ddata.sitechangeTreatments = [{eventType: 'Site Change', mills: before}];
var sbx = prepareSandbox();
sbx.extendedSettings = { 'enableAlerts': 'TRUE' };
cage.setProperties(sbx);
cage.checkNotifications(sbx);
var highest = ctx.notifications.findHighestAlarm('CAGE');
highest.level.should.equal(levels.WARN);
highest.title.should.equal('Cannula age 48 hours');
done();
});
});