Skip to content

Commit

Permalink
Move api/v1/statuses/* to request spec (#28954)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed Jan 26, 2024
1 parent 44f6d28 commit ff8937a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

require 'rails_helper'

describe Api::V1::Statuses::HistoriesController do
render_views

describe 'API V1 Statuses Histories' do
let(:user) { Fabricate(:user) }
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses', application: app) }
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 oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { token }
end

describe 'GET #show' do
describe 'GET /api/v1/statuses/:status_id/history' do
let(:status) { Fabricate(:status, account: user.account) }

before do
get :show, params: { status_id: status.id }
get "/api/v1/statuses/#{status.id}/history", headers: headers
end

it 'returns http success' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

require 'rails_helper'

describe Api::V1::Statuses::MutesController do
render_views

describe 'API V1 Statuses Mutes' do
let(:user) { Fabricate(:user) }
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:mutes', application: app) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'write:mutes' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }

context 'with an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { token }
end

describe 'POST #create' do
describe 'POST /api/v1/statuses/:status_id/mute' do
let(:status) { Fabricate(:status, account: user.account) }

before do
post :create, params: { status_id: status.id }
post "/api/v1/statuses/#{status.id}/mute", headers: headers
end

it 'creates a conversation mute', :aggregate_failures do
Expand All @@ -27,12 +22,12 @@
end
end

describe 'POST #destroy' do
describe 'POST /api/v1/statuses/:status_id/unmute' do
let(:status) { Fabricate(:status, account: user.account) }

before do
user.account.mute_conversation!(status.conversation)
post :destroy, params: { status_id: status.id }
post "/api/v1/statuses/#{status.id}/unmute", headers: headers
end

it 'destroys the conversation mute', :aggregate_failures do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

require 'rails_helper'

describe Api::V1::Statuses::ReblogsController do
render_views

describe 'API V1 Statuses Reblogs' do
let(:user) { Fabricate(:user) }
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses', application: app) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'write:statuses' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }

context 'with an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { token }
end

describe 'POST #create' do
describe 'POST /api/v1/statuses/:status_id/reblog' do
let(:status) { Fabricate(:status, account: user.account) }

before do
post :create, params: { status_id: status.id }
post "/api/v1/statuses/#{status.id}/reblog", headers: headers
end

context 'with public status' do
Expand Down Expand Up @@ -46,13 +41,13 @@
end
end

describe 'POST #destroy', :sidekiq_inline do
describe 'POST /api/v1/statuses/:status_id/unreblog', :sidekiq_inline do
context 'with public status' do
let(:status) { Fabricate(:status, account: user.account) }

before do
ReblogService.new.call(user.account, status)
post :destroy, params: { status_id: status.id }
post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
end

it 'destroys the reblog', :aggregate_failures do
Expand All @@ -76,7 +71,7 @@
before do
ReblogService.new.call(user.account, status)
status.account.block!(user.account)
post :destroy, params: { status_id: status.id }
post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
end

it 'destroys the reblog', :aggregate_failures do
Expand All @@ -98,7 +93,7 @@
let(:status) { Fabricate(:status, visibility: :private) }

before do
post :destroy, params: { status_id: status.id }
post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
end

it 'returns http not found' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@

require 'rails_helper'

describe Api::V1::Statuses::TranslationsController do
render_views

describe 'API V1 Statuses Translations' do
let(:user) { Fabricate(:user) }
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses', application: app) }
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 oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { token }
end

describe 'POST #create' do
describe 'POST /api/v1/statuses/:status_id/translate' do
let(:status) { Fabricate(:status, account: user.account, text: 'Hola', language: 'es') }

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'] })
post :create, params: { status_id: status.id }
post "/api/v1/statuses/#{status.id}/translate", headers: headers
end

it 'returns http success' do
Expand Down

0 comments on commit ff8937a

Please sign in to comment.