about summary refs log tree commit diff
path: root/spec/controllers/api/v1/instances/translation_languages_controller_spec.rb
blob: 5b7e4abb6fbdc3edd7955d714673592a26412c05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

require 'rails_helper'

describe Api::V1::Instances::TranslationLanguagesController do
  describe 'GET #show' do
    context 'when no translation service is configured' do
      it 'returns empty language matrix' do
        get :show

        expect(response).to have_http_status(200)
        expect(body_as_json).to eq({})
      end
    end

    context 'when a translation service is configured' do
      before do
        service = instance_double(TranslationService::DeepL, languages: { nil => %w(en de), 'en' => ['de'] })
        allow(TranslationService).to receive(:configured?).and_return(true)
        allow(TranslationService).to receive(:configured).and_return(service)
      end

      it 'returns language matrix' do
        get :show

        expect(response).to have_http_status(200)
        expect(body_as_json).to eq({ und: %w(en de), en: ['de'] })
      end
    end
  end
end