|
3 | 3 | describe Fastlane::Helper::GlotpressDownloader do
|
4 | 4 | describe 'downloading' do
|
5 | 5 | 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 | + |
6 | 22 | context 'when GlotPress returs a 429 code' do
|
7 | 23 | it 'retries automatically' do
|
8 | 24 | sleep_time = 0.1
|
|
24 | 40 |
|
25 | 41 | response = downloader.download(fake_url)
|
26 | 42 |
|
27 |
| - expect(count).to eq(2) |
| 43 | + assert_requested(:get, fake_url, times: 2) |
28 | 44 | expect(response.code).to eq('200')
|
29 | 45 | end
|
30 | 46 |
|
|
50 | 66 |
|
51 | 67 | downloader.download(fake_url)
|
52 | 68 |
|
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 |
54 | 70 | end
|
55 | 71 | end
|
56 | 72 | end
|
57 | 73 | end
|
58 | 74 |
|
59 | 75 | 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 | + |
60 | 92 | context 'when GlotPress returs a 429 code' do
|
61 | 93 | it 'prompt the user for confirmation, ignoring the max auto retry parameter' do
|
62 | 94 | sleep_time = 0.1
|
|
0 commit comments