|
|
@ -16,7 +16,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/700000000000000000000001',
|
|
|
|
url: '/condition/700000000000000000000001',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200,
|
|
|
|
httpStatus: 200,
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', parameters: {material: 'copper', weeks: 3}, treatment_template: '200000000000000000000001'}
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'A1', parameters: {material: 'copper', weeks: 3}, treatment_template: '200000000000000000000001'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('returns the right condition for an API key', done => {
|
|
|
|
it('returns the right condition for an API key', done => {
|
|
|
@ -25,7 +25,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/700000000000000000000001',
|
|
|
|
url: '/condition/700000000000000000000001',
|
|
|
|
auth: {key: 'janedoe'},
|
|
|
|
auth: {key: 'janedoe'},
|
|
|
|
httpStatus: 200,
|
|
|
|
httpStatus: 200,
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', parameters: {material: 'copper', weeks: 3}, treatment_template: '200000000000000000000001'}
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'A1', parameters: {material: 'copper', weeks: 3}, treatment_template: '200000000000000000000001'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects an invalid id', done => {
|
|
|
|
it('rejects an invalid id', done => {
|
|
|
@ -61,7 +61,7 @@ describe('/condition', () => {
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200,
|
|
|
|
httpStatus: 200,
|
|
|
|
req: {},
|
|
|
|
req: {},
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', treatment_template: '200000000000000000000001', parameters: {material: 'copper', weeks: 3}}
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'A1', treatment_template: '200000000000000000000001', parameters: {material: 'copper', weeks: 3}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('keeps unchanged properties', done => {
|
|
|
|
it('keeps unchanged properties', done => {
|
|
|
@ -73,7 +73,7 @@ describe('/condition', () => {
|
|
|
|
req: {parameters: {material: 'copper', weeks: 3}}
|
|
|
|
req: {parameters: {material: 'copper', weeks: 3}}
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(res.body).be.eql({_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', treatment_template: '200000000000000000000001', parameters: {material: 'copper', weeks: 3}});
|
|
|
|
should(res.body).be.eql({_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'A1', treatment_template: '200000000000000000000001', parameters: {material: 'copper', weeks: 3}});
|
|
|
|
ConditionModel.findById('700000000000000000000001').lean().exec((err, data) => {
|
|
|
|
ConditionModel.findById('700000000000000000000001').lean().exec((err, data) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(data).have.property('status', 10);
|
|
|
|
should(data).have.property('status', 10);
|
|
|
@ -90,7 +90,7 @@ describe('/condition', () => {
|
|
|
|
req: {parameters: {material: 'copper'}}
|
|
|
|
req: {parameters: {material: 'copper'}}
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(res.body).be.eql({_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', treatment_template: '200000000000000000000001', parameters: {material: 'copper', weeks: 3}});
|
|
|
|
should(res.body).be.eql({_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'A1', treatment_template: '200000000000000000000001', parameters: {material: 'copper', weeks: 3}});
|
|
|
|
ConditionModel.findById('700000000000000000000001').lean().exec((err, data) => {
|
|
|
|
ConditionModel.findById('700000000000000000000001').lean().exec((err, data) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(data).have.property('status', 10);
|
|
|
|
should(data).have.property('status', 10);
|
|
|
@ -107,12 +107,12 @@ describe('/condition', () => {
|
|
|
|
req: {parameters: {material: 'hot air', weeks: 10}}
|
|
|
|
req: {parameters: {material: 'hot air', weeks: 10}}
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(res.body).be.eql({_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', treatment_template: '200000000000000000000001', parameters: {material: 'hot air', weeks: 10}});
|
|
|
|
should(res.body).be.eql({_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'A1', treatment_template: '200000000000000000000001', parameters: {material: 'hot air', weeks: 10}});
|
|
|
|
ConditionModel.findById('700000000000000000000001').lean().exec((err, data: any) => {
|
|
|
|
ConditionModel.findById('700000000000000000000001').lean().exec((err, data: any) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(data).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template', 'status', '__v');
|
|
|
|
should(data).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template', 'status', '__v');
|
|
|
|
should(data.sample_id.toString()).be.eql('400000000000000000000001');
|
|
|
|
should(data.sample_id.toString()).be.eql('400000000000000000000001');
|
|
|
|
should(data).have.property('number', 'B1');
|
|
|
|
should(data).have.property('number', 'A1');
|
|
|
|
should(data.treatment_template.toString()).be.eql('200000000000000000000001');
|
|
|
|
should(data.treatment_template.toString()).be.eql('200000000000000000000001');
|
|
|
|
should(data).have.property('status', 0);
|
|
|
|
should(data).have.property('status', 0);
|
|
|
|
should(data).have.property('parameters');
|
|
|
|
should(data).have.property('parameters');
|
|
|
@ -129,7 +129,17 @@ describe('/condition', () => {
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200,
|
|
|
|
httpStatus: 200,
|
|
|
|
req: {parameters: {weeks: 8}},
|
|
|
|
req: {parameters: {weeks: 8}},
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', treatment_template: '200000000000000000000001', parameters: {material: 'copper', weeks: 8}}
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'A1', treatment_template: '200000000000000000000001', parameters: {material: 'copper', weeks: 8}}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects changing the condition number', done => {
|
|
|
|
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
|
|
|
|
method: 'put',
|
|
|
|
|
|
|
|
url: '/condition/700000000000000000000001',
|
|
|
|
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
|
|
|
|
httpStatus: 400,
|
|
|
|
|
|
|
|
req: {number: 'C2'},
|
|
|
|
|
|
|
|
res: {status: 'Invalid body format', details: '"number" is not allowed'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects not specified parameters', done => {
|
|
|
|
it('rejects not specified parameters', done => {
|
|
|
@ -198,7 +208,7 @@ describe('/condition', () => {
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
httpStatus: 200,
|
|
|
|
httpStatus: 200,
|
|
|
|
req: {parameters: {material: 'hot air', weeks: 10}},
|
|
|
|
req: {parameters: {material: 'hot air', weeks: 10}},
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', treatment_template: '200000000000000000000001', parameters: {material: 'hot air', weeks: 10}}
|
|
|
|
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'A1', treatment_template: '200000000000000000000001', parameters: {material: 'hot air', weeks: 10}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects an API key', done => {
|
|
|
|
it('rejects an API key', done => {
|
|
|
@ -227,34 +237,41 @@ describe('/condition', () => {
|
|
|
|
req: {parameters: {material: 'hot air', weeks: 10}}
|
|
|
|
req: {parameters: {material: 'hot air', weeks: 10}}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}); // TODO: how to deal with template changes? Template versioning?
|
|
|
|
});
|
|
|
|
// TODO: rewrite delete methods -> set status for every database collection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('DELETE /condition/{id}', () => {
|
|
|
|
describe('DELETE /condition/{id}', () => {
|
|
|
|
it('sets the status to deleted', done => {
|
|
|
|
it('sets the status to deleted', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'delete',
|
|
|
|
method: 'delete',
|
|
|
|
url: '/condition/700000000000000000000002',
|
|
|
|
url: '/condition/700000000000000000000004',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(res.body).be.eql({status: 'OK'});
|
|
|
|
should(res.body).be.eql({status: 'OK'});
|
|
|
|
ConditionModel.findById('700000000000000000000002').lean().exec((err, data: any) => {
|
|
|
|
ConditionModel.findById('700000000000000000000004').lean().exec((err, data: any) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(data).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template', 'status', '__v');
|
|
|
|
should(data).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template', 'status', '__v');
|
|
|
|
should(data.sample_id.toString()).be.eql('400000000000000000000002');
|
|
|
|
should(data.sample_id.toString()).be.eql('400000000000000000000001');
|
|
|
|
should(data).have.property('number', 'B1');
|
|
|
|
should(data).have.property('number', 'A6');
|
|
|
|
should(data.treatment_template.toString()).be.eql('200000000000000000000001');
|
|
|
|
should(data.treatment_template.toString()).be.eql('200000000000000000000001');
|
|
|
|
should(data).have.property('status', -1);
|
|
|
|
should(data).have.property('status', -1);
|
|
|
|
should(data).have.property('parameters');
|
|
|
|
should(data).have.property('parameters');
|
|
|
|
should(data.parameters).have.property('material', 'copper');
|
|
|
|
should(data.parameters).have.property('material', 'hot air');
|
|
|
|
should(data.parameters).have.property('weeks', 3);
|
|
|
|
should(data.parameters).have.property('weeks', 5);
|
|
|
|
done();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects a deleting a condition referenced by measurements'); // TODO
|
|
|
|
it('rejects deleting a condition referenced by measurements'/*, done => {
|
|
|
|
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
|
|
|
|
method: 'delete',
|
|
|
|
|
|
|
|
url: '/condition/700000000000000000000002',
|
|
|
|
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
|
|
|
|
httpStatus: 200,
|
|
|
|
|
|
|
|
res: {status: 'Condition still in use'}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}*/); // TODO after decision
|
|
|
|
it('rejects an invalid id', done => {
|
|
|
|
it('rejects an invalid id', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'delete',
|
|
|
|
method: 'delete',
|
|
|
@ -266,7 +283,7 @@ describe('/condition', () => {
|
|
|
|
it('rejects an API key', done => {
|
|
|
|
it('rejects an API key', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'delete',
|
|
|
|
method: 'delete',
|
|
|
|
url: '/condition/700000000000000000000002',
|
|
|
|
url: '/condition/700000000000000000000004',
|
|
|
|
auth: {key: 'janedoe'},
|
|
|
|
auth: {key: 'janedoe'},
|
|
|
|
httpStatus: 401
|
|
|
|
httpStatus: 401
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -274,7 +291,7 @@ describe('/condition', () => {
|
|
|
|
it('rejects requests from a read user', done => {
|
|
|
|
it('rejects requests from a read user', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'delete',
|
|
|
|
method: 'delete',
|
|
|
|
url: '/condition/700000000000000000000002',
|
|
|
|
url: '/condition/700000000000000000000004',
|
|
|
|
auth: {basic: 'user'},
|
|
|
|
auth: {basic: 'user'},
|
|
|
|
httpStatus: 403
|
|
|
|
httpStatus: 403
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -290,7 +307,7 @@ describe('/condition', () => {
|
|
|
|
it('accepts an maintain/admin user deleting a condition belonging to a sample of another user', done => {
|
|
|
|
it('accepts an maintain/admin user deleting a condition belonging to a sample of another user', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'delete',
|
|
|
|
method: 'delete',
|
|
|
|
url: '/condition/700000000000000000000002',
|
|
|
|
url: '/condition/700000000000000000000004',
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -302,7 +319,7 @@ describe('/condition', () => {
|
|
|
|
it('returns 404 for an unknown id', done => {
|
|
|
|
it('returns 404 for an unknown id', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'delete',
|
|
|
|
method: 'delete',
|
|
|
|
url: '/condition/00000000000w000000000002',
|
|
|
|
url: '/condition/000000000000000000000002',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 404
|
|
|
|
httpStatus: 404
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -310,7 +327,7 @@ describe('/condition', () => {
|
|
|
|
it('rejects unauthorized requests', done => {
|
|
|
|
it('rejects unauthorized requests', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'delete',
|
|
|
|
method: 'delete',
|
|
|
|
url: '/condition/700000000000000000000002',
|
|
|
|
url: '/condition/700000000000000000000004',
|
|
|
|
httpStatus: 401
|
|
|
|
httpStatus: 401
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -323,13 +340,13 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200,
|
|
|
|
httpStatus: 200,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(res.body).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template');
|
|
|
|
should(res.body).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template');
|
|
|
|
should(res.body).have.property('_id').be.type('string');
|
|
|
|
should(res.body).have.property('_id').be.type('string');
|
|
|
|
should(res.body).have.property('sample_id', '400000000000000000000002');
|
|
|
|
should(res.body).have.property('sample_id', '400000000000000000000002');
|
|
|
|
should(res.body).have.property('number', 'B2');
|
|
|
|
should(res.body).have.property('number', 'A7');
|
|
|
|
should(res.body).have.property('treatment_template', '200000000000000000000001');
|
|
|
|
should(res.body).have.property('treatment_template', '200000000000000000000001');
|
|
|
|
should(res.body).have.property('parameters');
|
|
|
|
should(res.body).have.property('parameters');
|
|
|
|
should(res.body.parameters).have.property('material', 'hot air');
|
|
|
|
should(res.body.parameters).have.property('material', 'hot air');
|
|
|
@ -343,14 +360,14 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200,
|
|
|
|
httpStatus: 200,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
ConditionModel.findById(res.body._id).lean().exec((err, data: any) => {
|
|
|
|
ConditionModel.findById(res.body._id).lean().exec((err, data: any) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(data).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template', 'status', '__v');
|
|
|
|
should(data).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template', 'status', '__v');
|
|
|
|
should(data.sample_id.toString()).be.eql('400000000000000000000002');
|
|
|
|
should(data.sample_id.toString()).be.eql('400000000000000000000002');
|
|
|
|
should(data).have.property('number', 'B2');
|
|
|
|
should(data).have.property('number', 'A7');
|
|
|
|
should(data.treatment_template.toString()).be.eql('200000000000000000000001');
|
|
|
|
should(data.treatment_template.toString()).be.eql('200000000000000000000001');
|
|
|
|
should(data).have.property('status', 0);
|
|
|
|
should(data).have.property('status', 0);
|
|
|
|
should(data).have.property('parameters');
|
|
|
|
should(data).have.property('parameters');
|
|
|
@ -366,7 +383,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '4000000000h0000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
req: {sample_id: '4000000000h0000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
res: {status: 'Invalid body format', details: '"sample_id" with value "4000000000h0000000000002" fails to match the required pattern: /[0-9a-f]{24}/'}
|
|
|
|
res: {status: 'Invalid body format', details: '"sample_id" with value "4000000000h0000000000002" fails to match the required pattern: /[0-9a-f]{24}/'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -376,7 +393,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '000000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
req: {sample_id: '000000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
res: {status: 'Sample id not available'}
|
|
|
|
res: {status: 'Sample id not available'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -386,7 +403,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000h00000000001'},
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000h00000000001'},
|
|
|
|
res: {status: 'Invalid body format', details: '"treatment_template" with value "200000000000h00000000001" fails to match the required pattern: /[0-9a-f]{24}/'}
|
|
|
|
res: {status: 'Invalid body format', details: '"treatment_template" with value "200000000000h00000000001" fails to match the required pattern: /[0-9a-f]{24}/'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -396,18 +413,18 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '000000000000000000000001'},
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '000000000000000000000001'},
|
|
|
|
res: {status: 'Treatment template not available'}
|
|
|
|
res: {status: 'Treatment template not available'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects a condition number already in use for this sample', done => {
|
|
|
|
it('rejects setting a condition number', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'post',
|
|
|
|
method: 'post',
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '400000000000000000000001', number: 'B1', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
req: {sample_id: '400000000000000000000001', number: 'A7', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
res: {status: 'Condition number already taken'}
|
|
|
|
res: {status: 'Invalid body format', details: '"number" is not allowed'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects not specified parameters', done => {
|
|
|
|
it('rejects not specified parameters', done => {
|
|
|
@ -416,7 +433,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10, xx: 12}, treatment_template: '200000000000000000000001'},
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10, xx: 12}, treatment_template: '200000000000000000000001'},
|
|
|
|
res: {status: 'Invalid body format', details: '"xx" is not allowed'}
|
|
|
|
res: {status: 'Invalid body format', details: '"xx" is not allowed'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -426,7 +443,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air'}, treatment_template: '200000000000000000000001'},
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air'}, treatment_template: '200000000000000000000001'},
|
|
|
|
res: {status: 'Invalid body format', details: '"weeks" is required'}
|
|
|
|
res: {status: 'Invalid body format', details: '"weeks" is required'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -436,7 +453,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'xxx', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'xxx', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
res: {status: 'Invalid body format', details: '"material" must be one of [copper, hot air]'}
|
|
|
|
res: {status: 'Invalid body format', details: '"material" must be one of [copper, hot air]'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -446,7 +463,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: -10}, treatment_template: '200000000000000000000001'},
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: -10}, treatment_template: '200000000000000000000001'},
|
|
|
|
res: {status: 'Invalid body format', details: '"weeks" must be larger than or equal to 1'}
|
|
|
|
res: {status: 'Invalid body format', details: '"weeks" must be larger than or equal to 1'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -456,7 +473,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 11}, treatment_template: '200000000000000000000001'},
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 11}, treatment_template: '200000000000000000000001'},
|
|
|
|
res: {status: 'Invalid body format', details: '"weeks" must be less than or equal to 10'}
|
|
|
|
res: {status: 'Invalid body format', details: '"weeks" must be less than or equal to 10'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -466,7 +483,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
req: {parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
res: {status: 'Invalid body format', details: '"sample_id" is required'}
|
|
|
|
res: {status: 'Invalid body format', details: '"sample_id" is required'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -476,27 +493,17 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}},
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}},
|
|
|
|
res: {status: 'Invalid body format', details: '"treatment_template" is required'}
|
|
|
|
res: {status: 'Invalid body format', details: '"treatment_template" is required'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects a missing number', done => {
|
|
|
|
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
|
|
|
|
method: 'post',
|
|
|
|
|
|
|
|
url: '/condition/new',
|
|
|
|
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
|
|
|
|
httpStatus: 400,
|
|
|
|
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'},
|
|
|
|
|
|
|
|
res: {status: 'Invalid body format', details: '"number" is required'}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('rejects adding a condition to the sample of an other user for a write user', done => {
|
|
|
|
it('rejects adding a condition to the sample of an other user for a write user', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'post',
|
|
|
|
method: 'post',
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 403,
|
|
|
|
httpStatus: 403,
|
|
|
|
req: {sample_id: '400000000000000000000003', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
req: {sample_id: '400000000000000000000003', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('accepts adding a condition to the sample of an other user for a maintain/admin user', done => {
|
|
|
|
it('accepts adding a condition to the sample of an other user for a maintain/admin user', done => {
|
|
|
@ -505,13 +512,13 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
httpStatus: 200,
|
|
|
|
httpStatus: 200,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
|
if (err) return done(err);
|
|
|
|
if (err) return done(err);
|
|
|
|
should(res.body).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template');
|
|
|
|
should(res.body).have.only.keys('_id', 'sample_id', 'number', 'parameters', 'treatment_template');
|
|
|
|
should(res.body).have.property('_id').be.type('string');
|
|
|
|
should(res.body).have.property('_id').be.type('string');
|
|
|
|
should(res.body).have.property('sample_id', '400000000000000000000002');
|
|
|
|
should(res.body).have.property('sample_id', '400000000000000000000002');
|
|
|
|
should(res.body).have.property('number', 'B2');
|
|
|
|
should(res.body).have.property('number', 'A7');
|
|
|
|
should(res.body).have.property('treatment_template', '200000000000000000000001');
|
|
|
|
should(res.body).have.property('treatment_template', '200000000000000000000001');
|
|
|
|
should(res.body).have.property('parameters');
|
|
|
|
should(res.body).have.property('parameters');
|
|
|
|
should(res.body.parameters).have.property('material', 'hot air');
|
|
|
|
should(res.body.parameters).have.property('material', 'hot air');
|
|
|
@ -525,7 +532,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {key: 'janedoe'},
|
|
|
|
auth: {key: 'janedoe'},
|
|
|
|
httpStatus: 401,
|
|
|
|
httpStatus: 401,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects requests from a read user', done => {
|
|
|
|
it('rejects requests from a read user', done => {
|
|
|
@ -534,7 +541,7 @@ describe('/condition', () => {
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
auth: {basic: 'user'},
|
|
|
|
auth: {basic: 'user'},
|
|
|
|
httpStatus: 403,
|
|
|
|
httpStatus: 403,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects unauthorized requests', done => {
|
|
|
|
it('rejects unauthorized requests', done => {
|
|
|
@ -542,7 +549,7 @@ describe('/condition', () => {
|
|
|
|
method: 'post',
|
|
|
|
method: 'post',
|
|
|
|
url: '/condition/new',
|
|
|
|
url: '/condition/new',
|
|
|
|
httpStatus: 401,
|
|
|
|
httpStatus: 401,
|
|
|
|
req: {sample_id: '400000000000000000000002', number: 'B2', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
req: {sample_id: '400000000000000000000002', parameters: {material: 'hot air', weeks: 10}, treatment_template: '200000000000000000000001'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|