|
1 | 1 | require 'spec_helper'
|
2 | 2 | require 'tmpdir'
|
3 | 3 |
|
4 |
| -Locale = Struct.new(:name) |
5 |
| - |
6 | 4 | describe Fastlane::Actions::IosDownloadStringsFilesFromGlotpressAction do
|
7 | 5 | let(:test_data_dir) { File.join(File.dirname(__FILE__), 'test-data', 'translations', 'ios_generate_strings_file_from_code') }
|
8 | 6 |
|
9 | 7 | 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 |
13 | 62 | end
|
14 | 63 |
|
15 | 64 | describe 'error handling' do
|
|
0 commit comments