Skip to content

Commit

Permalink
Add and validate _userId field on all device data; update test data
Browse files Browse the repository at this point in the history
  • Loading branch information
darinkrauss committed Aug 20, 2016
1 parent ab92310 commit 4008d47
Show file tree
Hide file tree
Showing 28 changed files with 128 additions and 56 deletions.
5 changes: 3 additions & 2 deletions lib/jellyfishService.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,14 @@ function createServer(serverConfig, mongoClient, seagullClient, userApiClient, g
},
function(userId, cb) {
getPrivatePair(userId, function(err, privatePair) {
cb(err, privatePair ? privatePair.id : null);
cb(err, userId, privatePair ? privatePair.id : null);
});
},
function(groupId, cb) {
function(userId, groupId, cb) {
async.mapSeries(
array,
function(obj, cb) {
obj._userId = userId;
obj._groupId = groupId;
dataBroker.addDatum(obj, function(err){
if (err != null) {
Expand Down
9 changes: 6 additions & 3 deletions lib/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ exports.isArrayWithValueSchema = function(schema){
};
};

exports.requireXOR = function(datum, field1, field2) {
if ((datum[field1] == null && datum[field2] == null) || (datum[field1] != null && datum[field2] != null)) {
exports.requireXOR = function(datum, field1, field2) {
if ((datum[field1] == null && datum[field2] == null) || (datum[field1] != null && datum[field2] != null)) {
throw except.IAE('should contain either %s or %s', field1, field2);
}
return true;
Expand Down Expand Up @@ -384,6 +384,9 @@ exports.makeHandler = function(key, spec) {
a thing from transformers, 'cause it's nice when things line up like that.
*/
function decepticon(datum, cb) {
if (datum._userId == null) {
return cb(new Error('_userId must be set on a datum'));
}
if (datum._groupId == null) {
return cb(new Error('_groupId must be set on a datum'));
}
Expand Down Expand Up @@ -501,4 +504,4 @@ exports.makeId = function(datum) {
}

return exports.generateId(datum, idFields);
};
};
2 changes: 2 additions & 0 deletions lib/streamDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ module.exports = function(mongoClient){
var self = this;

pre.hasProperty(datum, 'id');
pre.hasProperty(datum, '_userId');
pre.hasProperty(datum, '_groupId');

datum = _.clone(datum);
Expand All @@ -180,6 +181,7 @@ module.exports = function(mongoClient){
},
updateDatum: function(datum, cb) {
pre.hasProperty(datum, 'id');
pre.hasProperty(datum, '_userId');
pre.hasProperty(datum, '_groupId');
updateDatumInternal(datum, 0, cb);
},
Expand Down
11 changes: 10 additions & 1 deletion test/api/basal/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"duration": 21600000,
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "kmm427pfbrc6rugtmbuli8j4q61u17uk",
"_version": 0,
Expand All @@ -29,6 +30,7 @@
"duration": 21600000,
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "cjou7vscvp8ogv34d6vejootulqfn3jd",
"_version": 0,
Expand All @@ -47,6 +49,7 @@
"duration": 10800000,
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "cjou7vscvp8ogv34d6vejootulqfn3jd",
"_version": 1,
Expand Down Expand Up @@ -78,6 +81,7 @@
"deviceId": "tools",
"uploadId": "tools"
},
"_userId": "abcd",
"_groupId": "1234",
"rate": 1,
"id": "tn33bjb0241j9qh4jg9vdnf1g6k1g9r8",
Expand Down Expand Up @@ -109,6 +113,7 @@
"deviceId": "tools",
"uploadId": "tools"
},
"_userId": "abcd",
"_groupId": "1234",
"rate": 1,
"id": "tn33bjb0241j9qh4jg9vdnf1g6k1g9r8",
Expand Down Expand Up @@ -141,6 +146,7 @@
"deviceId": "tools",
"uploadId": "tools"
},
"_userId": "abcd",
"_groupId": "1234",
"rate": 0.5,
"id": "ga58m84ggkscldj30lehrg74n313skcj",
Expand All @@ -160,6 +166,7 @@
"duration": 21600000,
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "lsqqotp92j1d25d3d3ac53dsh6rgjg94",
"_version": 0,
Expand All @@ -178,6 +185,7 @@
"duration": 14400000,
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "lsqqotp92j1d25d3d3ac53dsh6rgjg94",
"_version": 1,
Expand All @@ -202,10 +210,11 @@
"duration": 18000000,
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "kftn188l8rjuvma3qkd3iqg34t0plajp",
"_version": 0,
"_active": true,
"_schemaVersion": 0
}
]
]
6 changes: 5 additions & 1 deletion test/api/bolusAndWizard/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"normal": 2.5,
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "oi4effqrtdsk8g353dcstbeg06pip5kp",
"_version": 0,
Expand All @@ -25,6 +26,7 @@
"normal": 1.5,
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "oi4effqrtdsk8g353dcstbeg06pip5kp",
"_version": 1,
Expand All @@ -42,6 +44,7 @@
"normal": 3.5,
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "hvnk1ngku6sqcpgav3t08f0m8lmhk6hv",
"_version": 0,
Expand Down Expand Up @@ -69,10 +72,11 @@
"deviceId": "tools",
"uploadId": "tools",
"bolus": "hvnk1ngku6sqcpgav3t08f0m8lmhk6hv",
"_userId": "abcd",
"_groupId": "1234",
"id": "vnputuqq0jtfhvi8tm7jinum5s24kkdq",
"_version": 0,
"_active": true,
"_schemaVersion": 0
}
]
]
6 changes: 5 additions & 1 deletion test/api/cbg/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"units": "mmol/L",
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "eb12p6h892pmd0hhccpt2r17muc407o0",
"_version": 0,
Expand All @@ -25,6 +26,7 @@
"units": "mmol/L",
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "ha2ogn1kenqqhseed504sqnanhnclg5s",
"_version": 0,
Expand All @@ -42,6 +44,7 @@
"units": "mmol/L",
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "i922lobl3kron3t81pjap31anopkspvb",
"_version": 0,
Expand All @@ -55,10 +58,11 @@
"units": "mmol/L",
"deviceId": "DexHealthKit_Dexcom:com.dexcom.Share2:3.0.4.17",
"uploadId": "upid_HealthKit_org.tidepool.blipnotes:1.1:242_2016-03-10T10:25:55-06:00",
"_userId": "abcd",
"_groupId": "1234",
"id": "nsikjhfaprplpq78hc7di2lu5qpt1e3k",
"_version": 0,
"_active": true,
"_schemaVersion": 0
}
]
]
3 changes: 2 additions & 1 deletion test/api/cgmSettings/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"rate": 0.16652243973136602
}
},
"_userId": "abcd",
"_groupId": "1234",
"id": "grop2783hkosd5lbv4sr9047a74vggch",
"_version": 0,
"_active": true,
"_schemaVersion": 0
}
]
]
8 changes: 7 additions & 1 deletion test/api/deviceEvent/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"timezoneOffset": 0,
"conversionOffset": 0,
"status": "qdmhpmdd2v5v8uuv6otmqp7sjqlmb1cr",
"_userId": "abcd",
"_groupId": "1234",
"id": "64h7169livcae35c10d32ai721ugse79",
"_version": 0,
Expand All @@ -26,6 +27,7 @@
"timezoneOffset": 0,
"conversionOffset": 0,
"status": "qdmhpmdd2v5v8uuv6otmqp7sjqlmb1cr",
"_userId": "abcd",
"_groupId": "1234",
"id": "f4t0qjh45tgjep3vjsm2cn0isqg5u6ie",
"_version": 0,
Expand All @@ -45,6 +47,7 @@
"time": "2014-07-28T00:07:10.000Z",
"timezoneOffset": 0,
"conversionOffset": 0,
"_userId": "abcd",
"_groupId": "1234",
"annotations": [
{
Expand All @@ -70,6 +73,7 @@
"time": "2014-07-28T00:07:10.000Z",
"timezoneOffset": 0,
"conversionOffset": 0,
"_userId": "abcd",
"_groupId": "1234",
"id": "qdmhpmdd2v5v8uuv6otmqp7sjqlmb1cr",
"_version": 1,
Expand All @@ -88,6 +92,7 @@
"time": "2014-07-28T00:12:03.000Z",
"timezoneOffset": 0,
"conversionOffset": 0,
"_userId": "abcd",
"_groupId": "1234",
"id": "ep1kqd57okpgke6c0g7al5j1f80cqg5m",
"_version": 0,
Expand All @@ -112,10 +117,11 @@
"conversionOffset": 0,
"deviceId": "Paradigm Revel - 723",
"uploadId": "test",
"_userId": "abcd",
"_groupId": "1234",
"id": "j80h9aqiioe8d8e41sh4ujf7ek28rppi",
"_version": 0,
"_active": true,
"_schemaVersion": 0
}
]
]
11 changes: 7 additions & 4 deletions test/api/ingestionApiTest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
* == BSD2 LICENSE ==
* Copyright (c) 2014, Tidepool Project
*
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the associated License, which is identical to the BSD 2-Clause
* License as published by the Open Source Initiative at opensource.org.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the License for more details.
*
*
* You should have received a copy of the License along with this program; if
* not, you can obtain one from Tidepool Project at tidepool.org.
* == BSD2 LICENSE ==
Expand All @@ -32,6 +32,7 @@ var mongoClient = require('../../lib/mongo/mongoClient.js')(
var streamDAO = require('../../lib/streamDAO.js')(mongoClient);
var dataBroker = require('../../lib/dataBroker.js')(streamDAO);

var userId = "abcd";
var groupId = "1234";

describe('ingestion API', function () {
Expand All @@ -55,6 +56,7 @@ describe('ingestion API', function () {
async.mapSeries(
input,
function(e, cb){
e._userId = userId;
e._groupId = groupId;
dataBroker.addDatum(e, cb);
},
Expand All @@ -66,7 +68,7 @@ describe('ingestion API', function () {
mongoClient.withCollection('deviceData', done, function(coll, cb){
coll.find().sort({"time": 1, "id": 1, "_version": 1}).toArray(function(err, results){
expect(results.map(function(e){ return _.omit(e, 'createdTime', 'modifiedTime', "_id", '_archivedTime'); }))
.deep.equals(output.map(function(e){ e._groupId = groupId; return e; }));
.deep.equals(output.map(function(e){ e._userId = userId; e._groupId = groupId; return e; }));
cb(err);
});
});
Expand All @@ -80,6 +82,7 @@ describe('ingestion API', function () {
async.mapSeries(
badInput,
function(e, cb){
e._userId = userId;
e._groupId = groupId;
dataBroker.addDatum(e, cb);
},
Expand Down
4 changes: 3 additions & 1 deletion test/api/ketones/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"units": "mmol/L",
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "si9lrlao50l4qi0hcc8bc5siaaq1se4a",
"_version": 0,
Expand All @@ -24,10 +25,11 @@
"value": "moderate",
"deviceId": "tools",
"uploadId": "tools",
"_userId": "abcd",
"_groupId": "1234",
"id": "d3o9aav2c4b1tc8purlb493ff82c4q8p",
"_version": 0,
"_active": true,
"_schemaVersion": 0
}
]
]
3 changes: 2 additions & 1 deletion test/api/pumpSettings/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@
"start": 18000000
}
],
"_userId": "abcd",
"_groupId": "1234",
"id": "254a6gvhik3oucn5p5fblabem9rckbvg",
"_version": 0,
"_active": true,
"_schemaVersion": 0
}
]
]
Loading

0 comments on commit 4008d47

Please sign in to comment.