From e8bbce904347642fdada51d9679d718457453568 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Tue, 27 Aug 2024 21:50:18 +0200 Subject: [PATCH] Fix tests --- spec/lib/translation_service/deepl_spec.rb | 6 ++--- .../libre_translate_spec.rb | 4 ++-- .../api/v1/statuses/translations_spec.rb | 2 +- .../services/translate_status_service_spec.rb | 22 +++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/lib/translation_service/deepl_spec.rb b/spec/lib/translation_service/deepl_spec.rb index 4797a3dc63..e7156c6dfc 100644 --- a/spec/lib/translation_service/deepl_spec.rb +++ b/spec/lib/translation_service/deepl_spec.rb @@ -38,7 +38,7 @@ RSpec.describe TranslationService::DeepL do .with(body: 'text=Guten+Tag&source_lang&target_lang=en&tag_handling=html') .to_return(body: '{"translations":[{"detected_source_language":"DE","text":"Good morning"}]}') - translations = service.translate(['Guten Tag'], nil, 'en') + translations = service.translate(['Guten Tag'], 'und', 'en') expect(translations.size).to eq 1 translation = translations.first @@ -62,7 +62,7 @@ RSpec.describe TranslationService::DeepL do describe '#languages' do it 'returns source languages' do - expect(service.languages.keys).to eq [nil, 'en', 'uk'] + expect(service.languages.keys).to eq %w(und en uk) end it 'returns target languages for each source language' do @@ -71,7 +71,7 @@ RSpec.describe TranslationService::DeepL do end it 'returns target languages for auto-detection' do - expect(service.languages[nil]).to eq %w(en pt en-GB zh) + expect(service.languages['und']).to eq %w(en pt en-GB zh) end end diff --git a/spec/lib/translation_service/libre_translate_spec.rb b/spec/lib/translation_service/libre_translate_spec.rb index 90966a8ebf..08433e6ff0 100644 --- a/spec/lib/translation_service/libre_translate_spec.rb +++ b/spec/lib/translation_service/libre_translate_spec.rb @@ -15,7 +15,7 @@ RSpec.describe TranslationService::LibreTranslate do subject(:languages) { service.languages } it 'returns source languages' do - expect(languages.keys).to eq ['en', 'da', nil] + expect(languages.keys).to eq %w(en da und) end it 'returns target languages for each source language' do @@ -24,7 +24,7 @@ RSpec.describe TranslationService::LibreTranslate do end it 'returns target languages for auto-detected language' do - expect(languages[nil]).to eq %w(de en es pt) + expect(languages['und']).to eq %w(de en es pt) end end diff --git a/spec/requests/api/v1/statuses/translations_spec.rb b/spec/requests/api/v1/statuses/translations_spec.rb index e2ab5d0b80..d198b929da 100644 --- a/spec/requests/api/v1/statuses/translations_spec.rb +++ b/spec/requests/api/v1/statuses/translations_spec.rb @@ -32,7 +32,7 @@ describe 'API V1 Statuses Translations' do translation = TranslationService::Translation.new(text: 'Hello') service = instance_double(TranslationService::DeepL, translate: [translation]) allow(TranslationService).to receive_messages(configured?: true, configured: service) - Rails.cache.write('translation_service/languages', { 'es' => ['en'] }) + Rails.cache.write('v2:translation_service/languages', { 'es' => ['en'] }) post "/api/v1/statuses/#{status.id}/translate", headers: headers end diff --git a/spec/services/translate_status_service_spec.rb b/spec/services/translate_status_service_spec.rb index 0779fbbe6c..fe26ad332e 100644 --- a/spec/services/translate_status_service_spec.rb +++ b/spec/services/translate_status_service_spec.rb @@ -33,32 +33,32 @@ RSpec.describe TranslateStatusService do end it 'returns translated status content' do - expect(service.call(status, 'es').content).to eq '

Hola

' + expect(service.call(status, nil, 'es').content).to eq '

Hola

' end it 'returns source language' do - expect(service.call(status, 'es').detected_source_language).to eq 'en' + expect(service.call(status, nil, 'es').detected_source_language).to eq 'en' end it 'returns translation provider' do - expect(service.call(status, 'es').provider).to eq 'Dummy' + expect(service.call(status, nil, 'es').provider).to eq 'Dummy' end it 'returns original status' do - expect(service.call(status, 'es').status).to eq status + expect(service.call(status, nil, 'es').status).to eq status end describe 'status has content with custom emoji' do let(:text) { 'Hello & :highfive:' } it 'does not translate shortcode' do - expect(service.call(status, 'es').content).to eq '

Hola & :highfive:

' + expect(service.call(status, nil, 'es').content).to eq '

Hola & :highfive:

' end end describe 'status has no spoiler_text' do it 'returns an empty string' do - expect(service.call(status, 'es').spoiler_text).to eq '' + expect(service.call(status, nil, 'es').spoiler_text).to eq '' end end @@ -66,7 +66,7 @@ RSpec.describe TranslateStatusService do let(:spoiler_text) { 'Hello & Hello!' } it 'translates the spoiler text' do - expect(service.call(status, 'es').spoiler_text).to eq 'Hola & Hola!' + expect(service.call(status, nil, 'es').spoiler_text).to eq 'Hola & Hola!' end end @@ -74,7 +74,7 @@ RSpec.describe TranslateStatusService do let(:spoiler_text) { 'Hello :highfive:' } it 'does not translate shortcode' do - expect(service.call(status, 'es').spoiler_text).to eq 'Hola :highfive:' + expect(service.call(status, nil, 'es').spoiler_text).to eq 'Hola :highfive:' end end @@ -82,7 +82,7 @@ RSpec.describe TranslateStatusService do let(:spoiler_text) { 'Hello :Hello:' } it 'translates the invalid shortcode' do - expect(service.call(status, 'es').spoiler_text).to eq 'Hola :Hola:' + expect(service.call(status, nil, 'es').spoiler_text).to eq 'Hola :Hola:' end end @@ -90,7 +90,7 @@ RSpec.describe TranslateStatusService do let(:poll) { Fabricate(:poll, options: ['Hello 1', 'Hello 2']) } it 'translates the poll option title' do - status_translation = service.call(status, 'es') + status_translation = service.call(status, nil, 'es') expect(status_translation.poll_options.size).to eq 2 expect(status_translation.poll_options.first.title).to eq 'Hola 1' end @@ -100,7 +100,7 @@ RSpec.describe TranslateStatusService do let(:media_attachments) { [Fabricate(:media_attachment, description: 'Hello & :highfive:')] } it 'translates the media attachment description' do - status_translation = service.call(status, 'es') + status_translation = service.call(status, nil, 'es') media_attachment = status_translation.media_attachments.first expect(media_attachment.id).to eq media_attachments.first.id