Files
cgm-remote-monitor/tests/insulinage.test.js
T
Sulka HaroandGitHub cb33193e08 Server-side localization fixes, better speech api use (#3724)
* Adds API to plugin manager that calls plugins to visualize alarms

* Refactoring how the translation object is managed after discovering every server-side plugin had it's own instance of the translations and the language code wasn't propagated to any code that generated alarms

* Add more missing translations

* Some more localization fixes
Update Finnish to 100% localized
Change Mongo connection to not stop retrying connecting

* Better scaling for mmol
Fix bug in detecting new BG values

* Delta calculation was the wrong way round :D

* add missing dutch translations

* Have tests bail early & tell Mocha to exit at the end of the run

* Try if Travis likes running tests one by one better

* Enable blocking IO for Travis
2018-07-27 16:04:07 +03:00

97 lines
3.0 KiB
JavaScript

'use strict';
require('should');
var levels = require('../lib/levels');
describe('insulinage', function ( ) {
var env = require('../env')();
var ctx = {};
ctx.ddata = require('../lib/data/ddata')();
ctx.notifications = require('../lib/notifications')(env, ctx);
ctx.language = require('../lib/language')();
var iage = require('../lib/plugins/insulinage')(ctx);
var sandbox = require('../lib/sandbox')();
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 insulin age', function (done) {
var data = {
insulinchangeTreatments: [
{eventType: 'Insulin Change', notes: 'Foo', mills: Date.now() - 48 * 60 * 60000}
, {eventType: 'Insulin Change', notes: 'Bar', mills: Date.now() - 24 * 60 * 60000}
]
};
var ctx = {
settings: {}
, pluginBase: {
updatePillText: function mockedUpdatePillText(plugin, options) {
options.value.should.equal('1d0h');
options.info[1].value.should.equal('Bar');
done();
}
}
};
ctx.language = require('../lib/language')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
iage.setProperties(sbx);
iage.updateVisualisation(sbx);
});
it('set a pill to the current insulin age', function (done) {
var data = {
insulinchangeTreatments: [
{eventType: 'Insulin Change', notes: 'Foo', mills: Date.now() - 48 * 60 * 60000}
, {eventType: 'Insulin 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);
iage.setProperties(sbx);
iage.updateVisualisation(sbx);
});
it('trigger a warning when insulin is 48 hours old', function (done) {
ctx.notifications.initRequests();
var before = Date.now() - (48 * 60 * 60 * 1000);
ctx.ddata.insulinchangeTreatments = [{eventType: 'Insulin Change', mills: before}];
var sbx = prepareSandbox();
sbx.extendedSettings = { 'enableAlerts': 'TRUE' };
iage.setProperties(sbx);
iage.checkNotifications(sbx);
var highest = ctx.notifications.findHighestAlarm('IAGE');
highest.level.should.equal(levels.WARN);
highest.title.should.equal('Insulin reservoir age 48 hours');
done();
});
});