Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tests/ar2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ describe('ar2', function ( ) {
var highest = ctx.notifications.findHighestAlarm();
highest.level.should.equal(helper.ctx.levels.WARN);
highest.title.should.equal('Warning, HIGH predicted');
highest.message.should.equal('BG Now: 170 +20 ↗ mg/dl\nBG 15m: 206 mg/dl\nIOB: 1.25U');

var expectedMessage =
ctx.settings.units === 'mmol' ?
'BG Now: 9.4 +1.1 ↗ mmol/L\nBG 15m: 11.4 mmol/L\nIOB: 1.25U' :
'BG Now: 170 +20 ↗ mg/dl\nBG 15m: 206 mg/dl\nIOB: 1.25U';
highest.message.should.equal(expectedMessage);

done();
});
Expand Down Expand Up @@ -160,4 +165,4 @@ describe('ar2', function ( ) {
}, [], sbx);
});

});
});
75 changes: 51 additions & 24 deletions tests/boluswizardpreview.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ describe('boluswizardpreview', function ( ) {

var profile = {
dia: 3
, sens: 90
, target_high: 120
, target_low: 100
, units: ctx.settings.units
, sens: ctx.settings.units === 'mmol' ? 5 : 90
, target_high: ctx.settings.units === 'mmol' ? 6.7 : 120
, target_low: ctx.settings.units === 'mmol' ? 5.6 : 100
};

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

results.effect.should.equal(0);
results.effectDisplay.should.equal(0);
results.outcome.should.equal(100);
results.outcomeDisplay.should.equal(100);

var expectedOutcome =
ctx.settings.units === 'mmol' ? 5.6 : 100;
results.outcome.should.equal(expectedOutcome);
results.outcomeDisplay.should.equal(expectedOutcome);

results.bolusEstimate.should.equal(0);
results.displayLine.should.equal('BWP: 0U');

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

var profile = {
dia: 3
, sens: 50
, target_high: 100
, target_low: 50
, units: ctx.settings.units
, sens: ctx.settings.units === 'mmol' ? 2.8 : 50
, target_high: ctx.settings.units === 'mmol' ? 5.6 : 100
, target_low: ctx.settings.units === 'mmol' ? 2.8 : 50
};

ctx.ddata.profiles = [profile];

var sbx = prepareSandbox();
var results = boluswizardpreview.calc(sbx);

Math.round(results.effect).should.equal(50);
results.effectDisplay.should.equal(50);
Math.round(results.outcome).should.equal(50);
results.outcomeDisplay.should.equal(50);
var expectedEffect =
ctx.settings.units === 'mmol' ? 2.8 : 50;
results.effect.should.equal(expectedEffect);
results.effectDisplay.should.equal(expectedEffect);

var expectedOutcome =
ctx.settings.units === 'mmol' ? 2.8 : 50;
results.outcome.should.equal(expectedOutcome);
results.outcomeDisplay.should.equal(expectedOutcome);

results.bolusEstimate.should.equal(0);
results.displayLine.should.equal('BWP: 0U');

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

var profile = {
dia: 3
, sens: 50
, target_high: 200
, target_low: 100
, units: ctx.settings.units
, sens: ctx.settings.units === 'mmol' ? 2.8 : 50
, target_high: ctx.settings.units === 'mmol' ? 11.1 : 200
, target_low: ctx.settings.units === 'mmol' ? 5.6 : 100
, basal: 1
};

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

Math.round(results.effect).should.equal(50);
results.effectDisplay.should.equal(50);
Math.round(results.outcome).should.equal(50);
results.outcomeDisplay.should.equal(50);
var expectedResult =
ctx.settings.units === 'mmol' ? 2.8 : 50;
results.effect.should.equal(expectedResult);
results.effectDisplay.should.equal(expectedResult);

var expectedOutcome =
ctx.settings.units === 'mmol' ? 2.8 : 50;
results.outcome.should.equal(expectedOutcome);
results.outcomeDisplay.should.equal(expectedOutcome);

Math.round(results.bolusEstimate).should.equal(-1);
results.displayLine.should.equal('BWP: -1.00U');
results.tempBasalAdjustment.thirtymin.should.equal(-100);
Expand All @@ -116,7 +135,7 @@ describe('boluswizardpreview', function ( ) {
done();
});

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

// boilerplate for client sandbox running in mmol

Expand Down Expand Up @@ -159,8 +178,7 @@ describe('boluswizardpreview', function ( ) {
done();
});


it('should calculate IOB results correctly with 0.45 U IOB resulting in going low in MMOL', function (done) {
it('should calculate IOB results correctly with 0.45 U IOB resulting in going low in MMOL', function (done) {

// boilerplate for client sandbox running in mmol

Expand Down Expand Up @@ -230,7 +248,13 @@ describe('boluswizardpreview', function ( ) {
var highest = ctx.notifications.findHighestAlarm();
highest.level.should.equal(ctx.levels.WARN);
highest.title.should.equal('Warning, Check BG, time to bolus?');
highest.message.should.equal('BG Now: 180 +5 ↗ mg/dl\nBG 15m: 187 mg/dl\nBWP: 0.66U');

var expectedMessage =
ctx.settings.units === 'mmol' ?
'BG Now: 10 +0.3 ↗ mmol/L\nBG 15m: 10.4 mmol/L\nBWP: 0.65U' :
'BG Now: 180 +5 ↗ mg/dl\nBG 15m: 187 mg/dl\nBWP: 0.66U';
highest.message.should.equal(expectedMessage);

done();
});

Expand Down Expand Up @@ -274,8 +298,11 @@ describe('boluswizardpreview', function ( ) {
});

it('set a pill to the BWP with infos', function (done) {

var ctx = {
settings: {}
settings: {
units: helper.ctx.settings.units
}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
options.label.should.equal('BWP');
Expand Down
5 changes: 4 additions & 1 deletion tests/inithelper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const fs = require('fs');
const moment = require('moment-timezone');
const language = require('../lib/language')(fs);
Expand All @@ -7,6 +6,10 @@ const levels = require('../lib/levels');

function helper() {

if (process.env['DISPLAY_UNITS'] && process.env['DISPLAY_UNITS'].toLowerCase().includes('mmol')) {
settings.units = 'mmol';
}

helper.ctx = {
language: language
, settings: settings
Expand Down
2 changes: 0 additions & 2 deletions tests/iob.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ describe('IOB', function() {

let ctx = helper.ctx;

ctx.settings = require('../lib/settings')();

var iob = require('../lib/plugins/iob')(ctx);

it('should handle virtAsst requests', function (done) {
Expand Down
1 change: 0 additions & 1 deletion tests/pump.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const helper = require('./inithelper')();
const moment = helper.ctx.moment;

var top_ctx = helper.getctx();
top_ctx.settings = require('../lib/settings')();
top_ctx.language.set('en');

var env = require('../lib/server/env')();
Expand Down
28 changes: 15 additions & 13 deletions tests/simplealarms.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
var should = require('should');
var levels = require('../lib/levels');
const helper = require('./inithelper')();

describe('simplealarms', function ( ) {
var env = require('../lib/server/env')();
var ctx = {
settings: {}
, language: require('../lib/language')()
, levels: levels
};
var ctx = helper.getctx();

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

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

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

var sbx = require('../lib/sandbox')().serverInit(env, ctx);
bgnow.setProperties(sbx);
simplealarms.checkNotifications(sbx);
var highest = ctx.notifications.findHighestAlarm();
highest.level.should.equal(levels.WARN);
highest.message.should.equal('BG Now: 181 +10 mg/dl');
highest.level.should.equal(ctx.levels.WARN);

var expectedMessage =
ctx.settings.units === 'mmol' ?
'BG Now: 10.1 +0.6 mmol/L' :
'BG Now: 182 +11 mg/dl';
highest.message.should.equal(expectedMessage);

done();
});

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

var sbx = require('../lib/sandbox')().serverInit(env, ctx);
simplealarms.checkNotifications(sbx);
ctx.notifications.findHighestAlarm().level.should.equal(levels.URGENT);
ctx.notifications.findHighestAlarm().level.should.equal(ctx.levels.URGENT);

done();
});
Expand All @@ -60,7 +62,7 @@ describe('simplealarms', function ( ) {

var sbx = require('../lib/sandbox')().serverInit(env, ctx);
simplealarms.checkNotifications(sbx);
ctx.notifications.findHighestAlarm().level.should.equal(levels.WARN);
ctx.notifications.findHighestAlarm().level.should.equal(ctx.levels.WARN);

done();
});
Expand All @@ -71,10 +73,10 @@ describe('simplealarms', function ( ) {

var sbx = require('../lib/sandbox')().serverInit(env, ctx);
simplealarms.checkNotifications(sbx);
ctx.notifications.findHighestAlarm().level.should.equal(levels.URGENT);
ctx.notifications.findHighestAlarm().level.should.equal(ctx.levels.URGENT);

done();
});


});
});
27 changes: 18 additions & 9 deletions tests/timeago.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
var should = require('should');
var levels = require('../lib/levels');
var times = require('../lib/times');
const helper = require('./inithelper')();

describe('timeago', function() {
var ctx = {};
ctx.levels = levels;
var ctx = helper.getctx();
ctx.ddata = require('../lib/data/ddata')();
ctx.notifications = require('../lib/notifications')(env, ctx);
ctx.language = require('../lib/language')();
ctx.settings = require('../lib/settings')();
ctx.settings.heartbeat = 0.5; // short heartbeat to speedup tests

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

var highest = ctx.notifications.findHighestAlarm('Time Ago');
highest.level.should.equal(levels.WARN);
highest.message.should.equal('Last received: 16 mins ago\nBG Now: 100 mg/dl');
highest.level.should.equal(ctx.levels.WARN);

var expectedMessage =
ctx.settings.units === 'mmol' ?
'Last received: 16 mins ago\nBG Now: 5.6 mmol/L' :
'Last received: 16 mins ago\nBG Now: 100 mg/dl';
highest.message.should.equal(expectedMessage);

done();
});

Expand All @@ -67,8 +70,14 @@ describe('timeago', function() {
var sbx = freshSBX();
timeago.checkNotifications(sbx);
var highest = ctx.notifications.findHighestAlarm('Time Ago');
highest.level.should.equal(levels.URGENT);
highest.message.should.equal('Last received: 31 mins ago\nBG Now: 100 mg/dl');
highest.level.should.equal(ctx.levels.URGENT);

var expectedMessage =
ctx.settings.units === 'mmol' ?
'Last received: 31 mins ago\nBG Now: 5.6 mmol/L' :
'Last received: 31 mins ago\nBG Now: 100 mg/dl';
highest.message.should.equal(expectedMessage);

done();
});

Expand Down
6 changes: 2 additions & 4 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ describe('utils', function ( ) {

const ctx = helper.getctx();

ctx.settings = {
alarmTimeagoUrgentMins: 30
, alarmTimeagoWarnMins: 15
};
ctx.settings.alarmTimeagoUrgentMins = 30;
ctx.settings.alarmTimeagoWarnMins = 15;

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

Expand Down