2023-11-20 22:05:28 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 15:12:25 +10:00
|
|
|
RSpec.describe 'Translation Languages' do
|
2023-11-20 22:05:28 +11:00
|
|
|
describe 'GET /api/v1/instances/translation_languages' do
|
|
|
|
context 'when no translation service is configured' do
|
|
|
|
it 'returns empty language matrix', :aggregate_failures do
|
|
|
|
get api_v1_instance_translation_languages_path
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
|
2024-09-06 19:58:46 +10:00
|
|
|
expect(response.parsed_body)
|
2023-11-20 22:05:28 +11:00
|
|
|
.to eq({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a translation service is configured' do
|
|
|
|
before { configure_translation_service }
|
|
|
|
|
|
|
|
it 'returns language matrix', :aggregate_failures do
|
|
|
|
get api_v1_instance_translation_languages_path
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
|
2024-09-06 19:58:46 +10:00
|
|
|
expect(response.parsed_body)
|
2024-09-03 00:25:21 +10:00
|
|
|
.to match({ und: %w(en de), en: ['de'] })
|
2023-11-20 22:05:28 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def configure_translation_service
|
|
|
|
allow(TranslationService).to receive_messages(configured?: true, configured: service_double)
|
|
|
|
end
|
|
|
|
|
|
|
|
def service_double
|
|
|
|
instance_double(TranslationService::DeepL, languages: { nil => %w(en de), 'en' => ['de'] })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|