mirror of
https://github.com/mastodon/mastodon.git
synced 2025-12-07 14:53:38 +00:00
Some checks are pending
Check i18n / check-i18n (push) Waiting to run
Chromatic / Run Chromatic (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Historical data migration test / test (16-alpine) (push) Waiting to run
Historical data migration test / test (17-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / test (3.3) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.2) (push) Blocked by required conditions
Ruby Testing / ImageMagick tests (3.3) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.3) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
70 lines
2.3 KiB
Ruby
70 lines
2.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe 'API V1 Statuses Translations' do
|
|
let(:user) { Fabricate(:user) }
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
let(:scopes) { 'read:statuses' }
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
|
|
|
context 'with an application token' do
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: nil, scopes: scopes) }
|
|
|
|
describe 'POST /api/v1/statuses/:status_id/translate' do
|
|
let(:status) { Fabricate(:status, account: user.account, text: 'Hola', language: 'es') }
|
|
|
|
before do
|
|
post "/api/v1/statuses/#{status.id}/translate", headers: headers
|
|
end
|
|
|
|
it 'returns http unprocessable entity' do
|
|
expect(response).to have_http_status(422)
|
|
expect(response.content_type)
|
|
.to start_with('application/json')
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'with an oauth token' do
|
|
describe 'POST /api/v1/statuses/:status_id/translate' do
|
|
subject { post "/api/v1/statuses/#{status.id}/translate", headers: headers }
|
|
|
|
before 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'] })
|
|
end
|
|
|
|
context 'with a public status' do
|
|
let(:status) { Fabricate(:status, account: user.account, text: 'Hola', language: 'es') }
|
|
|
|
it 'returns http success' do
|
|
subject
|
|
|
|
expect(response)
|
|
.to have_http_status(200)
|
|
expect(response.media_type)
|
|
.to eq('application/json')
|
|
end
|
|
end
|
|
|
|
context 'with a private status' do
|
|
let(:status) { Fabricate(:status, visibility: :private, account: user.account, text: 'Hola', language: 'es') }
|
|
|
|
it 'returns http forbidden' do
|
|
subject
|
|
|
|
expect(response)
|
|
.to have_http_status(403)
|
|
expect(response.media_type)
|
|
.to eq('application/json')
|
|
expect(response.parsed_body)
|
|
.to include(error: /not allowed/)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|