mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
also dedupe and process data within a posted array more treatment api tests
144 lines
4.8 KiB
JavaScript
144 lines
4.8 KiB
JavaScript
'use strict';
|
|
|
|
var request = require('supertest');
|
|
var should = require('should');
|
|
|
|
describe('Treatment API', function ( ) {
|
|
this.timeout(10000);
|
|
var self = this;
|
|
|
|
var api = require('../lib/api/');
|
|
beforeEach(function (done) {
|
|
process.env.API_SECRET = 'this is my long pass phrase';
|
|
self.env = require('../env')();
|
|
self.env.settings.enable = ['careportal'];
|
|
this.wares = require('../lib/middleware/')(self.env);
|
|
self.app = require('express')();
|
|
self.app.enable('api');
|
|
require('../lib/bootevent')(self.env).boot(function booted(ctx) {
|
|
self.ctx = ctx;
|
|
self.app.use('/api', api(self.env, ctx));
|
|
done();
|
|
});
|
|
});
|
|
|
|
after(function () {
|
|
delete process.env.API_SECRET;
|
|
});
|
|
|
|
it('post single treatments', function (done) {
|
|
var doneCalled = false;
|
|
|
|
self.ctx.bus.on('data-loaded', function dataWasLoaded ( ) {
|
|
self.ctx.ddata.treatments.length.should.equal(3);
|
|
self.ctx.ddata.treatments[0].mgdl.should.equal(100);
|
|
should.not.exist(self.ctx.ddata.treatments[0].eventTime);
|
|
should.not.exist(self.ctx.ddata.treatments[0].notes);
|
|
|
|
should.not.exist(self.ctx.ddata.treatments[1].eventTime);
|
|
should.not.exist(self.ctx.ddata.treatments[1].glucose);
|
|
should.not.exist(self.ctx.ddata.treatments[1].glucoseType);
|
|
should.not.exist(self.ctx.ddata.treatments[1].units);
|
|
self.ctx.ddata.treatments[1].insulin.should.equal(2);
|
|
self.ctx.ddata.treatments[2].carbs.should.equal(30);
|
|
|
|
//if travis is slow the 2 posts take long enough that 2 data-loaded events are emitted
|
|
if (!doneCalled) { done(); }
|
|
|
|
doneCalled = true;
|
|
|
|
});
|
|
|
|
self.ctx.treatments().remove({ }, function ( ) {
|
|
request(self.app)
|
|
.post('/api/treatments/')
|
|
.set('api-secret', self.env.api_secret || '')
|
|
.send({eventType: 'BG Check', glucose: 100, preBolus: '0', glucoseType: 'Finger', units: 'mg/dl', notes: ''})
|
|
.expect(200)
|
|
.end(function (err) {
|
|
if (err) {
|
|
done(err);
|
|
}
|
|
});
|
|
|
|
request(self.app)
|
|
.post('/api/treatments/')
|
|
.set('api-secret', self.env.api_secret || '')
|
|
.send({eventType: 'Meal Bolus', carbs: '30', insulin: '2.00', preBolus: '15', glucoseType: 'Finger', units: 'mg/dl'})
|
|
.expect(200)
|
|
.end(function (err) {
|
|
if (err) {
|
|
done(err);
|
|
}
|
|
});
|
|
|
|
});
|
|
});
|
|
|
|
it('post a treatment array', function (done) {
|
|
|
|
self.ctx.bus.on('data-loaded', function dataWasLoaded ( ) {
|
|
self.ctx.ddata.treatments.length.should.equal(3);
|
|
self.ctx.ddata.treatments[0].mgdl.should.equal(100);
|
|
should.not.exist(self.ctx.ddata.treatments[0].eventTime);
|
|
should.not.exist(self.ctx.ddata.treatments[0].notes);
|
|
|
|
should.not.exist(self.ctx.ddata.treatments[1].eventTime);
|
|
should.not.exist(self.ctx.ddata.treatments[1].glucose);
|
|
should.not.exist(self.ctx.ddata.treatments[1].glucoseType);
|
|
should.not.exist(self.ctx.ddata.treatments[1].units);
|
|
self.ctx.ddata.treatments[1].insulin.should.equal(2);
|
|
self.ctx.ddata.treatments[2].carbs.should.equal(30);
|
|
|
|
done();
|
|
});
|
|
|
|
self.ctx.treatments().remove({ }, function ( ) {
|
|
request(self.app)
|
|
.post('/api/treatments/')
|
|
.set('api-secret', self.env.api_secret || '')
|
|
.send([
|
|
{eventType: 'BG Check', glucose: 100, preBolus: '0', glucoseType: 'Finger', units: 'mg/dl', notes: ''}
|
|
, {eventType: 'Meal Bolus', carbs: '30', insulin: '2.00', preBolus: '15', glucoseType: 'Finger', units: 'mg/dl'}
|
|
])
|
|
.expect(200)
|
|
.end(function (err) {
|
|
if (err) {
|
|
done(err);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
it('post a treatment array and dedupe', function (done) {
|
|
|
|
self.ctx.bus.on('data-loaded', function dataWasLoaded ( ) {
|
|
self.ctx.ddata.treatments.length.should.equal(1);
|
|
self.ctx.ddata.treatments[0].mgdl.should.equal(100);
|
|
done();
|
|
});
|
|
|
|
self.ctx.treatments().remove({ }, function ( ) {
|
|
var now = (new Date()).toISOString();
|
|
request(self.app)
|
|
.post('/api/treatments/')
|
|
.set('api-secret', self.env.api_secret || '')
|
|
.send([
|
|
{eventType: 'BG Check', glucose: 100, created_at: now}
|
|
, {eventType: 'BG Check', glucose: 100, created_at: now}
|
|
, {eventType: 'BG Check', glucose: 100, created_at: now}
|
|
, {eventType: 'BG Check', glucose: 100, created_at: now}
|
|
, {eventType: 'BG Check', glucose: 100, created_at: now}
|
|
, {eventType: 'BG Check', glucose: 100, created_at: now}
|
|
, {eventType: 'BG Check', glucose: 100, created_at: now}
|
|
, {eventType: 'BG Check', glucose: 100, created_at: now}
|
|
])
|
|
.expect(200)
|
|
.end(function (err) {
|
|
if (err) {
|
|
done(err);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}); |