Skip to content

Commit c00057c

Browse files
committed
Fix tests that fail when DISPLAY_UNITS=mmol
Some of the tests check for values in units of mg/dL. These fail when the `DISPLAY_UNITS` environment variable is set to `mmol` or `mmol/L`. The failures can be reproduced with: ``` $ DISPLAY_UNITS=mmol npm run-script test $ DISPLAY_UNITS=mmol/L npm run-script test ``` This change fixes the failing cases by first checking the configured units, and then choosing an expected value accordingly. This fix was tested with: ``` $ npm run-script test $ DISPLAY_UNITS=mg/dl npm run-script test $ DISPLAY_UNITS=mmol npm run-script test $ DISPLAY_UNITS=mmol/L npm run-script test ``` Fixes #8353
1 parent e74f53c commit c00057c

File tree

8 files changed

+97
-56
lines changed

8 files changed

+97
-56
lines changed

tests/ar2.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ describe('ar2', function ( ) {
7272
var highest = ctx.notifications.findHighestAlarm();
7373
highest.level.should.equal(helper.ctx.levels.WARN);
7474
highest.title.should.equal('Warning, HIGH predicted');
75-
highest.message.should.equal('BG Now: 170 +20 ↗ mg/dl\nBG 15m: 206 mg/dl\nIOB: 1.25U');
75+
76+
var expectedMessage =
77+
ctx.settings.units === 'mmol' ?
78+
'BG Now: 9.4 +1.1 ↗ mmol/L\nBG 15m: 11.4 mmol/L\nIOB: 1.25U' :
79+
'BG Now: 170 +20 ↗ mg/dl\nBG 15m: 206 mg/dl\nIOB: 1.25U';
80+
highest.message.should.equal(expectedMessage);
7681

7782
done();
7883
});
@@ -160,4 +165,4 @@ describe('ar2', function ( ) {
160165
}, [], sbx);
161166
});
162167

163-
});
168+
});

