Skip to content

Commit c63fb04

Browse files
committed
Add test for GlotPressDownaloader
1 parent d447ed0 commit c63fb04

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

spec/metadata_download_helper_spec.rb

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
11
require 'spec_helper'
22

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+
332
describe Fastlane::Helper::MetadataDownloader do
433
describe 'downloading from GlotPress' do
534
context 'when GlotPress returs a 429 code' do
635
it 'automatically retries' do
736
in_tmp_dir do |tmp_dir|
8-
metadata_downaloder = described_class.new(
37+
metadata_downloader = described_class.new(
938
tmp_dir,
1039
{ key: { desc: 'target-file-name.txt' } },
1140
true
@@ -32,7 +61,7 @@
3261
expect(Fastlane::UI).to receive(:success)
3362
.with(/Successfully downloaded `en-AU`./)
3463

35-
metadata_downaloder.download('en-AU', fake_url, false)
64+
metadata_downloader.download('en-AU', fake_url, false)
3665

3766
expect(count).to eq(2)
3867
end

0 commit comments

Comments
 (0)