forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox.test.js
90 lines (68 loc) · 2.48 KB
/
sandbox.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
var should = require('should');
describe('sandbox', function ( ) {
var sandbox = require('../lib/sandbox')();
var now = Date.now();
it('init on client', function (done) {
var ctx = {
settings: {
units: 'mg/dl'
, thresholds:{
bgHigh: 260
, bgTargetTop: 180
, bgTargetBottom: 80
, bgLow: 55
}
}
, pluginBase: {}
};
ctx.language = require('../lib/language')();
var data = {sgvs: [{mgdl: 100, mills: now}]};
var sbx = sandbox.clientInit(ctx, Date.now(), data);
sbx.pluginBase.should.equal(ctx.pluginBase);
sbx.data.should.equal(data);
sbx.lastSGVMgdl().should.equal(100);
done();
});
function createServerSandbox() {
var env = require('../lib/server/env')();
var ctx = {};
ctx.ddata = require('../lib/data/ddata')();
ctx.notifications = require('../lib/notifications')(env, ctx);
ctx.language = require('../lib/language')();
return sandbox.serverInit(env, ctx);
}
it('init on server', function (done) {
var sbx = createServerSandbox();
sbx.data.sgvs = [{mgdl: 100, mills: now}];
should.exist(sbx.notifications.requestNotify);
should.not.exist(sbx.notifications.process);
should.not.exist(sbx.notifications.ack);
sbx.lastSGVMgdl().should.equal(100);
done();
});
it('display 39 as LOW and 401 as HIGH', function () {
var sbx = createServerSandbox();
sbx.displayBg({mgdl: 39}).should.equal('LOW');
sbx.displayBg({mgdl: '39'}).should.equal('LOW');
sbx.displayBg({mgdl: 401}).should.equal('HIGH');
sbx.displayBg({mgdl: '401'}).should.equal('HIGH');
});
it('build BG Now line using properties', function ( ) {
var sbx = createServerSandbox();
sbx.data.sgvs = [{mgdl: 99, mills: now}];
sbx.properties = { delta: {display: '+5' }, direction: {value: 'FortyFiveUp', label: '↗', entity: '↗'} };
sbx.buildBGNowLine().should.equal('BG Now: 99 +5 ↗ mg/dl');
});
it('build default message using properties', function ( ) {
var sbx = createServerSandbox();
sbx.data.sgvs = [{mgdl: 99, mills: now}];
sbx.properties = {
delta: {display: '+5' }
, direction: {value: 'FortyFiveUp', label: '↗', entity: '↗'}
, rawbg: {displayLine: 'Raw BG: 100 mg/dl'}
, iob: {displayLine: 'IOB: 1.25U'}
, cob: {displayLine: 'COB: 15g'}
};
sbx.buildDefaultMessage().should.equal('BG Now: 99 +5 ↗ mg/dl\nRaw BG: 100 mg/dl\nIOB: 1.25U\nCOB: 15g');
});
});