Add basic pagination

This commit is contained in:
typicode
2016-07-04 20:13:41 +02:00
parent 706ab46d55
commit 3a23d8663b
2 changed files with 53 additions and 4 deletions

View File

@ -51,6 +51,24 @@ describe('Server', function () {
{resource: {name: 'howe'}}
]
db.list = [
{id: 1},
{id: 2},
{id: 3},
{id: 4},
{id: 5},
{id: 6},
{id: 7},
{id: 8},
{id: 9},
{id: 10},
{id: 11},
{id: 12},
{id: 13},
{id: 14},
{id: 15}
]
server = jsonServer.create()
router = jsonServer.router(db)
server.use(jsonServer.defaults())
@ -236,6 +254,30 @@ describe('Server', function () {
})
})
describe('GET /:resource?_page=', function () {
it('should paginate', function (done) {
request(server)
.get('/list?_page=2')
.expect('Content-Type', /json/)
.expect('x-total-count', db.list.length.toString())
.expect('Access-Control-Expose-Headers', 'X-Total-Count')
.expect(db.list.slice(10, 20))
.expect(200, done)
})
})
describe('GET /:resource?_page=&_limit=', function () {
it('should paginate with a custom limit', function (done) {
request(server)
.get('/list?_page=2&_limit=1')
.expect('Content-Type', /json/)
.expect('x-total-count', db.list.length.toString())
.expect('Access-Control-Expose-Headers', 'X-Total-Count')
.expect(db.list.slice(1, 2))
.expect(200, done)
})
})
describe('GET /:resource?attr_gte=&attr_lte=', function () {
it('should respond with a limited array', function (done) {
request(server)