tests/boluswizardpreview.test.js

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ describe('boluswizardpreview', function ( ) {
3434

3535
var profile = {
3636
dia: 3
37-
, sens: 90
38-
, target_high: 120
39-
, target_low: 100
37+
, units: ctx.settings.units
38+
, sens: ctx.settings.units === 'mmol' ? 5 : 90
39+
, target_high: ctx.settings.units === 'mmol' ? 6.7 : 120
40+
, target_low: ctx.settings.units === 'mmol' ? 5.6 : 100
4041
};
4142

4243
it('should calculate IOB results correctly with 0 IOB', function (done) {
@@ -50,8 +51,12 @@ describe('boluswizardpreview', function ( ) {
5051

5152
results.effect.should.equal(0);
5253
results.effectDisplay.should.equal(0);
53-
results.outcome.should.equal(100);
54-
results.outcomeDisplay.should.equal(100);
54+
55+
var expectedOutcome =
56+
ctx.settings.units === 'mmol' ? 5.6 : 100;
57+
results.outcome.should.equal(expectedOutcome);
58+
results.outcomeDisplay.should.equal(expectedOutcome);
59+
5560
results.bolusEstimate.should.equal(0);
5661
results.displayLine.should.equal('BWP: 0U');
5762

@@ -65,20 +70,27 @@ describe('boluswizardpreview', function ( ) {
6570

6671
var profile = {
6772
dia: 3
68-
, sens: 50
69-
, target_high: 100
70-
, target_low: 50
73+
, units: ctx.settings.units
74+
, sens: ctx.settings.units === 'mmol' ? 2.8 : 50
75+
, target_high: ctx.settings.units === 'mmol' ? 5.6 : 100
76+
, target_low: ctx.settings.units === 'mmol' ? 2.8 : 50
7177
};
7278

7379
ctx.ddata.profiles = [profile];
7480

7581
var sbx = prepareSandbox();
7682
var results = boluswizardpreview.calc(sbx);
7783

78-
Math.round(results.effect).should.equal(50);
79-
results.effectDisplay.should.equal(50);
80-
Math.round(results.outcome).should.equal(50);
81-
results.outcomeDisplay.should.equal(50);
84+
var expectedEffect =
85+
ctx.settings.units === 'mmol' ? 2.8 : 50;
86+
results.effect.should.equal(expectedEffect);
87+
results.effectDisplay.should.equal(expectedEffect);
88+
89+
var expectedOutcome =
90+
ctx.settings.units === 'mmol' ? 2.8 : 50;
91+
results.outcome.should.equal(expectedOutcome);
92+
results.outcomeDisplay.should.equal(expectedOutcome);
93+
8294
results.bolusEstimate.should.equal(0);
8395
results.displayLine.should.equal('BWP: 0U');
8496

@@ -92,9 +104,10 @@ describe('boluswizardpreview', function ( ) {
92104

93105
var profile = {
94106
dia: 3
95-
, sens: 50
96-
, target_high: 200
97-
, target_low: 100
107+
, units: ctx.settings.units
108+
, sens: ctx.settings.units === 'mmol' ? 2.8 : 50
109+
, target_high: ctx.settings.units === 'mmol' ? 11.1 : 200
110+
, target_low: ctx.settings.units === 'mmol' ? 5.6 : 100
98111
, basal: 1
99112
};
100113

@@ -104,10 +117,16 @@ describe('boluswizardpreview', function ( ) {
104117
var sbx = prepareSandbox();
105118
var results = boluswizardpreview.calc(sbx);
106119

107-
Math.round(results.effect).should.equal(50);
108-
results.effectDisplay.should.equal(50);
109-
Math.round(results.outcome).should.equal(50);
110-
results.outcomeDisplay.should.equal(50);
120+
var expectedResult =
121+
ctx.settings.units === 'mmol' ? 2.8 : 50;
122+
results.effect.should.equal(expectedResult);
123+
results.effectDisplay.should.equal(expectedResult);
124+
125+
var expectedOutcome =
126+
ctx.settings.units === 'mmol' ? 2.8 : 50;
127+
results.outcome.should.equal(expectedOutcome);
128+
results.outcomeDisplay.should.equal(expectedOutcome);
129+
111130
Math.round(results.bolusEstimate).should.equal(-1);
112131
results.displayLine.should.equal('BWP: -1.00U');
113132
results.tempBasalAdjustment.thirtymin.should.equal(-100);
@@ -116,7 +135,7 @@ describe('boluswizardpreview', function ( ) {
116135
done();
117136
});
118137

119-
it('should calculate IOB results correctly with 1.0 U IOB resulting in going low in MMOL', function (done) {
138+
it('should calculate IOB results correctly with 1.0 U IOB resulting in going low in MMOL', function (done) {
120139

121140
// boilerplate for client sandbox running in mmol
122141

@@ -159,8 +178,7 @@ describe('boluswizardpreview', function ( ) {
159178
done();
160179
});
161180

162-
163-
it('should calculate IOB results correctly with 0.45 U IOB resulting in going low in MMOL', function (done) {
181+
it('should calculate IOB results correctly with 0.45 U IOB resulting in going low in MMOL', function (done) {
164182

165183
// boilerplate for client sandbox running in mmol
166184

@@ -230,7 +248,13 @@ describe('boluswizardpreview', function ( ) {
230248
var highest = ctx.notifications.findHighestAlarm();
231249
highest.level.should.equal(ctx.levels.WARN);
232250
highest.title.should.equal('Warning, Check BG, time to bolus?');
233-
highest.message.should.equal('BG Now: 180 +5 ↗ mg/dl\nBG 15m: 187 mg/dl\nBWP: 0.66U');
251+
252+
var expectedMessage =
253+
ctx.settings.units === 'mmol' ?
254+
'BG Now: 10 +0.3 ↗ mmol/L\nBG 15m: 10.4 mmol/L\nBWP: 0.65U' :
255+
'BG Now: 180 +5 ↗ mg/dl\nBG 15m: 187 mg/dl\nBWP: 0.66U';
256+
highest.message.should.equal(expectedMessage);
257+
234258
done();
235259
});
236260

@@ -274,8 +298,11 @@ describe('boluswizardpreview', function ( ) {
274298
});
275299

276300
it('set a pill to the BWP with infos', function (done) {
301+
277302
var ctx = {
278-
settings: {}
303+
settings: {
304+
units: helper.ctx.settings.units
305+
}
279306
, pluginBase: {
280307
updatePillText: function mockedUpdatePillText(plugin, options) {
281308
options.label.should.equal('BWP');

tests/inithelper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const fs = require('fs');
32
const moment = require('moment-timezone');
43
const language = require('../lib/language')(fs);
@@ -7,6 +6,10 @@ const levels = require('../lib/levels');
76

87
function helper() {
98

9+
if (process.env['DISPLAY_UNITS'] && process.env['DISPLAY_UNITS'].toLowerCase().includes('mmol')) {
10+
settings.units = 'mmol';
11+
}
12+
1013
helper.ctx = {
1114
language: language
1215
, settings: settings

tests/iob.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ describe('IOB', function() {
88

99
let ctx = helper.ctx;
1010

11-
ctx.settings = require('../lib/settings')();
12-
1311
var iob = require('../lib/plugins/iob')(ctx);
1412

1513
it('should handle virtAsst requests', function (done) {

tests/pump.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const helper = require('./inithelper')();
66
const moment = helper.ctx.moment;
77

88
var top_ctx = helper.getctx();
9-
top_ctx.settings = require('../lib/settings')();
109
top_ctx.language.set('en');
1110

1211
var env = require('../lib/server/env')();

tests/simplealarms.test.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
var should = require('should');
2-
var levels = require('../lib/levels');
2+
const helper = require('./inithelper')();
33

44
describe('simplealarms', function ( ) {
55
var env = require('../lib/server/env')();
6-
var ctx = {
7-
settings: {}
8-
, language: require('../lib/language')()
9-
, levels: levels
10-
};
6+
var ctx = helper.getctx();
117

128
var simplealarms = require('../lib/plugins/simplealarms')(ctx);
139

@@ -32,14 +28,20 @@ describe('simplealarms', function ( ) {
3228

3329
it('should trigger a warning when above target', function (done) {
3430
ctx.notifications.initRequests();
35-
ctx.ddata.sgvs = [{mills: before, mgdl: 171}, {mills: now, mgdl: 181}];
31+
ctx.ddata.sgvs = [{mills: before, mgdl: 171}, {mills: now, mgdl: 182}];
3632

3733
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
3834
bgnow.setProperties(sbx);
3935
simplealarms.checkNotifications(sbx);
4036
var highest = ctx.notifications.findHighestAlarm();
41-
highest.level.should.equal(levels.WARN);
42-
highest.message.should.equal('BG Now: 181 +10 mg/dl');
37+
highest.level.should.equal(ctx.levels.WARN);
38+
39+
var expectedMessage =
40+
ctx.settings.units === 'mmol' ?
41+
'BG Now: 10.1 +0.6 mmol/L' :
42+
'BG Now: 182 +11 mg/dl';
43+
highest.message.should.equal(expectedMessage);
44+
4345
done();
4446
});
4547

@@ -49,7 +51,7 @@ describe('simplealarms', function ( ) {
4951

5052
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
5153
simplealarms.checkNotifications(sbx);
52-
ctx.notifications.findHighestAlarm().level.should.equal(levels.URGENT);
54+
ctx.notifications.findHighestAlarm().level.should.equal(ctx.levels.URGENT);
5355

5456
done();
5557
});
@@ -60,7 +62,7 @@ describe('simplealarms', function ( ) {
6062

6163
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
6264
simplealarms.checkNotifications(sbx);
63-
ctx.notifications.findHighestAlarm().level.should.equal(levels.WARN);
65+
ctx.notifications.findHighestAlarm().level.should.equal(ctx.levels.WARN);
6466

6567
done();
6668
});
@@ -71,10 +73,10 @@ describe('simplealarms', function ( ) {
7173

7274
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
7375
simplealarms.checkNotifications(sbx);
74-
ctx.notifications.findHighestAlarm().level.should.equal(levels.URGENT);
76+
ctx.notifications.findHighestAlarm().level.should.equal(ctx.levels.URGENT);
7577

7678
done();
7779
});
7880

7981

80-
});
82+
});

tests/timeago.test.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
var should = require('should');
2-
var levels = require('../lib/levels');
32
var times = require('../lib/times');
3+
const helper = require('./inithelper')();
44

55
describe('timeago', function() {
6-
var ctx = {};
7-
ctx.levels = levels;
6+
var ctx = helper.getctx();
87
ctx.ddata = require('../lib/data/ddata')();
98
ctx.notifications = require('../lib/notifications')(env, ctx);
10-
ctx.language = require('../lib/language')();
11-
ctx.settings = require('../lib/settings')();
129
ctx.settings.heartbeat = 0.5; // short heartbeat to speedup tests
1310

1411
var timeago = require('../lib/plugins/timeago')(ctx);
@@ -55,8 +52,14 @@ describe('timeago', function() {
5552
var currentTime = new Date().getTime();
5653

5754
var highest = ctx.notifications.findHighestAlarm('Time Ago');
58-
highest.level.should.equal(levels.WARN);
59-
highest.message.should.equal('Last received: 16 mins ago\nBG Now: 100 mg/dl');
55+
highest.level.should.equal(ctx.levels.WARN);
56+
57+
var expectedMessage =
58+
ctx.settings.units === 'mmol' ?
59+
'Last received: 16 mins ago\nBG Now: 5.6 mmol/L' :
60+
'Last received: 16 mins ago\nBG Now: 100 mg/dl';
61+
highest.message.should.equal(expectedMessage);
62+
6063
done();
6164
});
6265

@@ -67,8 +70,14 @@ describe('timeago', function() {
6770
var sbx = freshSBX();
6871
timeago.checkNotifications(sbx);
6972
var highest = ctx.notifications.findHighestAlarm('Time Ago');
70-
highest.level.should.equal(levels.URGENT);
71-
highest.message.should.equal('Last received: 31 mins ago\nBG Now: 100 mg/dl');
73+
highest.level.should.equal(ctx.levels.URGENT);
74+
75+
var expectedMessage =
76+
ctx.settings.units === 'mmol' ?
77+
'Last received: 31 mins ago\nBG Now: 5.6 mmol/L' :
78+
'Last received: 31 mins ago\nBG Now: 100 mg/dl';
79+
highest.message.should.equal(expectedMessage);
80+
7281
done();
7382
});
7483

tests/utils.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ describe('utils', function ( ) {
88

99
const ctx = helper.getctx();
1010

11-
ctx.settings = {
12-
alarmTimeagoUrgentMins: 30
13-
, alarmTimeagoWarnMins: 15
14-
};
11+
ctx.settings.alarmTimeagoUrgentMins = 30;
12+
ctx.settings.alarmTimeagoWarnMins = 15;
1513

1614
var utils = require('../lib/utils')(ctx);
1715

0 commit comments

Comments
 (0)