implementation of measurement fields
This commit is contained in:
@ -244,6 +244,42 @@ describe('/sample', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('adds the specified measurements', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'get',
|
||||
url: '/samples?status=all&fields[]=number&fields[]=measurements.kf',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
should(res.body.find(e => e.number === '1')).have.property('kf', {});
|
||||
should(res.body.find(e => e.number === 'Rng36')).have.property('kf', {'weight %': 0.5, 'standard deviation': null});
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('multiplies the sample information for each spectrum', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'get',
|
||||
url: '/samples?status=all&fields[]=number&fields[]=measurements.spectrum',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
should(res.body).have.lengthOf(2);
|
||||
should(res.body[0]).have.property('spectrum', [[3997.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]]);
|
||||
should(res.body[1]).have.property('spectrum', [[3996.12558,98.00555],[3995.08519,98.03253],[3993.04480,98.02657]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('rejects unknown measurement names', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'get',
|
||||
url: '/samples?status=all&fields[]=number&fields[]=measurements.xx',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
res: {status: 'Invalid body format', details: 'Measurement key not found'}
|
||||
});
|
||||
});
|
||||
it('returns a correct csv file if specified', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'get',
|
||||
@ -253,9 +289,9 @@ describe('/sample', () => {
|
||||
httpStatus: 200
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
should(res.text).be.eql('"_id","number","type","color","batch","condition","material_id","note_id","user_id","added"\r\n' +
|
||||
'"400000000000000000000001","1","granulate","black","","{""material"":""copper"",""weeks"":3,""condition_template"":""200000000000000000000001""}","100000000000000000000004",,"000000000000000000000002","2004-01-10T13:37:04.000Z"\r\n' +
|
||||
'"400000000000000000000002","21","granulate","natural","1560237365","{""material"":""copper"",""weeks"":3,""condition_template"":""200000000000000000000001""}","100000000000000000000001","500000000000000000000001","000000000000000000000002","2004-01-10T13:37:04.000Z"');
|
||||
should(res.text).be.eql('"_id","number","type","color","batch","condition.material","condition.weeks","condition.condition_template","material_id","note_id","user_id","added"\r\n' +
|
||||
'"400000000000000000000001","1","granulate","black","","copper",3,"200000000000000000000001","100000000000000000000004",,"000000000000000000000002","2004-01-10T13:37:04.000Z"\r\n' +
|
||||
'"400000000000000000000002","21","granulate","natural","1560237365","copper",3,"200000000000000000000001","100000000000000000000001","500000000000000000000001","000000000000000000000002","2004-01-10T13:37:04.000Z"');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -268,6 +304,15 @@ describe('/sample', () => {
|
||||
res: [{number: '1', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, color: 'black', material: {name: 'Schulamid 66 GF 25 H', mineral: 0}}]
|
||||
});
|
||||
});
|
||||
it('rejects a from-id not in the database', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'get',
|
||||
url: '/samples?from-id=5ea0450ed851c30a90e70894&sort=color-asc',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
res: {status: 'Invalid body format', details: 'from-id not found'}
|
||||
});
|
||||
});
|
||||
it('rejects an invalid fields parameter', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'get',
|
||||
@ -283,7 +328,7 @@ describe('/sample', () => {
|
||||
url: '/samples?status=all&page-size=1&fields[]=xx',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
res: {status: 'Invalid body format', details: '"fields[0]" must be one of [_id, color, number, type, batch, added, material.name, material.supplier, material.group, material.mineral, material.glass_fiber, material.carbon_fiber, material.number, condition, material_id, note_id, user_id, material._id, material.numbers]'}
|
||||
res: {status: 'Invalid body format', details: '"fields[0]" with value "xx" fails to match the required pattern: /^(_id|color|number|type|batch|added|material\\.name|material\\.supplier|material\\.group|material\\.mineral|material\\.glass_fiber|material\\.carbon_fiber|material\\.number|condition|material_id|material|note_id|user_id|material\\._id|material\\.numbers|measurements\\..+)$/m'}
|
||||
});
|
||||
});
|
||||
it('rejects a negative page size', done => {
|
||||
@ -329,7 +374,7 @@ describe('/sample', () => {
|
||||
httpStatus: 401
|
||||
});
|
||||
});
|
||||
}); // TODO: measurement fields
|
||||
});
|
||||
|
||||
describe('GET /samples/{state}', () => {
|
||||
it('returns all new samples', done => {
|
||||
|
Reference in New Issue
Block a user