|
|
@ -48,6 +48,22 @@ describe('/sample', () => {
|
|
|
|
done();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns deleted samples for admin', done => {
|
|
|
|
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
|
|
url: '/samples?status[]=deleted&fields[]=number&fields=status',
|
|
|
|
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
|
|
|
|
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 ==='deleted').length);
|
|
|
|
|
|
|
|
should(res.body).matchEach(sample => {
|
|
|
|
|
|
|
|
should(sample).have.property('status', 'deleted').be.type('string');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
it('works with an API key', done => {
|
|
|
|
it('works with an API key', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
@ -78,7 +94,7 @@ describe('/sample', () => {
|
|
|
|
it('allows filtering by state', done => {
|
|
|
|
it('allows filtering by state', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=new',
|
|
|
|
url: '/samples?status[]=new',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -104,7 +120,7 @@ describe('/sample', () => {
|
|
|
|
it('uses the given page size', done => {
|
|
|
|
it('uses the given page size', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&page-size=3',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&page-size=3',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -116,7 +132,7 @@ describe('/sample', () => {
|
|
|
|
it('returns results starting from first-id', done => {
|
|
|
|
it('returns results starting from first-id', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&from-id=400000000000000000000002',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&from-id=400000000000000000000002',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -129,7 +145,7 @@ describe('/sample', () => {
|
|
|
|
it('returns the right page number', done => {
|
|
|
|
it('returns the right page number', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&to-page=2&page-size=2',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&to-page=2&page-size=2',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -141,7 +157,7 @@ describe('/sample', () => {
|
|
|
|
it('works with negative page numbers', done => {
|
|
|
|
it('works with negative page numbers', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&to-page=-1&page-size=2&from-id=400000000000000000000004',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&to-page=-1&page-size=2&from-id=400000000000000000000004',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -154,7 +170,7 @@ describe('/sample', () => {
|
|
|
|
it('returns an empty array for a page number out of range', done => {
|
|
|
|
it('returns an empty array for a page number out of range', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&to-page=100&page-size=2',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&to-page=100&page-size=2',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -167,7 +183,7 @@ describe('/sample', () => {
|
|
|
|
it('returns an empty array for a page number out of negative range', done => {
|
|
|
|
it('returns an empty array for a page number out of negative range', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&to-page=-100&page-size=3&from-id=400000000000000000000004',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&to-page=-100&page-size=3&from-id=400000000000000000000004',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -180,7 +196,7 @@ describe('/sample', () => {
|
|
|
|
it('sorts the samples ascending', done => {
|
|
|
|
it('sorts the samples ascending', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&sort=color-asc',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&sort=color-asc',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -193,7 +209,7 @@ describe('/sample', () => {
|
|
|
|
it('sorts the samples descending', done => {
|
|
|
|
it('sorts the samples descending', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&sort=number-desc',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&sort=number-desc',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -207,7 +223,7 @@ describe('/sample', () => {
|
|
|
|
it('sorts the samples correctly in combination with paging', done => {
|
|
|
|
it('sorts the samples correctly in combination with paging', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&sort=color-asc&page-size=2&from-id=400000000000000000000006',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&sort=color-asc&page-size=2&from-id=400000000000000000000006',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -220,7 +236,7 @@ describe('/sample', () => {
|
|
|
|
it('sorts the samples correctly in combination with going pages backward', done => {
|
|
|
|
it('sorts the samples correctly in combination with going pages backward', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&sort=color-desc&page-size=2&from-id=400000000000000000000004&to-page=-1',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&sort=color-desc&page-size=2&from-id=400000000000000000000004&to-page=-1',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -233,7 +249,7 @@ describe('/sample', () => {
|
|
|
|
it('sorts the samples correctly for material keys', done => {
|
|
|
|
it('sorts the samples correctly for material keys', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&sort=material.name-desc',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&sort=material.name-desc',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -247,7 +263,7 @@ describe('/sample', () => {
|
|
|
|
it('adds the status if specified', done => {
|
|
|
|
it('adds the status if specified', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=status',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=status',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -260,7 +276,7 @@ describe('/sample', () => {
|
|
|
|
it('adds the specified measurements', done => {
|
|
|
|
it('adds the specified measurements', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=measurements.kf',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=measurements.kf',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -273,7 +289,7 @@ describe('/sample', () => {
|
|
|
|
it('multiplies the sample information for each spectrum', done => {
|
|
|
|
it('multiplies the sample information for each spectrum', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=measurements.spectrum.dpt',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=measurements.spectrum.dpt',
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
auth: {basic: 'admin'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -287,7 +303,7 @@ describe('/sample', () => {
|
|
|
|
it('filters a sample property', done => { // TODO: implement filters
|
|
|
|
it('filters a sample property', done => { // TODO: implement filters
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=type&filters[]=%7B%22mode%22%3A%22eq%22%2C%22field%22%3A%22type%22%2C%22values%22%3A%5B%22part%22%5D%7D',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=type&filters[]=%7B%22mode%22%3A%22eq%22%2C%22field%22%3A%22type%22%2C%22values%22%3A%5B%22part%22%5D%7D',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -303,7 +319,7 @@ describe('/sample', () => {
|
|
|
|
it('filters a material property', done => {
|
|
|
|
it('filters a material property', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=material.name&filters[]=%7B%22mode%22%3A%22in%22%2C%22field%22%3A%22material.name%22%2C%22values%22%3A%5B%22Schulamid%2066%20GF%2025%20H%22%2C%22Stanyl%20TW%20200%20F8%22%5D%7D',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=material.name&filters[]=%7B%22mode%22%3A%22in%22%2C%22field%22%3A%22material.name%22%2C%22values%22%3A%5B%22Schulamid%2066%20GF%2025%20H%22%2C%22Stanyl%20TW%20200%20F8%22%5D%7D',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -319,7 +335,7 @@ describe('/sample', () => {
|
|
|
|
it('filters by measurement value', done => {
|
|
|
|
it('filters by measurement value', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=material.name&fields[]=measurements.kf.weight%20%25&filters[]=%7B%22mode%22%3A%22gt%22%2C%22field%22%3A%22measurements.kf.weight%20%25%22%2C%22values%22%3A%5B0.5%5D%7D',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=material.name&fields[]=measurements.kf.weight%20%25&filters[]=%7B%22mode%22%3A%22gt%22%2C%22field%22%3A%22measurements.kf.weight%20%25%22%2C%22values%22%3A%5B0.5%5D%7D',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -335,7 +351,7 @@ describe('/sample', () => {
|
|
|
|
it('filters by measurement value not in the fields', done => {
|
|
|
|
it('filters by measurement value not in the fields', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=material.name&filters[]=%7B%22mode%22%3A%22gt%22%2C%22field%22%3A%22measurements.kf.weight%20%25%22%2C%22values%22%3A%5B0.5%5D%7D',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=material.name&filters[]=%7B%22mode%22%3A%22gt%22%2C%22field%22%3A%22measurements.kf.weight%20%25%22%2C%22values%22%3A%5B0.5%5D%7D',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -349,7 +365,7 @@ describe('/sample', () => {
|
|
|
|
it('filters by a measurement properties property', done => {
|
|
|
|
it('filters by a measurement properties property', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
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',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&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'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -364,7 +380,7 @@ describe('/sample', () => {
|
|
|
|
it('filters and sorts by a measurement properties property', done => {
|
|
|
|
it('filters and sorts by a measurement properties property', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
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',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&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'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -381,7 +397,7 @@ describe('/sample', () => {
|
|
|
|
it('filters multiple properties', done => {
|
|
|
|
it('filters multiple properties', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=batch&filters[]=%7B%22mode%22%3A%22lte%22%2C%22field%22%3A%22number%22%2C%22values%22%3A%5B%22Rng33%22%5D%7D&filters[]=%7B%22mode%22%3A%22nin%22%2C%22field%22%3A%22batch%22%2C%22values%22%3A%5B%221704-005%22%5D%7D',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=batch&filters[]=%7B%22mode%22%3A%22lte%22%2C%22field%22%3A%22number%22%2C%22values%22%3A%5B%22Rng33%22%5D%7D&filters[]=%7B%22mode%22%3A%22nin%22%2C%22field%22%3A%22batch%22%2C%22values%22%3A%5B%221704-005%22%5D%7D',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -394,7 +410,7 @@ describe('/sample', () => {
|
|
|
|
it('rejects returning spectral data for a write user', done => {
|
|
|
|
it('rejects returning spectral data for a write user', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=measurements.spectrum.dpt',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=measurements.spectrum.dpt',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 403
|
|
|
|
httpStatus: 403
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -402,7 +418,7 @@ describe('/sample', () => {
|
|
|
|
it('rejects an invalid JSON string as a filters parameter', done => {
|
|
|
|
it('rejects an invalid JSON string as a filters parameter', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=material.glass_fiber&fields[]=batch&filters[]=xx',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=material.glass_fiber&fields[]=batch&filters[]=xx',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
res: {status: 'Invalid body format', details: 'Invalid JSON string for filter parameter'}
|
|
|
|
res: {status: 'Invalid body format', details: 'Invalid JSON string for filter parameter'}
|
|
|
@ -411,7 +427,7 @@ describe('/sample', () => {
|
|
|
|
it('rejects an invalid filter mode', done => {
|
|
|
|
it('rejects an invalid filter mode', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
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',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&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'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
res: {status: 'Invalid body format', details: '"filters[0].mode" must be one of [eq, ne, lt, lte, gt, gte, in, nin, stringin]'}
|
|
|
|
res: {status: 'Invalid body format', details: '"filters[0].mode" must be one of [eq, ne, lt, lte, gt, gte, in, nin, stringin]'}
|
|
|
@ -420,7 +436,7 @@ describe('/sample', () => {
|
|
|
|
it('rejects an filter field not existing', done => {
|
|
|
|
it('rejects an filter field not existing', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=material.glass_fiber&fields[]=batch&filters[]=%7B%22mode%22%3A%22eq%22%2C%22field%22%3A%22xx%22%2C%22values%22%3A%5B%221704-005%22%5D%7D',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=material.glass_fiber&fields[]=batch&filters[]=%7B%22mode%22%3A%22eq%22%2C%22field%22%3A%22xx%22%2C%22values%22%3A%5B%221704-005%22%5D%7D',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
res: {status: 'Invalid body format', details: 'Invalid JSON string for filter parameter'}
|
|
|
|
res: {status: 'Invalid body format', details: 'Invalid JSON string for filter parameter'}
|
|
|
@ -429,7 +445,7 @@ describe('/sample', () => {
|
|
|
|
it('rejects unknown measurement names', done => {
|
|
|
|
it('rejects unknown measurement names', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=measurements.xx',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=measurements.xx',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
res: {status: 'Invalid body format', details: 'Measurement key not found'}
|
|
|
|
res: {status: 'Invalid body format', details: 'Measurement key not found'}
|
|
|
@ -438,7 +454,7 @@ describe('/sample', () => {
|
|
|
|
it('returns a correct csv file if specified', done => {
|
|
|
|
it('returns a correct csv file if specified', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&page-size=2&csv=true',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&page-size=2&csv=true',
|
|
|
|
contentType: /text\/csv/,
|
|
|
|
contentType: /text\/csv/,
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
@ -453,7 +469,7 @@ describe('/sample', () => {
|
|
|
|
it('returns only the fields specified', done => {
|
|
|
|
it('returns only the fields specified', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&page-size=1&fields[]=number&fields[]=condition&fields[]=color&fields[]=material.name&fields[]=material.supplier',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&page-size=1&fields[]=number&fields[]=condition&fields[]=color&fields[]=material.name&fields[]=material.supplier',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200,
|
|
|
|
httpStatus: 200,
|
|
|
|
res: [{number: '1', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, color: 'black', material: {name: 'Schulamid 66 GF 25 H', supplier: 'Schulmann'}}]
|
|
|
|
res: [{number: '1', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, color: 'black', material: {name: 'Schulamid 66 GF 25 H', supplier: 'Schulmann'}}]
|
|
|
@ -462,7 +478,7 @@ describe('/sample', () => {
|
|
|
|
it('returns specified material properties fields', done => {
|
|
|
|
it('returns specified material properties fields', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&fields[]=number&fields[]=material.properties.glass_fiber&fields[]=material.name',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&fields[]=number&fields[]=material.properties.glass_fiber&fields[]=material.name',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 200
|
|
|
|
httpStatus: 200
|
|
|
|
}).end((err, res) => {
|
|
|
|
}).end((err, res) => {
|
|
|
@ -490,7 +506,7 @@ describe('/sample', () => {
|
|
|
|
it('rejects an invalid fields parameter', done => {
|
|
|
|
it('rejects an invalid fields parameter', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&page-size=1&fields=number',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&page-size=1&fields=number',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
res: {status: 'Invalid body format', details: '"fields" must be an array'}
|
|
|
|
res: {status: 'Invalid body format', details: '"fields" must be an array'}
|
|
|
@ -499,7 +515,7 @@ describe('/sample', () => {
|
|
|
|
it('rejects an unknown field name', done => {
|
|
|
|
it('rejects an unknown field name', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=all&page-size=1&fields[]=xx',
|
|
|
|
url: '/samples?status[]=new&status[]=validated&page-size=1&fields[]=xx',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
res: {status: 'Invalid body format', details: 'Invalid field name'}
|
|
|
|
res: {status: 'Invalid body format', details: 'Invalid field name'}
|
|
|
@ -535,10 +551,10 @@ describe('/sample', () => {
|
|
|
|
it('rejects an invalid state name', done => {
|
|
|
|
it('rejects an invalid state name', done => {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
TestHelper.request(server, done, {
|
|
|
|
method: 'get',
|
|
|
|
method: 'get',
|
|
|
|
url: '/samples?status=xxx',
|
|
|
|
url: '/samples?status[]=xxx',
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
auth: {basic: 'janedoe'},
|
|
|
|
httpStatus: 400,
|
|
|
|
httpStatus: 400,
|
|
|
|
res: {status: 'Invalid body format', details: '"status" must be one of [validated, new, all]'}
|
|
|
|
res: {status: 'Invalid body format', details: '"status[0]" must be one of [validated, new]'}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('rejects unauthorized requests', done => {
|
|
|
|
it('rejects unauthorized requests', done => {
|
|
|
|