|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
| 3 | +describe Fastlane::Helper::GlotPressDownloader do |
| 4 | + describe 'downloading' do |
| 5 | + context 'when GlotPress returs a 429 code' do |
| 6 | + it 'automatically retries' do |
| 7 | + downloader = described_class.new(true) |
| 8 | + fake_url = 'https://test.com' |
| 9 | + |
| 10 | + count = 0 |
| 11 | + stub_request(:get, fake_url).to_return do |
| 12 | + count += 1 |
| 13 | + if count == 1 |
| 14 | + { status: 429, body: 'Too Many Requests' } |
| 15 | + else |
| 16 | + { status: 200, body: 'OK' } |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + expect(Fastlane::UI).to receive(:message) |
| 21 | + .with(/Received 429 for `#{fake_url}`. Auto retrying in 20 seconds.../) |
| 22 | + |
| 23 | + response = downloader.download(fake_url) |
| 24 | + |
| 25 | + expect(count).to eq(2) |
| 26 | + expect(response.code).to eq('200') |
| 27 | + end |
| 28 | + end |
| 29 | + end |
| 30 | +end |
| 31 | + |
3 | 32 | describe Fastlane::Helper::MetadataDownloader do |
4 | 33 | describe 'downloading from GlotPress' do |
5 | 34 | context 'when GlotPress returs a 429 code' do |
6 | 35 | it 'automatically retries' do |
7 | 36 | in_tmp_dir do |tmp_dir| |
8 | | - metadata_downaloder = described_class.new( |
| 37 | + metadata_downloader = described_class.new( |
9 | 38 | tmp_dir, |
10 | 39 | { key: { desc: 'target-file-name.txt' } }, |
11 | 40 | true |
|
32 | 61 | expect(Fastlane::UI).to receive(:success) |
33 | 62 | .with(/Successfully downloaded `en-AU`./) |
34 | 63 |
|
35 | | - metadata_downaloder.download('en-AU', fake_url, false) |
| 64 | + metadata_downloader.download('en-AU', fake_url, false) |
36 | 65 |
|
37 | 66 | expect(count).to eq(2) |
38 | 67 | end |
|
0 commit comments