Skip to content

Commit 41225bf

Browse files
committed
Implement happy path test cases
1 parent dfe96a7 commit 41225bf

File tree

1 file changed

+54
-5
lines changed

1 file changed

+54
-5
lines changed

spec/ios_download_strings_files_from_glotpress_spec.rb

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,64 @@
11
require 'spec_helper'
22
require 'tmpdir'
33

4-
Locale = Struct.new(:name)
5-
64
describe Fastlane::Actions::IosDownloadStringsFilesFromGlotpressAction do
75
let(:test_data_dir) { File.join(File.dirname(__FILE__), 'test-data', 'translations', 'ios_generate_strings_file_from_code') }
86

97
describe 'downloading export files from GlotPress' do
10-
it 'downloads all the locales into the expected directories'
11-
it 'uses the proper filters when exporting the files from GlotPress'
12-
it 'uses a custom table name for the `.strings` files if provided'
8+
let(:gp_fake_url) { 'https://stub.glotpress.com/rspec-fake-project' }
9+
let(:locales_subset) { {'fr-FR': 'fr', 'zh-cn': 'zh-Hans' } }
10+
11+
def gp_stub(locale:, query:)
12+
stub_request(:get, "#{gp_fake_url}/#{locale}/default/export-translations").with(query: query)
13+
end
14+
15+
def test_gp_download(filters:, tablename:, expected_gp_params:)
16+
Dir.mktmpdir('a8c-release-toolkit-tests-') do |tmp_dir|
17+
# Arrange
18+
stub_fr = gp_stub(locale: 'fr-FR', query: expected_gp_params).to_return(body: '"key" = "fr-copy";')
19+
stub_zh = gp_stub(locale: 'zh-cn', query: expected_gp_params).to_return(body: '"key" = "zh-copy";')
20+
21+
# Act
22+
run_described_fastlane_action({
23+
project_url: gp_fake_url,
24+
locales: locales_subset,
25+
download_dir: tmp_dir,
26+
table_basename: tablename,
27+
filters: filters
28+
}.compact)
29+
30+
# Assert
31+
expect(stub_fr).to have_been_made.once
32+
file_fr = File.join(tmp_dir, 'fr.lproj', "#{tablename || 'Localizable'}.strings")
33+
expect(File).to exist(file_fr)
34+
expect(File.read(file_fr)).to eq('"key" = "fr-copy";')
35+
36+
expect(stub_zh).to have_been_made.once
37+
file_zh = File.join(tmp_dir, 'zh-Hans.lproj', "#{tablename || 'Localizable'}.strings")
38+
expect(File).to exist(file_zh)
39+
expect(File.read(file_zh)).to eq('"key" = "zh-copy";')
40+
end
41+
end
42+
43+
it 'downloads all the locales into the expected directories' do
44+
test_gp_download(filters: nil, tablename: nil, expected_gp_params: { 'filters[status]': 'current', format: 'strings' })
45+
end
46+
47+
it 'uses the proper filters when exporting the files from GlotPress' do
48+
test_gp_download(
49+
filters: { term: 'foo', status: 'review' },
50+
tablename: nil,
51+
expected_gp_params: { 'filters[term]': 'foo', 'filters[status]': 'review', format: 'strings' }
52+
)
53+
end
54+
55+
it 'uses a custom table name for the `.strings` files if provided' do
56+
test_gp_download(
57+
filters: nil,
58+
tablename: "MyApp",
59+
expected_gp_params: { 'filters[status]': 'current', format: 'strings' }
60+
)
61+
end
1362
end
1463

1564
describe 'error handling' do

0 commit comments

Comments
 (0)