@@ -4,32 +4,41 @@ const { findLatestCommitInPr } = require('../../lib/push-jenkins-update')
44
55const nock = require ( 'nock' )
66const readFixture = require ( '../read-fixture' )
7- const { ignoreQueryParams } = require ( '../common' )
87
98tap . test ( 'findLatestCommitInPr: paginates results when more than 100 commits in a PR' , async ( t ) => {
10- const commitsFixturePage1 = readFixture ( 'pull-requests-commits-page-1.json' )
11- const commitsFixturePage104 = readFixture ( 'pull-requests-commits-page-104.json' )
9+ const commitsFixturePage1 = readFixture ( 'pull-request-commits-page-1.json' )
10+ const commitsFixturePage2 = readFixture ( 'pull-request-commits-page-2.json' )
11+ const commitsFixturePage3 = readFixture ( 'pull-request-commits-page-3.json' )
12+ const commitsFixturePage4 = readFixture ( 'pull-request-commits-page-4.json' )
1213 const owner = 'nodejs'
1314 const repo = 'node'
1415 const pr = 9745
1516
16- const headers = {
17- Link : '<https://api.github.com/repos/nodejs/node/pulls/9745/commits?page=104>; rel="last"'
18- }
1917 const firstPageScope = nock ( 'https://api.github.com' )
20- . filteringPath ( ignoreQueryParams )
2118 . get ( `/repos/${ owner } /${ repo } /pulls/${ pr } /commits` )
22- . reply ( 200 , commitsFixturePage1 , headers )
19+ . reply ( 200 , commitsFixturePage1 , { link : '<https://api.github.com/repositories/27193779/pulls/9745/commits?page=2>; rel="next", <https://api.github.com/repositories/27193779/pulls/9745/commits?page=4>; rel="last"' } )
2320
24- const lastPageScope = nock ( 'https://api.github.com' )
25- . get ( `/repos/${ owner } /${ repo } /pulls/${ pr } /commits` )
26- . query ( { page : 104 , per_page : 100 } )
27- . reply ( 200 , commitsFixturePage104 )
21+ const secondPageScope = nock ( 'https://api.github.com' )
22+ . get ( `/repositories/27193779/pulls/${ pr } /commits` )
23+ . query ( { page : 2 } )
24+ . reply ( 200 , commitsFixturePage2 , { link : '<https://api.github.com/repositories/27193779/pulls/9745/commits?page=1>; rel="prev", <https://api.github.com/repositories/27193779/pulls/9745/commits?page=3>; rel="next", <https://api.github.com/repositories/27193779/pulls/9745/commits?page=4>; rel="last", <https://api.github.com/repositories/27193779/pulls/9745/commits?page=1>; rel="first"' } )
25+
26+ const thirdPageScope = nock ( 'https://api.github.com' )
27+ . get ( `/repositories/27193779/pulls/${ pr } /commits` )
28+ . query ( { page : 3 } )
29+ . reply ( 200 , commitsFixturePage3 , { link : '<https://api.github.com/repositories/27193779/pulls/9745/commits?page=2>; rel="prev", <https://api.github.com/repositories/27193779/pulls/9745/commits?page=4>; rel="next", <https://api.github.com/repositories/27193779/pulls/9745/commits?page=4>; rel="last", <https://api.github.com/repositories/27193779/pulls/9745/commits?page=1>; rel="first"' } )
30+
31+ const fourthPageScope = nock ( 'https://api.github.com' )
32+ . get ( `/repositories/27193779/pulls/${ pr } /commits` )
33+ . query ( { page : 4 } )
34+ . reply ( 200 , commitsFixturePage4 , { link : '<https://api.github.com/repositories/27193779/pulls/9745/commits?page=3>; rel="prev", <https://api.github.com/repositories/27193779/pulls/9745/commits?page=1>; rel="first"' } )
2835
2936 t . plan ( 1 )
3037
3138 const commit = await findLatestCommitInPr ( { owner, repo, pr } )
3239 t . equal ( commit . sha , 'c1aa949064892dbe693750686c06f4ad5673e577' )
3340 firstPageScope . done ( )
34- lastPageScope . done ( )
41+ secondPageScope . done ( )
42+ thirdPageScope . done ( )
43+ fourthPageScope . done ( )
3544} )
0 commit comments