mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
* Experimental branch that replaces momentjs with dayjs in the client * Revert unintentional change * feat * Turns out dayjs is a no-go, but this has some good restructuring so submitting that
175 lines
5.5 KiB
JavaScript
175 lines
5.5 KiB
JavaScript
'use strict';
|
|
|
|
var should = require('should');
|
|
var times = require('../lib/times');
|
|
const helper = require('./inithelper')();
|
|
|
|
describe('sage', 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 sage = require('../lib/plugins/sensorage')(ctx);
|
|
var sandbox = require('../lib/sandbox')();
|
|
|
|
function prepareSandbox ( ) {
|
|
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
|
|
return sbx;
|
|
}
|
|
|
|
it('set a pill to the current age since start with change', function (done) {
|
|
|
|
var data = {
|
|
sensorTreatments: [
|
|
{eventType: 'Sensor Change', notes: 'Foo', mills: Date.now() - times.days(2).msecs}
|
|
, {eventType: 'Sensor Start', notes: 'Bar', mills: Date.now() - times.days(1).msecs}
|
|
]
|
|
};
|
|
|
|
var ctx = {
|
|
settings: {}
|
|
, pluginBase: {
|
|
updatePillText: function mockedUpdatePillText(plugin, options) {
|
|
|
|
console.log(JSON.stringify(options));
|
|
options.value.should.equal('1d0h');
|
|
options.info[0].label.should.equal('Sensor Insert');
|
|
options.info[1].should.match({ label: 'Duration', value: '2 days 0 hours' });
|
|
options.info[2].should.match({ label: 'Notes', value: 'Foo' });
|
|
options.info[3].label.should.equal('Sensor Start');
|
|
options.info[4].should.match({ label: 'Duration', value: '1 days 0 hours' });
|
|
options.info[5].should.match({ label: 'Notes', value: 'Bar' });
|
|
done();
|
|
}
|
|
}
|
|
};
|
|
ctx.language = require('../lib/language')();
|
|
|
|
var sbx = sandbox.clientInit(ctx, Date.now(), data);
|
|
sage.setProperties(sbx);
|
|
sage.updateVisualisation(sbx);
|
|
|
|
});
|
|
|
|
it('set a pill to the current age since start without change', function (done) {
|
|
|
|
var data = {
|
|
sensorTreatments: [
|
|
{eventType: 'Sensor Start', notes: 'Bar', mills: Date.now() - times.days(3).msecs}
|
|
]
|
|
};
|
|
|
|
var ctx = {
|
|
settings: {}
|
|
, pluginBase: {
|
|
updatePillText: function mockedUpdatePillText(plugin, options) {
|
|
options.value.should.equal('3d0h');
|
|
options.info[0].label.should.equal('Sensor Start');
|
|
options.info[1].should.match({ label: 'Duration', value: '3 days 0 hours' });
|
|
options.info[2].should.match({ label: 'Notes', value: 'Bar' });
|
|
done();
|
|
}
|
|
}
|
|
};
|
|
ctx.language = require('../lib/language')();
|
|
|
|
var sbx = sandbox.clientInit(ctx, Date.now(), data);
|
|
sage.setProperties(sbx);
|
|
sage.updateVisualisation(sbx);
|
|
|
|
});
|
|
|
|
it('set a pill to the current age since change without start', function (done) {
|
|
|
|
var data = {
|
|
sensorTreatments: [
|
|
{eventType: 'Sensor Change', notes: 'Foo', mills: Date.now() - times.days(3).msecs}
|
|
]
|
|
};
|
|
|
|
var ctx = {
|
|
settings: {}
|
|
, pluginBase: {
|
|
updatePillText: function mockedUpdatePillText(plugin, options) {
|
|
options.value.should.equal('3d0h');
|
|
options.info[0].label.should.equal('Sensor Insert');
|
|
options.info[1].should.match({ label: 'Duration', value: '3 days 0 hours' });
|
|
options.info[2].should.match({ label: 'Notes', value: 'Foo' });
|
|
done();
|
|
}
|
|
}
|
|
};
|
|
ctx.language = require('../lib/language')();
|
|
|
|
var sbx = sandbox.clientInit(ctx, Date.now(), data);
|
|
sage.setProperties(sbx);
|
|
sage.updateVisualisation(sbx);
|
|
|
|
});
|
|
|
|
it('set a pill to the current age since change after start', function (done) {
|
|
|
|
var data = {
|
|
sensorTreatments: [
|
|
{eventType: 'Sensor Start', notes: 'Bar', mills: Date.now() - times.days(10).msecs}
|
|
, {eventType: 'Sensor Change', notes: 'Foo', mills: Date.now() - times.days(3).msecs}
|
|
]
|
|
};
|
|
|
|
var ctx = {
|
|
settings: {}
|
|
, pluginBase: {
|
|
updatePillText: function mockedUpdatePillText(plugin, options) {
|
|
options.value.should.equal('3d0h');
|
|
options.info.length.should.equal(3);
|
|
options.info[0].label.should.equal('Sensor Insert');
|
|
options.info[1].should.match({ label: 'Duration', value: '3 days 0 hours' });
|
|
options.info[2].should.match({ label: 'Notes', value: 'Foo' });
|
|
done();
|
|
}
|
|
}
|
|
};
|
|
ctx.language = require('../lib/language')();
|
|
|
|
var sbx = sandbox.clientInit(ctx, Date.now(), data);
|
|
sage.setProperties(sbx);
|
|
sage.updateVisualisation(sbx);
|
|
|
|
});
|
|
|
|
it('trigger an alarm when sensor is 6 days and 22 hours old', function (done) {
|
|
ctx.notifications.initRequests();
|
|
|
|
var before = Date.now() - times.days(6).msecs - times.hours(22).msecs;
|
|
|
|
ctx.ddata.sensorTreatments = [{eventType: 'Sensor Start', mills: before}];
|
|
|
|
var sbx = prepareSandbox();
|
|
sbx.extendedSettings = { 'enableAlerts': true };
|
|
sage.setProperties(sbx);
|
|
sage.checkNotifications(sbx);
|
|
|
|
var highest = ctx.notifications.findHighestAlarm('SAGE');
|
|
highest.level.should.equal(ctx.levels.URGENT);
|
|
highest.title.should.equal('Sensor age 6 days 22 hours');
|
|
done();
|
|
});
|
|
|
|
it('not trigger an alarm when sensor is 6 days and 23 hours old', function (done) {
|
|
ctx.notifications.initRequests();
|
|
|
|
var before = Date.now() - times.days(6).msecs - times.hours(23).msecs;
|
|
|
|
ctx.ddata.sensorTreatments = [{eventType: 'Sensor Start', mills: before}];
|
|
|
|
var sbx = prepareSandbox();
|
|
sbx.extendedSettings = { 'enableAlerts': true };
|
|
sage.setProperties(sbx);
|
|
sage.checkNotifications(sbx);
|
|
|
|
should.not.exist(ctx.notifications.findHighestAlarm('SAGE'));
|
|
done();
|
|
});
|
|
|
|
});
|