Archived
2

added status filter

This commit is contained in:
VLE2FE
2020-06-15 12:49:32 +02:00
parent 5c04263475
commit c95af7bc0b
6 changed files with 69 additions and 2 deletions

View File

@ -71,6 +71,40 @@ describe('/sample', () => {
done();
});
});
it('allows filtering by state', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/samples?status=new',
auth: {basic: 'janedoe'},
httpStatus: 200
}).end((err, res) => {
if (err) return done(err);
const json = require('../test/db.json');
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ===globals.status.new).length);
should(res.body).matchEach(sample => {
should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id');
should(sample).have.property('_id').be.type('string');
should(sample).have.property('number').be.type('string');
should(sample).have.property('type').be.type('string');
should(sample).have.property('color').be.type('string');
should(sample).have.property('batch').be.type('string');
should(sample).have.property('condition').be.type('object');
should(sample).have.property('material_id').be.type('string');
should(sample).have.property('note_id');
should(sample).have.property('user_id').be.type('string');
});
done();
});
});
it('rejects an invalid state name', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/samples?status=xxx',
auth: {basic: 'janedoe'},
httpStatus: 400,
res: {status: 'Invalid body format', details: '"status" must be one of [validated, new, all]'}
});
});
it('rejects unauthorized requests', done => {
TestHelper.request(server, done, {
method: 'get',