From c0588fa11d1ee92ac9fd79f9ee5d72cb942c333b Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Thu, 18 Jun 2015 18:37:06 -0700 Subject: [PATCH] add back the x field to treatments so they can be used like normal entries --- lib/data.js | 5 +++-- tests/data.test.js | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/data.js b/lib/data.js index 166d8ce7785..cc7025a4d25 100644 --- a/lib/data.js +++ b/lib/data.js @@ -118,9 +118,10 @@ function init(env, ctx) { var tq = {find: {"created_at": {"$gte": new Date(treatment_earliest_data).toISOString()}}}; ctx.treatments.list(tq, function (err, results) { if (!err && results) { - var treatments = []; - treatments = results.map(function (treatment) { + var treatments = results.map(function (treatment) { treatment.created_at = new Date(treatment.created_at).getTime(); + //TODO: #CleanUpDataModel, some code expects x everywhere + treatment.x = treatment.created_at; return treatment; }); diff --git a/tests/data.test.js b/tests/data.test.js index 574db0f8d8e..27370f1fc93 100644 --- a/tests/data.test.js +++ b/tests/data.test.js @@ -22,6 +22,15 @@ describe('Data', function ( ) { delta.sgvs.length.should.equal(1); }); + it('adding one treatment record should return delta with one treatment', function() { + data.treatments = [{sgv: 100, x:100},{sgv: 100, x:99}]; + var newData = data.clone(); + newData.treatments = [{sgv: 100, x:100},{sgv: 100, x:99},{sgv: 100, x:98}]; + var delta = data.calculateDeltaBetweenDatasets(data,newData); + delta.delta.should.equal(true); + delta.treatments.length.should.equal(1); + }); + it('changes to treatments, mbgs and cals should be calculated even if sgvs is not changed', function() { data.sgvs = [{sgv: 100, x:100},{sgv: 100, x:99}]; data.treatments = [{sgv: 100, x:100},{sgv: 100, x:99}];