Skip to content

Commit 0c53205

Browse files
committed
Add test for 200 behavior in GlotPress download
1 parent 6e262dd commit 0c53205

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

spec/glotpress_downloader_spec.rb

+34-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
describe Fastlane::Helper::GlotpressDownloader do
44
describe 'downloading' do
55
context 'when auto retry is enabled' do
6+
context 'when GlotPress returs a 200 code' do
7+
it 'returns the response, without retrying' do
8+
downloader = described_class.new(auto_retry: true)
9+
fake_url = 'https://test.com'
10+
11+
stub_request(:get, fake_url).to_return(status: 200, body: 'OK')
12+
13+
response = downloader.download(fake_url)
14+
15+
expect(response.code).to eq('200')
16+
expect(response.body).to eq('OK')
17+
# Make sure there was no retry
18+
assert_requested(:get, fake_url, times: 1)
19+
end
20+
end
21+
622
context 'when GlotPress returs a 429 code' do
723
it 'retries automatically' do
824
sleep_time = 0.1
@@ -24,7 +40,7 @@
2440

2541
response = downloader.download(fake_url)
2642

27-
expect(count).to eq(2)
43+
assert_requested(:get, fake_url, times: 2)
2844
expect(response.code).to eq('200')
2945
end
3046

@@ -50,13 +66,29 @@
5066

5167
downloader.download(fake_url)
5268

53-
expect(count).to eq(max_retries + 1) # the original request plus the retries
69+
assert_requested(:get, fake_url, times: max_retries + 1) # the original request plus the retries
5470
end
5571
end
5672
end
5773
end
5874

5975
context 'when auto retry is disabled' do
76+
context 'when GlotPress returs a 200 code' do
77+
it 'returns the response, without retrying' do
78+
downloader = described_class.new(auto_retry: false)
79+
fake_url = 'https://test.com'
80+
81+
stub_request(:get, fake_url).to_return(status: 200, body: 'OK')
82+
83+
response = downloader.download(fake_url)
84+
85+
expect(response.code).to eq('200')
86+
expect(response.body).to eq('OK')
87+
# Make sure there was no retry
88+
assert_requested(:get, fake_url, times: 1)
89+
end
90+
end
91+
6092
context 'when GlotPress returs a 429 code' do
6193
it 'prompt the user for confirmation, ignoring the max auto retry parameter' do
6294
sleep_time = 0.1

0 commit comments

Comments
 (0)