forked from nightscout/cgm-remote-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrawbg.test.js
56 lines (39 loc) · 1.36 KB
/
rawbg.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
require('should');
describe('Raw BG', function ( ) {
var ctx = {
settings: { units: 'mg/dl'}
, language: require('../lib/language')()
, pluginBase: {}
};
ctx.language.set('en');
var rawbg = require('../lib/plugins/rawbg')(ctx);
var now = Date.now();
var data = {
sgvs: [{unfiltered: 113680, filtered: 111232, mgdl: 110, noise: 1, mills: now}]
, cals: [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, mills: now}]
};
it('should calculate Raw BG', function (done) {
var sandbox = require('../lib/sandbox')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
sbx.offerProperty = function mockedOfferProperty (name, setter) {
name.should.equal('rawbg');
var result = setter();
result.mgdl.should.equal(113);
result.noiseLabel.should.equal('Clean');
done();
};
rawbg.setProperties(sbx);
});
it('should handle alexa requests', function (done) {
var sandbox = require('../lib/sandbox')();
var sbx = sandbox.clientInit(ctx, Date.now(), data);
rawbg.setProperties(sbx);
rawbg.alexa.intentHandlers.length.should.equal(1);
rawbg.alexa.intentHandlers[0].intentHandler(function next(title, response) {
title.should.equal('Current Raw BG');
response.should.equal('Your raw bg is 113');
done();
}, [], sbx);
});
});