-
Notifications
You must be signed in to change notification settings - Fork 71.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #718 from nightscout/wip/treatment-tests
treatment tests
- Loading branch information
Showing
4 changed files
with
127 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
var request = require('supertest'); | ||
require('should'); | ||
|
||
describe('Treatment API', function ( ) { | ||
var self = this; | ||
|
||
var api = require('../lib/api/'); | ||
before(function (done) { | ||
process.env.API_SECRET = 'this is my long pass phrase'; | ||
self.env = require('../env')(); | ||
self.env.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 a some treatments', function (done) { | ||
self.ctx.bus.on('data-loaded', function dataWasLoaded ( ) { | ||
self.ctx.data.treatments.length.should.equal(3); | ||
self.ctx.data.treatments[0].mgdl.should.equal(100); | ||
|
||
self.ctx.data.treatments[1].mgdl.should.equal(100); | ||
self.ctx.data.treatments[1].insulin.should.equal('2.00'); | ||
self.ctx.data.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, glucoseType: 'Finger', units: 'mg/dl'}) | ||
.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, glucose: 100, glucoseType: 'Finger', units: 'mg/dl'}) | ||
.expect(200) | ||
.end(function (err) { | ||
if (err) { | ||
done(err); | ||
} | ||
}); | ||
|
||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var request = require('supertest'); | ||
require('should'); | ||
|
||
describe('Throttle', function ( ) { | ||
var self = this; | ||
|
||
var api = require('../lib/api/'); | ||
before(function (done) { | ||
process.env.API_SECRET = 'this is my long pass phrase'; | ||
self.env = require('../env')(); | ||
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('only update once when there are multiple posts', function (done) { | ||
|
||
//if the data-loaded event is triggered more than once the test will fail | ||
self.ctx.bus.on('data-loaded', function dataWasLoaded ( ) { | ||
done(); | ||
}); | ||
|
||
function post () { | ||
request(self.app) | ||
.post('/api/entries/') | ||
.set('api-secret', self.env.api_secret || '') | ||
.send({type: 'sgv', sgv: 100, date: Date.now()}) | ||
.expect(200) | ||
.end(function(err) { | ||
if (err) { | ||
done(err); | ||
} | ||
}); | ||
} | ||
|
||
_.times(10, post); | ||
}); | ||
|
||
}); |