mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
* * Simplified bundling to just one bundle * Removed cache invalidation token from bundling * Generate strong persistent random string on deploy to use for JWT signing * WIP: moving api-secret and JWT signing to a separate centralized security component * Moved some server components away from project root * Fix issues reported by linter * Ignore detect-object-injection everywhere but the client * Make admin message button red * Remove alarms for some security alerts on code * api_secret is now fully contained in the enclave
80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
var should = require('should');
|
|
var levels = require('../lib/levels');
|
|
|
|
describe('simplealarms', function ( ) {
|
|
var env = require('../lib/server/env')();
|
|
var ctx = {
|
|
settings: {}
|
|
, language: require('../lib/language')()
|
|
, levels: levels
|
|
};
|
|
|
|
var simplealarms = require('../lib/plugins/simplealarms')(ctx);
|
|
|
|
ctx.ddata = require('../lib/data/ddata')();
|
|
ctx.notifications = require('../lib/notifications')(env, ctx);
|
|
var bgnow = require('../lib/plugins/bgnow')(ctx);
|
|
|
|
var now = Date.now();
|
|
var before = now - (5 * 60 * 1000);
|
|
|
|
|
|
it('Not trigger an alarm when in range', function (done) {
|
|
ctx.notifications.initRequests();
|
|
ctx.ddata.sgvs = [{mills: now, mgdl: 100}];
|
|
|
|
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
|
|
simplealarms.checkNotifications(sbx);
|
|
should.not.exist(ctx.notifications.findHighestAlarm());
|
|
|
|
done();
|
|
});
|
|
|
|
it('should trigger a warning when above target', function (done) {
|
|
ctx.notifications.initRequests();
|
|
ctx.ddata.sgvs = [{mills: before, mgdl: 171}, {mills: now, mgdl: 181}];
|
|
|
|
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');
|
|
done();
|
|
});
|
|
|
|
it('should trigger a urgent alarm when really high', function (done) {
|
|
ctx.notifications.initRequests();
|
|
ctx.ddata.sgvs = [{mills: now, mgdl: 400}];
|
|
|
|
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
|
|
simplealarms.checkNotifications(sbx);
|
|
ctx.notifications.findHighestAlarm().level.should.equal(levels.URGENT);
|
|
|
|
done();
|
|
});
|
|
|
|
it('should trigger a warning when below target', function (done) {
|
|
ctx.notifications.initRequests();
|
|
ctx.ddata.sgvs = [{mills: now, mgdl: 70}];
|
|
|
|
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
|
|
simplealarms.checkNotifications(sbx);
|
|
ctx.notifications.findHighestAlarm().level.should.equal(levels.WARN);
|
|
|
|
done();
|
|
});
|
|
|
|
it('should trigger a urgent alarm when really low', function (done) {
|
|
ctx.notifications.initRequests();
|
|
ctx.ddata.sgvs = [{mills: now, mgdl: 40}];
|
|
|
|
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
|
|
simplealarms.checkNotifications(sbx);
|
|
ctx.notifications.findHighestAlarm().level.should.equal(levels.URGENT);
|
|
|
|
done();
|
|
});
|
|
|
|
|
|
}); |