Fix tests

This commit is contained in:
Christian Schmidt 2024-08-27 21:50:18 +02:00
parent 5d939d70ca
commit e8bbce9043
4 changed files with 17 additions and 17 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -33,32 +33,32 @@ RSpec.describe TranslateStatusService do
end
it 'returns translated status content' do
expect(service.call(status, 'es').content).to eq '<p>Hola</p>'
expect(service.call(status, nil, 'es').content).to eq '<p>Hola</p>'
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 '<p>Hola &amp; :highfive:</p>'
expect(service.call(status, nil, 'es').content).to eq '<p>Hola &amp; :highfive:</p>'
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