Move api/v1/statuses/* to request spec (#28954)

This commit is contained in:
Matt Jankowski 2024-01-26 12:45:54 -05:00 committed by GitHub
parent 44f6d285af
commit ff8937aa2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 50 deletions

View File

@ -2,23 +2,18 @@
require 'rails_helper' require 'rails_helper'
describe Api::V1::Statuses::HistoriesController do describe 'API V1 Statuses Histories' do
render_views
let(:user) { Fabricate(:user) } 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: scopes) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses', application: app) } let(:scopes) { 'read:statuses' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
context 'with an oauth token' do context 'with an oauth token' do
before do describe 'GET /api/v1/statuses/:status_id/history' do
allow(controller).to receive(:doorkeeper_token) { token }
end
describe 'GET #show' do
let(:status) { Fabricate(:status, account: user.account) } let(:status) { Fabricate(:status, account: user.account) }
before do before do
get :show, params: { status_id: status.id } get "/api/v1/statuses/#{status.id}/history", headers: headers
end end
it 'returns http success' do it 'returns http success' do

View File

@ -2,23 +2,18 @@
require 'rails_helper' require 'rails_helper'
describe Api::V1::Statuses::MutesController do describe 'API V1 Statuses Mutes' do
render_views
let(:user) { Fabricate(:user) } 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: scopes) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:mutes', application: app) } let(:scopes) { 'write:mutes' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
context 'with an oauth token' do context 'with an oauth token' do
before do describe 'POST /api/v1/statuses/:status_id/mute' do
allow(controller).to receive(:doorkeeper_token) { token }
end
describe 'POST #create' do
let(:status) { Fabricate(:status, account: user.account) } let(:status) { Fabricate(:status, account: user.account) }
before do before do
post :create, params: { status_id: status.id } post "/api/v1/statuses/#{status.id}/mute", headers: headers
end end
it 'creates a conversation mute', :aggregate_failures do it 'creates a conversation mute', :aggregate_failures do
@ -27,12 +22,12 @@ describe Api::V1::Statuses::MutesController do
end end
end end
describe 'POST #destroy' do describe 'POST /api/v1/statuses/:status_id/unmute' do
let(:status) { Fabricate(:status, account: user.account) } let(:status) { Fabricate(:status, account: user.account) }
before do before do
user.account.mute_conversation!(status.conversation) user.account.mute_conversation!(status.conversation)
post :destroy, params: { status_id: status.id } post "/api/v1/statuses/#{status.id}/unmute", headers: headers
end end
it 'destroys the conversation mute', :aggregate_failures do it 'destroys the conversation mute', :aggregate_failures do

View File

@ -2,23 +2,18 @@
require 'rails_helper' require 'rails_helper'
describe Api::V1::Statuses::ReblogsController do describe 'API V1 Statuses Reblogs' do
render_views
let(:user) { Fabricate(:user) } 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: scopes) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'write:statuses', application: app) } let(:scopes) { 'write:statuses' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
context 'with an oauth token' do context 'with an oauth token' do
before do describe 'POST /api/v1/statuses/:status_id/reblog' do
allow(controller).to receive(:doorkeeper_token) { token }
end
describe 'POST #create' do
let(:status) { Fabricate(:status, account: user.account) } let(:status) { Fabricate(:status, account: user.account) }
before do before do
post :create, params: { status_id: status.id } post "/api/v1/statuses/#{status.id}/reblog", headers: headers
end end
context 'with public status' do context 'with public status' do
@ -46,13 +41,13 @@ describe Api::V1::Statuses::ReblogsController do
end end
end end
describe 'POST #destroy', :sidekiq_inline do describe 'POST /api/v1/statuses/:status_id/unreblog', :sidekiq_inline do
context 'with public status' do context 'with public status' do
let(:status) { Fabricate(:status, account: user.account) } let(:status) { Fabricate(:status, account: user.account) }
before do before do
ReblogService.new.call(user.account, status) ReblogService.new.call(user.account, status)
post :destroy, params: { status_id: status.id } post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
end end
it 'destroys the reblog', :aggregate_failures do it 'destroys the reblog', :aggregate_failures do
@ -76,7 +71,7 @@ describe Api::V1::Statuses::ReblogsController do
before do before do
ReblogService.new.call(user.account, status) ReblogService.new.call(user.account, status)
status.account.block!(user.account) status.account.block!(user.account)
post :destroy, params: { status_id: status.id } post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
end end
it 'destroys the reblog', :aggregate_failures do it 'destroys the reblog', :aggregate_failures do
@ -98,7 +93,7 @@ describe Api::V1::Statuses::ReblogsController do
let(:status) { Fabricate(:status, visibility: :private) } let(:status) { Fabricate(:status, visibility: :private) }
before do before do
post :destroy, params: { status_id: status.id } post "/api/v1/statuses/#{status.id}/unreblog", headers: headers
end end
it 'returns http not found' do it 'returns http not found' do

View File

@ -2,19 +2,14 @@
require 'rails_helper' require 'rails_helper'
describe Api::V1::Statuses::TranslationsController do describe 'API V1 Statuses Translations' do
render_views
let(:user) { Fabricate(:user) } 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: scopes) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses', application: app) } let(:scopes) { 'read:statuses' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
context 'with an oauth token' do context 'with an oauth token' do
before do describe 'POST /api/v1/statuses/:status_id/translate' do
allow(controller).to receive(:doorkeeper_token) { token }
end
describe 'POST #create' do
let(:status) { Fabricate(:status, account: user.account, text: 'Hola', language: 'es') } let(:status) { Fabricate(:status, account: user.account, text: 'Hola', language: 'es') }
before do before do
@ -22,7 +17,7 @@ describe Api::V1::Statuses::TranslationsController do
service = instance_double(TranslationService::DeepL, translate: [translation]) service = instance_double(TranslationService::DeepL, translate: [translation])
allow(TranslationService).to receive_messages(configured?: true, configured: service) allow(TranslationService).to receive_messages(configured?: true, configured: service)
Rails.cache.write('translation_service/languages', { 'es' => ['en'] }) 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 end
it 'returns http success' do it 'returns http success' do