about summary refs log tree commit diff
path: root/spec/controllers/api/v1
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-03-16 23:12:59 +0100
committerClaire <claire.github-309c@sitedethib.com>2023-03-16 23:12:59 +0100
commit193250556cb4e6b1b3e2f9bd1ac023b290176fd4 (patch)
tree3bd6148ff028b8fe089cae9d805a7e587eaeec11 /spec/controllers/api/v1
parentf5daa20f2a90098c9d689c5ec9d95ce9887b3a33 (diff)
parent681dcd3fa35e886a21853ca829ff1be7f220e83a (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `README.md`:
  Upstream changed their README, we have our own.
  Kept ours.
- `app/helpers/application_helper.rb`:
  Minor code style fix upstream, on a line that is different in glitch-soc
  due to the different theming system.
  Applied the code style fix to our own code.
- `app/views/settings/preferences/appearance/show.html.haml`:
  Code style fix on a line next to lines exclusive to glitch-soc.
  Applied upstream changes.
- `yarn.lock`:
  Upstream updated a dependency textually close to a glitch-soc-only
  dependency.
  Updated the dependency like upstream did.
Diffstat (limited to 'spec/controllers/api/v1')
-rw-r--r--spec/controllers/api/v1/instances/translation_languages_controller_spec.rb31
-rw-r--r--spec/controllers/api/v1/statuses/translations_controller_spec.rb3
2 files changed, 33 insertions, 1 deletions
diff --git a/spec/controllers/api/v1/instances/translation_languages_controller_spec.rb b/spec/controllers/api/v1/instances/translation_languages_controller_spec.rb
new file mode 100644
index 000000000..5b7e4abb6
--- /dev/null
+++ b/spec/controllers/api/v1/instances/translation_languages_controller_spec.rb
@@ -0,0 +1,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
diff --git a/spec/controllers/api/v1/statuses/translations_controller_spec.rb b/spec/controllers/api/v1/statuses/translations_controller_spec.rb
index 2deea9fc0..8495779bf 100644
--- a/spec/controllers/api/v1/statuses/translations_controller_spec.rb
+++ b/spec/controllers/api/v1/statuses/translations_controller_spec.rb
@@ -19,9 +19,10 @@ describe Api::V1::Statuses::TranslationsController do
 
       before do
         translation = TranslationService::Translation.new(text: 'Hello')
-        service = instance_double(TranslationService::DeepL, translate: translation, supported?: true)
+        service = instance_double(TranslationService::DeepL, translate: translation)
         allow(TranslationService).to receive(:configured?).and_return(true)
         allow(TranslationService).to receive(:configured).and_return(service)
+        Rails.cache.write('translation_service/languages', { 'es' => ['en'] })
         post :create, params: { status_id: status.id }
       end