Archived
2

fixed sample requests for the restructured material

This commit is contained in:
VLE2FE
2020-07-17 10:41:19 +02:00
parent 78d35c520e
commit cd81cbf4bd
11 changed files with 115 additions and 28 deletions

View File

@ -200,7 +200,7 @@ describe('/sample', () => {
}).end((err, res) => {
if (err) return done(err);
should(res.body[0]).have.property('number', 'Rng36');
should(res.body[1]).have.property('number', '33');
should(res.body[1]).have.property('number', '34');
should(res.body[res.body.length - 1]).have.property('number', '1');
done();
});
@ -214,7 +214,7 @@ describe('/sample', () => {
}).end((err, res) => {
if (err) return done(err);
should(res.body[0]).have.property('_id', '400000000000000000000006');
should(res.body[1]).have.property('_id', '400000000000000000000002');
should(res.body[1]).have.property('_id', '400000000000000000000007');
done();
});
});
@ -226,7 +226,7 @@ describe('/sample', () => {
httpStatus: 200
}).end((err, res) => {
if (err) return done(err);
should(res.body[0]).have.property('_id', '400000000000000000000002');
should(res.body[0]).have.property('_id', '400000000000000000000007');
should(res.body[1]).have.property('_id', '400000000000000000000006');
done();
});
@ -334,6 +334,38 @@ describe('/sample', () => {
done();
});
});
it('filters by a measurement properties property', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/samples?status=all&fields[]=number&fields[]=material.name&fields[]=material.properties.glass_fiber&filters[]=%7B%22mode%22%3A%22eq%22%2C%22field%22%3A%22material.properties.glass_fiber%22%2C%22values%22%3A%5B%2225%22%5D%7D',
auth: {basic: 'janedoe'},
httpStatus: 200
}).end((err, res) => {
if (err) return done(err);
should(res.body).have.lengthOf(2);
should(res.body).matchEach(sample => {
should(sample.material.properties.glass_fiber).be.eql(25);
});
done();
});
});
it('filters and sorts by a measurement properties property', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/samples?status=all&sort=material.properties.glass_fiber-desc&fields[]=number&fields[]=material.name&fields[]=material.properties.glass_fiber&filters[]=%7B%22mode%22%3A%22eq%22%2C%22field%22%3A%22material.properties.glass_fiber%22%2C%22values%22%3A%5B%2225%22%5D%7D',
auth: {basic: 'janedoe'},
httpStatus: 200
}).end((err, res) => {
if (err) return done(err);
should(res.body).have.lengthOf(2);
should(res.body[0].number).be.eql('Rng36');
should(res.body[1].number).be.eql('1');
should(res.body).matchEach(sample => {
should(sample.material.properties.glass_fiber).be.eql(25);
});
done();
});
});
it('filters multiple properties', done => {
TestHelper.request(server, done, {
method: 'get',
@ -342,7 +374,7 @@ describe('/sample', () => {
httpStatus: 200
}).end((err, res) => {
if (err) return done(err);
should(res.body).have.lengthOf(3);
should(res.body).have.lengthOf(4);
should(res.body[0]).be.eql({number: '1', batch: ''});
done();
});
@ -359,7 +391,7 @@ describe('/sample', () => {
it('rejects an invalid filter mode', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/samples?status=all&fields[]=number&fields[]=material.glass_fiber&fields[]=batch&filters[]=%7B%22mode%22%3A%22xx%22%2C%22field%22%3A%22batch%22%2C%22values%22%3A%5B%221704-005%22%5D%7D',
url: '/samples?status=all&fields[]=number&fields[]=batch&filters[]=%7B%22mode%22%3A%22xx%22%2C%22field%22%3A%22batch%22%2C%22values%22%3A%5B%221704-005%22%5D%7D',
auth: {basic: 'janedoe'},
httpStatus: 400,
res: {status: 'Invalid body format', details: '"filters[0].mode" must be one of [eq, ne, lt, lte, gt, gte, in, nin]'}
@ -407,6 +439,25 @@ describe('/sample', () => {
res: [{number: '1', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, color: 'black', material: {name: 'Schulamid 66 GF 25 H', supplier: 'Schulmann'}}]
});
});
it('returns specified material properties fields', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/samples?status=all&fields[]=number&fields[]=material.properties.glass_fiber&fields[]=material.name',
auth: {basic: 'janedoe'},
httpStatus: 200
}).end((err, res) => {
if (err) return done(err);
const json = require('../test/db.json');
should(res.body).matchEach(sample => {
const materialId = json.collections.samples.find(e => e.number === sample.number).material_id;
const material = json.collections.materials.find(e => e._id.toString() == materialId);
should(sample).have.only.keys('number', 'material');
should(sample.material.name).be.eql(material.name);
should(sample.material.properties.glass_fiber).be.eql(material.properties.glass_fiber);
});
done()
});
});
it('rejects a from-id not in the database', done => {
TestHelper.request(server, done, {
method: 'get',