mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
Handle UUID treatment ids in v1 API
This commit is contained in:
@@ -246,4 +246,113 @@ describe('Treatment API', function ( ) {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('supports UUID treatment ids for post, put, and delete', function (done) {
|
||||
var treatmentId = '69F15FD2-8075-4DEB-AEA3-4352F455840D';
|
||||
var originalCreatedAt = '2026-02-17T02:00:16.000Z';
|
||||
var repostedCreatedAt = '2026-02-17T02:05:16.000Z';
|
||||
var updatedCreatedAt = '2026-02-17T02:10:16.000Z';
|
||||
|
||||
self.ctx.treatments.remove({ find: { created_at: { '$gte': '1999-01-01T00:00:00.000Z' } } }, function () {
|
||||
request(self.app)
|
||||
.post('/api/treatments/')
|
||||
.set('api-secret', api_secret_hash || '')
|
||||
.send({
|
||||
_id: treatmentId,
|
||||
eventType: 'Temporary Override',
|
||||
created_at: originalCreatedAt,
|
||||
durationType: 'indefinite',
|
||||
correctionRange: [90, 110],
|
||||
insulinNeedsScaleFactor: 1.2,
|
||||
reason: 'test override'
|
||||
})
|
||||
.expect(200)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
request(self.app)
|
||||
.post('/api/treatments/')
|
||||
.set('api-secret', api_secret_hash || '')
|
||||
.send({
|
||||
_id: treatmentId,
|
||||
eventType: 'Temporary Override',
|
||||
created_at: repostedCreatedAt,
|
||||
duration: 60,
|
||||
correctionRange: [90, 110],
|
||||
insulinNeedsScaleFactor: 1.2,
|
||||
reason: 'reposted override'
|
||||
})
|
||||
.expect(200)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
self.ctx.treatments.list({ find: { _id: treatmentId } }, function (err, list) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
list.length.should.equal(1);
|
||||
list[0]._id.should.equal(treatmentId);
|
||||
list[0].created_at.should.equal(repostedCreatedAt);
|
||||
list[0].duration.should.equal(60);
|
||||
should.not.exist(list[0].durationType);
|
||||
|
||||
request(self.app)
|
||||
.put('/api/treatments/')
|
||||
.set('api-secret', api_secret_hash || '')
|
||||
.send({
|
||||
_id: treatmentId,
|
||||
eventType: 'Temporary Override',
|
||||
created_at: updatedCreatedAt,
|
||||
duration: 30,
|
||||
correctionRange: [90, 110],
|
||||
insulinNeedsScaleFactor: 1.2,
|
||||
reason: 'updated override'
|
||||
})
|
||||
.expect(200)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
self.ctx.treatments.list({ find: { _id: treatmentId } }, function (err, updatedList) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
updatedList.length.should.equal(1);
|
||||
updatedList[0]._id.should.equal(treatmentId);
|
||||
updatedList[0].created_at.should.equal(updatedCreatedAt);
|
||||
updatedList[0].duration.should.equal(30);
|
||||
updatedList[0].reason.should.equal('updated override');
|
||||
|
||||
request(self.app)
|
||||
.delete('/api/treatments/' + encodeURIComponent(treatmentId))
|
||||
.set('api-secret', api_secret_hash || '')
|
||||
.expect(200)
|
||||
.end(function (err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
self.ctx.treatments.list({ find: { _id: treatmentId } }, function (err, deletedList) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
deletedList.length.should.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,4 +35,18 @@ describe('query', function ( ) {
|
||||
|
||||
(typeof opts.date).should.equal('undefined')
|
||||
});
|
||||
|
||||
it('should keep non-ObjectId _id queries as strings', function ( ) {
|
||||
var uuid = '69F15FD2-8075-4DEB-AEA3-4352F455840D';
|
||||
var opts = query({ find: { _id: uuid } });
|
||||
|
||||
opts._id.should.equal(uuid);
|
||||
});
|
||||
|
||||
it('should convert ObjectId-shaped _id queries', function ( ) {
|
||||
var objectId = '55cbd4e47e726599048a3f91';
|
||||
var opts = query({ find: { _id: objectId } });
|
||||
|
||||
opts._id.toString().should.equal(objectId);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user