From ff8937aa2c81c616cbe3b2d7ce7d0d11850f37b8 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 26 Jan 2024 12:45:54 -0500 Subject: [PATCH] Move `api/v1/statuses/*` to request spec (#28954) --- .../api/v1/statuses/histories_spec.rb} | 17 +++++-------- .../api/v1/statuses/mutes_spec.rb} | 21 ++++++---------- .../api/v1/statuses/reblogs_spec.rb} | 25 ++++++++----------- .../api/v1/statuses/translations_spec.rb} | 17 +++++-------- 4 files changed, 30 insertions(+), 50 deletions(-) rename spec/{controllers/api/v1/statuses/histories_controller_spec.rb => requests/api/v1/statuses/histories_spec.rb} (53%) rename spec/{controllers/api/v1/statuses/mutes_controller_spec.rb => requests/api/v1/statuses/mutes_spec.rb} (66%) rename spec/{controllers/api/v1/statuses/reblogs_controller_spec.rb => requests/api/v1/statuses/reblogs_spec.rb} (81%) rename spec/{controllers/api/v1/statuses/translations_controller_spec.rb => requests/api/v1/statuses/translations_spec.rb} (65%) diff --git a/spec/controllers/api/v1/statuses/histories_controller_spec.rb b/spec/requests/api/v1/statuses/histories_spec.rb similarity index 53% rename from spec/controllers/api/v1/statuses/histories_controller_spec.rb rename to spec/requests/api/v1/statuses/histories_spec.rb index 99384c8ed5..b3761ca688 100644 --- a/spec/controllers/api/v1/statuses/histories_controller_spec.rb +++ b/spec/requests/api/v1/statuses/histories_spec.rb @@ -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 diff --git a/spec/controllers/api/v1/statuses/mutes_controller_spec.rb b/spec/requests/api/v1/statuses/mutes_spec.rb similarity index 66% rename from spec/controllers/api/v1/statuses/mutes_controller_spec.rb rename to spec/requests/api/v1/statuses/mutes_spec.rb index 03274fe1cd..72fd7d9d11 100644 --- a/spec/controllers/api/v1/statuses/mutes_controller_spec.rb +++ b/spec/requests/api/v1/statuses/mutes_spec.rb @@ -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 @@ -27,12 +22,12 @@ describe Api::V1::Statuses::MutesController do 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 diff --git a/spec/controllers/api/v1/statuses/reblogs_controller_spec.rb b/spec/requests/api/v1/statuses/reblogs_spec.rb similarity index 81% rename from spec/controllers/api/v1/statuses/reblogs_controller_spec.rb rename to spec/requests/api/v1/statuses/reblogs_spec.rb index 014a03c1a2..cf0a1f861d 100644 --- a/spec/controllers/api/v1/statuses/reblogs_controller_spec.rb +++ b/spec/requests/api/v1/statuses/reblogs_spec.rb @@ -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 @@ -46,13 +41,13 @@ describe Api::V1::Statuses::ReblogsController do 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 @@ -76,7 +71,7 @@ describe Api::V1::Statuses::ReblogsController do 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 @@ -98,7 +93,7 @@ describe Api::V1::Statuses::ReblogsController do 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 diff --git a/spec/controllers/api/v1/statuses/translations_controller_spec.rb b/spec/requests/api/v1/statuses/translations_spec.rb similarity index 65% rename from spec/controllers/api/v1/statuses/translations_controller_spec.rb rename to spec/requests/api/v1/statuses/translations_spec.rb index 6257494ae1..5b0a994561 100644 --- a/spec/controllers/api/v1/statuses/translations_controller_spec.rb +++ b/spec/requests/api/v1/statuses/translations_spec.rb @@ -2,19 +2,14 @@ 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 @@ -22,7 +17,7 @@ describe Api::V1::Statuses::TranslationsController do 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