I am trying to test a collection find with skip and limit parameters
table.test.js
describe('# GET /api/v1/tables/meta', () => {
it('should get all tables - meta info only', () =>
request(app)
.get('/api/v1/tables/meta')
.expect(httpStatus.OK)
.then((res) => {
expect(res.body).to.be.an('array');
console.log('res.body:', res.body);
})
);
it('should get some tables w skip limit- meta info only', () =>
request(app)
.get('/api/v1/tables/meta?skip=1&limit=10')
.expect(httpStatus.OK)
.then((res) => {
expect(res.body).to.be.an('array');
console.log('res.body:', res.body);
})
);
});
table.router.js
router.route('/meta')
/** GET /api/tables - Get list of all tables meta **/
.get(tableCtrl.listTableMeta);
table.controller.js
function listTableMeta(req, res, next) {
// const limit = parseInt(req.query.limit, 10);
// const skip = parseInt(req.query.skip, 10);
const skip = 1;
const limit = 10;
Table.listMeta(req.query, { skip, limit })
.then(tables => res.json(tables))
.catch(e => next(e));
}
I have currently 2 tables in the Table collection
First test is OK, I get only one table as expected with hard setting skip/limit in controller
# GET /api/v1/tables/meta
req params: {}
skip: 1
limit: 10
Model query: {}
res.body: [ { _id: '590303660cb7110938272ca2',
meta:
{ name: 'TA-PUB-123',
description: 'TA-Public-123Description',
owner: '590303640cb7110938272c9b',
createdAt: '2017-04-28T08:55:02.104Z',
private: false,
permissions: [Object] } } ]
✓ should get all tables - meta info only
But the second test , with URL params ../tables/meta?skip=1&limit=10 is not giving the same result even with the same hard settings
why these params are modifying the query process ?
thanks for your feedback
via erwin
No comments:
Post a Comment