Skip to content

Commit

Permalink
fix(build_project_file_translation): error when the eTag param is p…
Browse files Browse the repository at this point in the history
…assed (#75)
  • Loading branch information
artem-vavilov authored Feb 12, 2024
1 parent 7703007 commit 5508a1d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/crowdin-api/api_resources/translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def build_project_file_translation(file_id = nil, query = {}, destination = nil,
file_id || raise_parameter_is_required_error(:file_id)
project_id || raise_project_id_is_required_error

headers = query[:eTag] ? { 'If-None-Match' => query[:eTag] } : {}
etag = query.delete(:eTag)
headers = etag ? { 'If-None-Match' => etag } : {}

request = Web::Request.new(
connection,
Expand Down
43 changes: 40 additions & 3 deletions spec/api_resources/translations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,49 @@
end

describe '#build_project_file_translation' do
subject(:build_project_file_translation) do
@crowdin.build_project_file_translation(file_id, query, destination, project_id)
end

let(:file_id) { 1 }
let(:query) { { targetLanguageId: target_language_id } }
let(:destination) { nil }

let(:target_language_id) { 'expected_language_id' }

it 'builds project file translation', :default do
expected_response = 'expected_response'

it 'when request are valid', :default do
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/builds/files/#{file_id}")
build_project_file_translation = @crowdin.build_project_file_translation(file_id, {}, nil, project_id)
expect(build_project_file_translation).to eq(200)
.with(
body: JSON.dump(query)
)
.to_return(
body: JSON.dump(expected_response)
)

is_expected.to eq(expected_response)
end

context 'when the `eTag` query param is passed' do
let(:query) { { targetLanguageId: 'expected_language_id', eTag: etag } }

let(:etag) { 'expected_etag' }

it 'builds project file translation for new changes after the passed `eTag`', :default do
expected_response = 'expected_response'

stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/builds/files/#{file_id}")
.with(
body: JSON.dump({ targetLanguageId: target_language_id }),
headers: { 'If-None-Match' => etag }
)
.to_return(
body: JSON.dump(expected_response)
)

is_expected.to eq(expected_response)
end
end
end

Expand Down

0 comments on commit 5508a1d

Please sign in to comment.