Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit 22c00c9

Browse files
committed
add test for pagination caching
1 parent cbd2794 commit 22c00c9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

spec/commands/check_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,40 @@ def stub_json(uri, body)
8585
end
8686
end
8787
end
88+
89+
context 'when paginating through many PRs' do
90+
def stub_body_json(uri, body, headers={})
91+
stub_request(:get, uri)
92+
.to_return(headers: {
93+
'Content-Type' => 'application/json',
94+
'ETag' => Digest::MD5.hexdigest(body.to_json),
95+
}.merge(headers), body: body.to_json)
96+
end
97+
98+
def stub_cache_json(uri)
99+
stub_request(:get, uri)
100+
.to_return(status: 304, body: '[]')
101+
end
102+
103+
it 'uses the cache that already exists' do
104+
pull_requests = (1..100).map do |i|
105+
{ number: i, head: { sha: "abcdef-#{i}", repo: { full_name: 'jtarchie/test' } }, base: { repo: { full_name: 'jtarchie/test' } } }
106+
end
107+
stub_body_json('https://api.github.com/repos/jtarchie/test/pulls?direction=asc&per_page=100&sort=updated&state=open', pull_requests[0..49], {
108+
'Link' => "<https://api.github.com/repos/jtarchie/test/pulls?direction=asc&per_page=100&sort=updated&state=open&page=2>; rel=\"next\""
109+
})
110+
stub_body_json('https://api.github.com/repos/jtarchie/test/pulls?direction=asc&per_page=100&sort=updated&state=open&page=2', pull_requests[50..99])
111+
112+
first_prs = check('source' => { 'repo' => 'jtarchie/test' } )
113+
expect(first_prs.length).to eq 100
114+
Billy.proxy.reset
115+
116+
stub_cache_json('https://api.github.com/repos/jtarchie/test/pulls?direction=asc&per_page=100&sort=updated&state=open')
117+
stub_cache_json('https://api.github.com/repos/jtarchie/test/pulls?direction=asc&per_page=100&sort=updated&state=open&page=2')
118+
second_prs = check('source' => { 'repo' => 'jtarchie/test' } )
119+
120+
expect(first_prs).to eq second_prs
121+
# expect A == B
122+
end
123+
end
88124
end

0 commit comments

Comments
 (0)