From 950d766986216aedb30f95a84d79bedffd171f00 Mon Sep 17 00:00:00 2001 From: Lara Aasem Date: Sun, 19 Mar 2023 21:14:21 +0200 Subject: [PATCH 1/7] feat: Add search glossaries concordance endpoint --- lib/crowdin-api/api_resources/glossaries.rb | 16 ++++++++++++++++ spec/api_resources/glossaries_spec.rb | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/crowdin-api/api_resources/glossaries.rb b/lib/crowdin-api/api_resources/glossaries.rb index 61f36fc..401b776 100644 --- a/lib/crowdin-api/api_resources/glossaries.rb +++ b/lib/crowdin-api/api_resources/glossaries.rb @@ -243,6 +243,22 @@ def delete_concept(glossary_id = nil, concept_id = nil) ) Web::SendRequest.new(request).perform end + + def search_glossaries_concordance(project_id = nil, query = {}) + project_id || raise_parameter_is_required_error(:project_id) + + %i[source_language_id target_language_id expression].each do |param| + query[param] || raise_parameter_is_required_error(param) + end + + request = Web::Request.new( + connection, + :post, + "#{config.target_api_url}/projects/#{project_id}/glossaries/concordance", + { params: query } + ) + Web::SendRequest.new(request).perform + end end end end diff --git a/spec/api_resources/glossaries_spec.rb b/spec/api_resources/glossaries_spec.rb index ae8e5b8..bb50ba3 100644 --- a/spec/api_resources/glossaries_spec.rb +++ b/spec/api_resources/glossaries_spec.rb @@ -206,5 +206,22 @@ expect(concept).to eq(200) end end + + describe '#search_glossaries_concordance' do + let(:project_id) { 1 } + + it 'returns 200 when request is valid', :default do + query = { source_language_id: "en", target_language_id: "ar", expression: "Hello world!" } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") + search_glossaries_concordance = @crowdin.search_glossaries_concordance(project_id, query) + expect(search_glossaries_concordance).to eq(200) + end + + it 'raises ArgumentError when request is missing required query parameter', :default do + query = { source_language_id: "en", target_language_id: "ar" } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") + expect{ @crowdin.search_glossaries_concordance(project_id, query) }.to raise_error(ArgumentError, ":expression is required") + end + end end end From 65c1294bd6e8142dcd668ed4595bbac97fd65707 Mon Sep 17 00:00:00 2001 From: Lara Aasem Date: Sun, 19 Mar 2023 21:14:45 +0200 Subject: [PATCH 2/7] feat: Add add translation alignment endpoint --- lib/crowdin-api/api_resources/translations.rb | 16 ++++++++++++++++ spec/api_resources/translations_spec.rb | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/crowdin-api/api_resources/translations.rb b/lib/crowdin-api/api_resources/translations.rb index 0da678b..5e41aa4 100644 --- a/lib/crowdin-api/api_resources/translations.rb +++ b/lib/crowdin-api/api_resources/translations.rb @@ -139,6 +139,22 @@ def export_project_translation(query = {}, destination = nil, project_id = confi ) Web::SendRequest.new(request, destination).perform end + + def add_translation_alignment(project_id = nil, query = {}) + project_id || raise_parameter_is_required_error(:project_id) + + %i[source_language_id target_language_id text].each do |param| + query[param] || raise_parameter_is_required_error(param) + end + + request = Web::Request.new( + connection, + :post, + "#{config.target_api_url}/projects/#{project_id}/translations/alignment", + { params: query } + ) + Web::SendRequest.new(request).perform + end end end end diff --git a/spec/api_resources/translations_spec.rb b/spec/api_resources/translations_spec.rb index e517b6f..91b3080 100644 --- a/spec/api_resources/translations_spec.rb +++ b/spec/api_resources/translations_spec.rb @@ -103,5 +103,22 @@ expect(export_project_translation).to eq(200) end end + + describe '#add_translation_alignment' do + let(:project_id) { 1 } + + it 'returns 200 when request is valid', :default do + query = { source_language_id: "en", target_language_id: "ar", text: "Hello world!" } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") + add_translation_alignment = @crowdin.add_translation_alignment(project_id, query) + expect(add_translation_alignment).to eq(200) + end + + it 'raises ArgumentError when request is missing required query parameter', :default do + query = { source_language_id: "en", target_language_id: "ar" } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") + expect{ @crowdin.add_translation_alignment(project_id, query) }.to raise_error(ArgumentError, ":text is required") + end + end end end From ca22b97af09cfd13be2ea8894f310e658b591ee5 Mon Sep 17 00:00:00 2001 From: Lara Aasem Date: Sun, 19 Mar 2023 21:14:59 +0200 Subject: [PATCH 3/7] feat: Add search tms concordance endpoint --- .../api_resources/translation_memory.rb | 16 ++++++++++++++++ spec/api_resources/translation_memory_spec.rb | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/crowdin-api/api_resources/translation_memory.rb b/lib/crowdin-api/api_resources/translation_memory.rb index 4284b5a..b4bfa73 100644 --- a/lib/crowdin-api/api_resources/translation_memory.rb +++ b/lib/crowdin-api/api_resources/translation_memory.rb @@ -126,6 +126,22 @@ def check_tm_import_status(tm_id = nil, import_id = nil) ) Web::SendRequest.new(request).perform end + + def search_tms_concordance(project_id = nil, query = {}) + project_id || raise_parameter_is_required_error(:project_id) + + %i[source_language_id target_language_id expression auto_substitution min_relevant].each do |param| + query[param] || raise_parameter_is_required_error(param) + end + + request = Web::Request.new( + connection, + :post, + "#{config.target_api_url}/projects/#{project_id}/tms/concordance", + { params: query } + ) + Web::SendRequest.new(request).perform + end end end end diff --git a/spec/api_resources/translation_memory_spec.rb b/spec/api_resources/translation_memory_spec.rb index c86821c..dded360 100644 --- a/spec/api_resources/translation_memory_spec.rb +++ b/spec/api_resources/translation_memory_spec.rb @@ -110,5 +110,22 @@ expect(check_tm_import_status).to eq(200) end end + + describe '#search_tms_concordance' do + let(:project_id) { 1 } + + it 'returns 200 when request is valid', :default do + query = { source_language_id: "en", target_language_id: "ar", expression: "Hello world!", auto_substitution: true, min_relevant: 60 } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/tms/concordance") + search_tms_concordance = @crowdin.search_tms_concordance(project_id, query) + expect(search_tms_concordance).to eq(200) + end + + it 'raises ArgumentError when request is missing required query parameter', :default do + query = { source_language_id: "en", target_language_id: "ar", expression: "Hello world!", auto_substitution: true } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/tms/concordance") + expect{ @crowdin.search_tms_concordance(project_id, query) }.to raise_error(ArgumentError, ":min_relevant is required") + end + end end end From c88d7b1bdcff49512e7353b4126c068ffbfad6ff Mon Sep 17 00:00:00 2001 From: Lara Aasem Date: Mon, 20 Mar 2023 20:20:31 +0200 Subject: [PATCH 4/7] fix: Lint --- spec/api_resources/glossaries_spec.rb | 8 +++++--- spec/api_resources/translation_memory_spec.rb | 10 +++++++--- spec/api_resources/translations_spec.rb | 8 +++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/spec/api_resources/glossaries_spec.rb b/spec/api_resources/glossaries_spec.rb index bb50ba3..7f1aff0 100644 --- a/spec/api_resources/glossaries_spec.rb +++ b/spec/api_resources/glossaries_spec.rb @@ -211,16 +211,18 @@ let(:project_id) { 1 } it 'returns 200 when request is valid', :default do - query = { source_language_id: "en", target_language_id: "ar", expression: "Hello world!" } + query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!' } stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") search_glossaries_concordance = @crowdin.search_glossaries_concordance(project_id, query) expect(search_glossaries_concordance).to eq(200) end it 'raises ArgumentError when request is missing required query parameter', :default do - query = { source_language_id: "en", target_language_id: "ar" } + query = { source_language_id: 'en', target_language_id: 'ar' } stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") - expect{ @crowdin.search_glossaries_concordance(project_id, query) }.to raise_error(ArgumentError, ":expression is required") + expect do + @crowdin.search_glossaries_concordance(project_id, query) + end.to raise_error(ArgumentError, ':expression is required') end end end diff --git a/spec/api_resources/translation_memory_spec.rb b/spec/api_resources/translation_memory_spec.rb index dded360..878cb79 100644 --- a/spec/api_resources/translation_memory_spec.rb +++ b/spec/api_resources/translation_memory_spec.rb @@ -115,16 +115,20 @@ let(:project_id) { 1 } it 'returns 200 when request is valid', :default do - query = { source_language_id: "en", target_language_id: "ar", expression: "Hello world!", auto_substitution: true, min_relevant: 60 } + query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!', + auto_substitution: true, min_relevant: 60 } stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/tms/concordance") search_tms_concordance = @crowdin.search_tms_concordance(project_id, query) expect(search_tms_concordance).to eq(200) end it 'raises ArgumentError when request is missing required query parameter', :default do - query = { source_language_id: "en", target_language_id: "ar", expression: "Hello world!", auto_substitution: true } + query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!', + auto_substitution: true } stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/tms/concordance") - expect{ @crowdin.search_tms_concordance(project_id, query) }.to raise_error(ArgumentError, ":min_relevant is required") + expect do + @crowdin.search_tms_concordance(project_id, query) + end.to raise_error(ArgumentError, ':min_relevant is required') end end end diff --git a/spec/api_resources/translations_spec.rb b/spec/api_resources/translations_spec.rb index 91b3080..cbb7159 100644 --- a/spec/api_resources/translations_spec.rb +++ b/spec/api_resources/translations_spec.rb @@ -108,16 +108,18 @@ let(:project_id) { 1 } it 'returns 200 when request is valid', :default do - query = { source_language_id: "en", target_language_id: "ar", text: "Hello world!" } + query = { source_language_id: 'en', target_language_id: 'ar', text: 'Hello world!' } stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") add_translation_alignment = @crowdin.add_translation_alignment(project_id, query) expect(add_translation_alignment).to eq(200) end it 'raises ArgumentError when request is missing required query parameter', :default do - query = { source_language_id: "en", target_language_id: "ar" } + query = { source_language_id: 'en', target_language_id: 'ar' } stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") - expect{ @crowdin.add_translation_alignment(project_id, query) }.to raise_error(ArgumentError, ":text is required") + expect do + @crowdin.add_translation_alignment(project_id, query) + end.to raise_error(ArgumentError, ':text is required') end end end From d87b4264bd536dffea40b2e8bfdaebb0ea674348 Mon Sep 17 00:00:00 2001 From: Lara Aasem Date: Mon, 20 Mar 2023 20:23:56 +0200 Subject: [PATCH 5/7] refactor: Move add_translation_alignment to string_translations resource --- .../api_resources/string_translations.rb | 16 ++++++++++++++++ lib/crowdin-api/api_resources/translations.rb | 16 ---------------- .../api_resources/string_translations_spec.rb | 19 +++++++++++++++++++ spec/api_resources/translations_spec.rb | 19 ------------------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/crowdin-api/api_resources/string_translations.rb b/lib/crowdin-api/api_resources/string_translations.rb index a02638b..b746b80 100644 --- a/lib/crowdin-api/api_resources/string_translations.rb +++ b/lib/crowdin-api/api_resources/string_translations.rb @@ -188,6 +188,22 @@ def cancel_vote(vote_id = nil, project_id = config.project_id) ) Web::SendRequest.new(request).perform end + + def add_translation_alignment(project_id = nil, query = {}) + project_id || raise_parameter_is_required_error(:project_id) + + %i[source_language_id target_language_id text].each do |param| + query[param] || raise_parameter_is_required_error(param) + end + + request = Web::Request.new( + connection, + :post, + "#{config.target_api_url}/projects/#{project_id}/translations/alignment", + { params: query } + ) + Web::SendRequest.new(request).perform + end end end end diff --git a/lib/crowdin-api/api_resources/translations.rb b/lib/crowdin-api/api_resources/translations.rb index 5e41aa4..0da678b 100644 --- a/lib/crowdin-api/api_resources/translations.rb +++ b/lib/crowdin-api/api_resources/translations.rb @@ -139,22 +139,6 @@ def export_project_translation(query = {}, destination = nil, project_id = confi ) Web::SendRequest.new(request, destination).perform end - - def add_translation_alignment(project_id = nil, query = {}) - project_id || raise_parameter_is_required_error(:project_id) - - %i[source_language_id target_language_id text].each do |param| - query[param] || raise_parameter_is_required_error(param) - end - - request = Web::Request.new( - connection, - :post, - "#{config.target_api_url}/projects/#{project_id}/translations/alignment", - { params: query } - ) - Web::SendRequest.new(request).perform - end end end end diff --git a/spec/api_resources/string_translations_spec.rb b/spec/api_resources/string_translations_spec.rb index 88fe864..8022c84 100644 --- a/spec/api_resources/string_translations_spec.rb +++ b/spec/api_resources/string_translations_spec.rb @@ -137,5 +137,24 @@ expect(cancel_vote).to eq(200) end end + + describe '#add_translation_alignment' do + let(:project_id) { 1 } + + it 'returns 200 when request is valid', :default do + query = { source_language_id: 'en', target_language_id: 'ar', text: 'Hello world!' } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") + add_translation_alignment = @crowdin.add_translation_alignment(project_id, query) + expect(add_translation_alignment).to eq(200) + end + + it 'raises ArgumentError when request is missing required query parameter', :default do + query = { source_language_id: 'en', target_language_id: 'ar' } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") + expect do + @crowdin.add_translation_alignment(project_id, query) + end.to raise_error(ArgumentError, ':text is required') + end + end end end diff --git a/spec/api_resources/translations_spec.rb b/spec/api_resources/translations_spec.rb index cbb7159..e517b6f 100644 --- a/spec/api_resources/translations_spec.rb +++ b/spec/api_resources/translations_spec.rb @@ -103,24 +103,5 @@ expect(export_project_translation).to eq(200) end end - - describe '#add_translation_alignment' do - let(:project_id) { 1 } - - it 'returns 200 when request is valid', :default do - query = { source_language_id: 'en', target_language_id: 'ar', text: 'Hello world!' } - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") - add_translation_alignment = @crowdin.add_translation_alignment(project_id, query) - expect(add_translation_alignment).to eq(200) - end - - it 'raises ArgumentError when request is missing required query parameter', :default do - query = { source_language_id: 'en', target_language_id: 'ar' } - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/translations/alignment") - expect do - @crowdin.add_translation_alignment(project_id, query) - end.to raise_error(ArgumentError, ':text is required') - end - end end end From cf77c292e8d1152bf4320ce575c5e11e275670ab Mon Sep 17 00:00:00 2001 From: Lara Aasem Date: Mon, 20 Mar 2023 20:25:44 +0200 Subject: [PATCH 6/7] refactor: Use raise_project_id_is_required_error for project_id instead of generic method --- lib/crowdin-api/api_resources/glossaries.rb | 2 +- lib/crowdin-api/api_resources/string_translations.rb | 2 +- lib/crowdin-api/api_resources/translation_memory.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/crowdin-api/api_resources/glossaries.rb b/lib/crowdin-api/api_resources/glossaries.rb index 401b776..163954b 100644 --- a/lib/crowdin-api/api_resources/glossaries.rb +++ b/lib/crowdin-api/api_resources/glossaries.rb @@ -245,7 +245,7 @@ def delete_concept(glossary_id = nil, concept_id = nil) end def search_glossaries_concordance(project_id = nil, query = {}) - project_id || raise_parameter_is_required_error(:project_id) + project_id || raise_project_id_is_required_error %i[source_language_id target_language_id expression].each do |param| query[param] || raise_parameter_is_required_error(param) diff --git a/lib/crowdin-api/api_resources/string_translations.rb b/lib/crowdin-api/api_resources/string_translations.rb index b746b80..b0c3070 100644 --- a/lib/crowdin-api/api_resources/string_translations.rb +++ b/lib/crowdin-api/api_resources/string_translations.rb @@ -190,7 +190,7 @@ def cancel_vote(vote_id = nil, project_id = config.project_id) end def add_translation_alignment(project_id = nil, query = {}) - project_id || raise_parameter_is_required_error(:project_id) + project_id || raise_project_id_is_required_error %i[source_language_id target_language_id text].each do |param| query[param] || raise_parameter_is_required_error(param) diff --git a/lib/crowdin-api/api_resources/translation_memory.rb b/lib/crowdin-api/api_resources/translation_memory.rb index b4bfa73..831f887 100644 --- a/lib/crowdin-api/api_resources/translation_memory.rb +++ b/lib/crowdin-api/api_resources/translation_memory.rb @@ -128,7 +128,7 @@ def check_tm_import_status(tm_id = nil, import_id = nil) end def search_tms_concordance(project_id = nil, query = {}) - project_id || raise_parameter_is_required_error(:project_id) + project_id || raise_project_id_is_required_error %i[source_language_id target_language_id expression auto_substitution min_relevant].each do |param| query[param] || raise_parameter_is_required_error(param) From 9e030f5351ce7edb7f484a358377df222566b8d3 Mon Sep 17 00:00:00 2001 From: Lara Aasem Date: Tue, 21 Mar 2023 22:15:13 +0200 Subject: [PATCH 7/7] refactor: Fix linting error by breaking up large describe block --- spec/api_resources/glossaries_spec.rb | 332 +++++++++++++------------- 1 file changed, 167 insertions(+), 165 deletions(-) diff --git a/spec/api_resources/glossaries_spec.rb b/spec/api_resources/glossaries_spec.rb index 7f1aff0..c137c13 100644 --- a/spec/api_resources/glossaries_spec.rb +++ b/spec/api_resources/glossaries_spec.rb @@ -1,229 +1,231 @@ # frozen_string_literal: true -describe Crowdin::ApiResources::Glossaries do - describe 'Default endpoints' do - describe '#list_glossaries' do - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries") - list_glossaries = @crowdin.list_glossaries - expect(list_glossaries).to eq(200) - end +describe Crowdin::ApiResources::Glossaries, 'Default endpoints' do + describe '#list_glossaries' do + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries") + list_glossaries = @crowdin.list_glossaries + expect(list_glossaries).to eq(200) end + end - describe '#add_glossary' do - it 'when request are valid', :default do - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries") - add_glossary = @crowdin.add_glossary - expect(add_glossary).to eq(200) - end + describe '#add_glossary' do + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries") + add_glossary = @crowdin.add_glossary + expect(add_glossary).to eq(200) end + end - describe '#get_glossary' do - let(:glossary_id) { 1 } + describe '#get_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") - get_glossary = @crowdin.get_glossary(glossary_id) - expect(get_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") + get_glossary = @crowdin.get_glossary(glossary_id) + expect(get_glossary).to eq(200) end + end - describe '#delete_glossary' do - let(:glossary_id) { 1 } + describe '#delete_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") - delete_glossary = @crowdin.delete_glossary(glossary_id) - expect(delete_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") + delete_glossary = @crowdin.delete_glossary(glossary_id) + expect(delete_glossary).to eq(200) end + end - describe '#edit_glossary' do - let(:glossary_id) { 1 } + describe '#edit_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") - edit_glossary = @crowdin.edit_glossary(glossary_id) - expect(edit_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}") + edit_glossary = @crowdin.edit_glossary(glossary_id) + expect(edit_glossary).to eq(200) end + end - describe '#export_glossary' do - let(:glossary_id) { 1 } + describe '#export_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports") - export_glossary = @crowdin.export_glossary({}, glossary_id) - expect(export_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports") + export_glossary = @crowdin.export_glossary({}, glossary_id) + expect(export_glossary).to eq(200) end + end - describe '#check_glossary_export_status' do - let(:glossary_id) { 1 } - let(:export_id) { 1 } + describe '#check_glossary_export_status' do + let(:glossary_id) { 1 } + let(:export_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}") - check_glossary_export_status = @crowdin.check_glossary_export_status(glossary_id, export_id) - expect(check_glossary_export_status).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}") + check_glossary_export_status = @crowdin.check_glossary_export_status(glossary_id, export_id) + expect(check_glossary_export_status).to eq(200) end + end - describe '#download_glossary' do - let(:glossary_id) { 1 } - let(:export_id) { 1 } + describe '#download_glossary' do + let(:glossary_id) { 1 } + let(:export_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}/download") - download_glossary = @crowdin.download_glossary(glossary_id, export_id) - expect(download_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/exports/#{export_id}/download") + download_glossary = @crowdin.download_glossary(glossary_id, export_id) + expect(download_glossary).to eq(200) end + end - describe '#import_glossary' do - let(:glossary_id) { 1 } + describe '#import_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports") - import_glossary = @crowdin.import_glossary(glossary_id) - expect(import_glossary).to eq(200) - end + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports") + import_glossary = @crowdin.import_glossary(glossary_id) + expect(import_glossary).to eq(200) end + end - describe '#check_glossary_import_status' do - let(:glossary_id) { 1 } - let(:import_id) { 1 } + describe '#check_glossary_import_status' do + let(:glossary_id) { 1 } + let(:import_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports/#{import_id}") - check_glossary_import_status = @crowdin.check_glossary_import_status(glossary_id, import_id) - expect(check_glossary_import_status).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/imports/#{import_id}") + check_glossary_import_status = @crowdin.check_glossary_import_status(glossary_id, import_id) + expect(check_glossary_import_status).to eq(200) end + end - describe '#list_terms' do - let(:glossary_id) { 1 } + describe '#clear_glossary' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") - list_terms = @crowdin.list_terms(glossary_id) - expect(list_terms).to eq(200) - end + it 'when request are valid', :default do + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") + clear_glossary = @crowdin.clear_glossary(glossary_id) + expect(clear_glossary).to eq(200) end + end - describe '#add_term' do - let(:glossary_id) { 1 } + describe '#search_glossaries_concordance' do + let(:project_id) { 1 } - it 'when request are valid', :default do - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") - add_term = @crowdin.add_term(glossary_id) - expect(add_term).to eq(200) - end + it 'returns 200 when request is valid', :default do + query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!' } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") + search_glossaries_concordance = @crowdin.search_glossaries_concordance(project_id, query) + expect(search_glossaries_concordance).to eq(200) end - describe '#clear_glossary' do - let(:glossary_id) { 1 } - - it 'when request are valid', :default do - stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") - clear_glossary = @crowdin.clear_glossary(glossary_id) - expect(clear_glossary).to eq(200) - end + it 'raises ArgumentError when request is missing required query parameter', :default do + query = { source_language_id: 'en', target_language_id: 'ar' } + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") + expect do + @crowdin.search_glossaries_concordance(project_id, query) + end.to raise_error(ArgumentError, ':expression is required') end + end +end - describe '#get_term' do - let(:glossary_id) { 1 } - let(:term_id) { 1 } +describe Crowdin::ApiResources::Glossaries, 'Concept endpoints' do + describe '#list_concepts' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") - get_term = @crowdin.get_term(glossary_id, term_id) - expect(get_term).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts") + concepts = @crowdin.list_concepts(glossary_id) + expect(concepts).to eq(200) end + end - describe '#delete_term' do - let(:glossary_id) { 1 } - let(:term_id) { 1 } + describe '#get_concept' do + let(:glossary_id) { 1 } + let(:concept_id) { 1 } - it 'when request are valid', :default do - stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") - delete_term = @crowdin.delete_term(glossary_id, term_id) - expect(delete_term).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") + concept = @crowdin.get_concept(glossary_id, concept_id) + expect(concept).to eq(200) end + end - describe '#edit_term' do - let(:glossary_id) { 1 } - let(:term_id) { 1 } + describe '#update_concept' do + let(:glossary_id) { 1 } + let(:concept_id) { 1 } - it 'when request are valid', :default do - stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") - edit_term = @crowdin.edit_term(glossary_id, term_id) - expect(edit_term).to eq(200) - end + it 'when request are valid', :default do + stub_request(:put, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") + concept = @crowdin.update_concept(glossary_id, concept_id) + expect(concept).to eq(200) end + end - describe '#list_concepts' do - let(:glossary_id) { 1 } + describe '#update_concept' do + let(:glossary_id) { 1 } + let(:concept_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts") - concepts = @crowdin.list_concepts(glossary_id) - expect(concepts).to eq(200) - end + it 'when request are valid', :default do + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") + concept = @crowdin.delete_concept(glossary_id, concept_id) + expect(concept).to eq(200) end + end +end - describe '#get_concept' do - let(:glossary_id) { 1 } - let(:concept_id) { 1 } +describe Crowdin::ApiResources::Glossaries, 'Term endpoints' do + describe '#list_terms' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") - concept = @crowdin.get_concept(glossary_id, concept_id) - expect(concept).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") + list_terms = @crowdin.list_terms(glossary_id) + expect(list_terms).to eq(200) end + end - describe '#update_concept' do - let(:glossary_id) { 1 } - let(:concept_id) { 1 } + describe '#add_term' do + let(:glossary_id) { 1 } - it 'when request are valid', :default do - stub_request(:put, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") - concept = @crowdin.update_concept(glossary_id, concept_id) - expect(concept).to eq(200) - end + it 'when request are valid', :default do + stub_request(:post, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms") + add_term = @crowdin.add_term(glossary_id) + expect(add_term).to eq(200) end + end - describe '#update_concept' do - let(:glossary_id) { 1 } - let(:concept_id) { 1 } + describe '#get_term' do + let(:glossary_id) { 1 } + let(:term_id) { 1 } - it 'when request are valid', :default do - stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/concepts/#{concept_id}") - concept = @crowdin.delete_concept(glossary_id, concept_id) - expect(concept).to eq(200) - end + it 'when request are valid', :default do + stub_request(:get, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") + get_term = @crowdin.get_term(glossary_id, term_id) + expect(get_term).to eq(200) end + end - describe '#search_glossaries_concordance' do - let(:project_id) { 1 } + describe '#delete_term' do + let(:glossary_id) { 1 } + let(:term_id) { 1 } + + it 'when request are valid', :default do + stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") + delete_term = @crowdin.delete_term(glossary_id, term_id) + expect(delete_term).to eq(200) + end + end - it 'returns 200 when request is valid', :default do - query = { source_language_id: 'en', target_language_id: 'ar', expression: 'Hello world!' } - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") - search_glossaries_concordance = @crowdin.search_glossaries_concordance(project_id, query) - expect(search_glossaries_concordance).to eq(200) - end + describe '#edit_term' do + let(:glossary_id) { 1 } + let(:term_id) { 1 } - it 'raises ArgumentError when request is missing required query parameter', :default do - query = { source_language_id: 'en', target_language_id: 'ar' } - stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/glossaries/concordance") - expect do - @crowdin.search_glossaries_concordance(project_id, query) - end.to raise_error(ArgumentError, ':expression is required') - end + it 'when request are valid', :default do + stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/glossaries/#{glossary_id}/terms/#{term_id}") + edit_term = @crowdin.edit_term(glossary_id, term_id) + expect(edit_term).to eq(200) end end end