From 37933b2859ada636c1a57c927d386acc0f1a5791 Mon Sep 17 00:00:00 2001 From: Gregor Date: Wed, 10 Jan 2018 21:37:17 -0800 Subject: [PATCH] test: better pagination smoke test --- test/integration/smoke-test.js | 64 ++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/test/integration/smoke-test.js b/test/integration/smoke-test.js index 14fdd0987e..380c3dcac2 100644 --- a/test/integration/smoke-test.js +++ b/test/integration/smoke-test.js @@ -61,20 +61,20 @@ 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': '; rel="next", ; rel="first", ; rel="prev"', + 'Link': '; rel="next", ; rel="first", ; 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({ @@ -82,8 +82,8 @@ describe('smoke', () => { }) github.orgs.getAll({ - per_page: 1, - page: 2 + page: 3, + per_page: 1 }) .then((result) => { @@ -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) }) })