Skip to content

Commit

Permalink
test: better pagination smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Jan 14, 2018
1 parent ec2c192 commit 37933b2
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions test/integration/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,29 @@ describe('smoke', () => {
it('pagination', (done) => {
nock('https://smoke-test.com')
.get('/organizations')
.query({page: 2, per_page: 1})
.query({page: 3, per_page: 1})
.reply(200, [{}], {
'Link': '<https://api.github.com/organizations?page=3>; rel="next", <https://api.github.com/organizations?page=0>; rel="first", <https://api.github.com/organizations?page=1>; rel="prev"',
'Link': '<https://smoke-test.com/organizations?page=4&per_page=1>; rel="next", <https://smoke-test.com/organizations?page=1&per_page=1>; rel="first", <https://smoke-test.com/organizations?page=2&per_page=1>; rel="prev"',
'X-GitHub-Media-Type': 'github.v3; format=json'
})

.get('/organizations')
.query({page: 0})
.query({page: 1, per_page: 1})
.reply(200, [{}])
.get('/organizations')
.query({page: 1})
.query({page: 2, per_page: 1})
.reply(200, [{}])
.get('/organizations')
.query({page: 3})
.query({page: 4, per_page: 1})
.reply(404, {})

const github = new GitHub({
host: 'smoke-test.com'
})

github.orgs.getAll({
per_page: 1,
page: 2
page: 3,
per_page: 1
})

.then((result) => {
Expand All @@ -92,28 +92,40 @@ describe('smoke', () => {
github.hasFirstPage(result).should.be.a('string')
should.not.exist(github.hasLastPage(result))

const customHeaders = {foo: 'bar'}
const callback = () => {}
github.getFirstPage(result, (error, result) => {
if (error) {
return done(error)
}

should.not.throw(() => {
github.hasPreviousPage(result)
})
should.not.exist(github.hasPreviousPage(result))

done()
})
github.getPreviousPage(result, customHeaders)
github.getNextPage(result).catch(callback)
github.getLastPage(result, customHeaders, (error) => {
error.code.should.equal('404')
})
Promise.all([
new Promise((resolve, reject) => {
github.getFirstPage(result, (error, result) => {
if (error) {
return reject(error)
}

should.not.throw(() => {
github.hasPreviousPage(result)
})
should.not.exist(github.hasPreviousPage(result))

resolve()
})
}),
github.getPreviousPage(result, {foo: 'bar', accept: 'application/vnd.github.v3+json'}),
github.getNextPage(result).catch(callback),
new Promise(resolve => {
github.getLastPage(result, { foo: 'bar' }, (error) => {
error.code.should.equal('404')
resolve()
})
}),
// test error with promise
github.getLastPage(result).catch(callback)
])
})

// test error with promise
github.getLastPage(result).catch(callback)
.then(() => {
done()
})

.catch(done)
})
})

0 comments on commit 37933b2

Please sign in to comment.