Skip to content

Commit 25662a7

Browse files
osahnerkunalkapadia
authored andcommitted
fix: skip and limit cast to number in user.model + add test case (#306)
1 parent 8bc61e2 commit 25662a7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

server/models/user.model.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ UserSchema.statics = {
6565
list({ skip = 0, limit = 50 } = {}) {
6666
return this.find()
6767
.sort({ createdAt: -1 })
68-
.skip(skip)
69-
.limit(limit)
68+
.skip(+skip)
69+
.limit(+limit)
7070
.exec();
7171
}
7272
};

server/tests/user.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ describe('## User APIs', () => {
9191
})
9292
.catch(done);
9393
});
94+
95+
it('should get all users (with limit and skip)', (done) => {
96+
request(app)
97+
.get('/api/users')
98+
.query({ limit: 10, skip: 1 })
99+
.expect(httpStatus.OK)
100+
.then((res) => {
101+
expect(res.body).to.be.an('array');
102+
done();
103+
})
104+
.catch(done);
105+
});
94106
});
95107

96108
describe('# DELETE /api/users/', () => {

0 commit comments

Comments
 (0)