Move controller->request specs for api/v1/statuses/* (#28818)

This commit is contained in:
Matt Jankowski 2024-01-22 06:58:54 -05:00 committed by GitHub
parent 5efb00ddb8
commit 7ecf7f5403
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 69 additions and 48 deletions

View file

@ -14,7 +14,7 @@ class Api::V1::Statuses::FavouritedByAccountsController < Api::V1::Statuses::Bas
def load_accounts def load_accounts
scope = default_accounts scope = default_accounts
scope = scope.where.not(id: current_account.excluded_from_timeline_account_ids) unless current_account.nil? scope = scope.not_excluded_by_account(current_account) unless current_account.nil?
scope.merge(paginated_favourites).to_a scope.merge(paginated_favourites).to_a
end end

View file

@ -14,7 +14,7 @@ class Api::V1::Statuses::RebloggedByAccountsController < Api::V1::Statuses::Base
def load_accounts def load_accounts
scope = default_accounts scope = default_accounts
scope = scope.where.not(id: current_account.excluded_from_timeline_account_ids) unless current_account.nil? scope = scope.not_excluded_by_account(current_account) unless current_account.nil?
scope.merge(paginated_statuses).to_a scope.merge(paginated_statuses).to_a
end end

View file

@ -2,21 +2,21 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Api::V1::Statuses::FavouritedByAccountsController do RSpec.describe 'API V1 Statuses Favourited by Accounts' do
render_views let(:user) { Fabricate(:user) }
let(:scopes) { 'read:accounts' }
let(:user) { Fabricate(:user) } # let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
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, application: app, scopes: 'read:accounts') } let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:alice) { Fabricate(:account) } let(:alice) { Fabricate(:account) }
let(:bob) { Fabricate(:account) } let(:bob) { Fabricate(:account) }
context 'with an oauth token' do context 'with an oauth token' do
before do subject do
allow(controller).to receive(:doorkeeper_token) { token } get "/api/v1/statuses/#{status.id}/favourited_by", headers: headers, params: { limit: 2 }
end end
describe 'GET #index' do describe 'GET /api/v1/statuses/:status_id/favourited_by' do
let(:status) { Fabricate(:status, account: user.account) } let(:status) { Fabricate(:status, account: user.account) }
before do before do
@ -24,30 +24,38 @@ RSpec.describe Api::V1::Statuses::FavouritedByAccountsController do
Favourite.create!(account: bob, status: status) Favourite.create!(account: bob, status: status)
end end
it 'returns http success' do it 'returns http success and accounts who favourited the status' do
get :index, params: { status_id: status.id, limit: 2 } subject
expect(response).to have_http_status(200)
expect(response.headers['Link'].links.size).to eq(2)
end
it 'returns accounts who favorited the status' do expect(response)
get :index, params: { status_id: status.id, limit: 2 } .to have_http_status(200)
expect(body_as_json.size).to eq 2 expect(response.headers['Link'].links.size)
expect([body_as_json[0][:id], body_as_json[1][:id]]).to contain_exactly(alice.id.to_s, bob.id.to_s) .to eq(2)
expect(body_as_json.size)
.to eq(2)
expect(body_as_json)
.to contain_exactly(
include(id: alice.id.to_s),
include(id: bob.id.to_s)
)
end end
it 'does not return blocked users' do it 'does not return blocked users' do
user.account.block!(bob) user.account.block!(bob)
get :index, params: { status_id: status.id, limit: 2 }
expect(body_as_json.size).to eq 1 subject
expect(body_as_json[0][:id]).to eq alice.id.to_s
expect(body_as_json.size)
.to eq 1
expect(body_as_json.first[:id]).to eq(alice.id.to_s)
end end
end end
end end
context 'without an oauth token' do context 'without an oauth token' do
before do subject do
allow(controller).to receive(:doorkeeper_token).and_return(nil) get "/api/v1/statuses/#{status.id}/favourited_by", params: { limit: 2 }
end end
context 'with a private status' do context 'with a private status' do
@ -59,7 +67,8 @@ RSpec.describe Api::V1::Statuses::FavouritedByAccountsController do
end end
it 'returns http unauthorized' do it 'returns http unauthorized' do
get :index, params: { status_id: status.id } subject
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
@ -74,7 +83,8 @@ RSpec.describe Api::V1::Statuses::FavouritedByAccountsController do
end end
it 'returns http success' do it 'returns http success' do
get :index, params: { status_id: status.id } subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
end end

View file

@ -2,21 +2,20 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe Api::V1::Statuses::RebloggedByAccountsController do RSpec.describe 'API V1 Statuses Reblogged by Accounts' do
render_views let(:user) { Fabricate(:user) }
let(:scopes) { 'read:accounts' }
let(:user) { Fabricate(:user) } let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') } let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app, scopes: 'read:accounts') }
let(:alice) { Fabricate(:account) } let(:alice) { Fabricate(:account) }
let(:bob) { Fabricate(:account) } let(:bob) { Fabricate(:account) }
context 'with an oauth token' do context 'with an oauth token' do
before do subject do
allow(controller).to receive(:doorkeeper_token) { token } get "/api/v1/statuses/#{status.id}/reblogged_by", headers: headers, params: { limit: 2 }
end end
describe 'GET #index' do describe 'GET /api/v1/statuses/:status_id/reblogged_by' do
let(:status) { Fabricate(:status, account: user.account) } let(:status) { Fabricate(:status, account: user.account) }
before do before do
@ -25,27 +24,37 @@ RSpec.describe Api::V1::Statuses::RebloggedByAccountsController do
end end
it 'returns accounts who reblogged the status', :aggregate_failures do it 'returns accounts who reblogged the status', :aggregate_failures do
get :index, params: { status_id: status.id, limit: 2 } subject
expect(response).to have_http_status(200) expect(response)
expect(response.headers['Link'].links.size).to eq(2) .to have_http_status(200)
expect(response.headers['Link'].links.size)
.to eq(2)
expect(body_as_json.size).to eq 2 expect(body_as_json.size)
expect([body_as_json[0][:id], body_as_json[1][:id]]).to contain_exactly(alice.id.to_s, bob.id.to_s) .to eq(2)
expect(body_as_json)
.to contain_exactly(
include(id: alice.id.to_s),
include(id: bob.id.to_s)
)
end end
it 'does not return blocked users' do it 'does not return blocked users' do
user.account.block!(bob) user.account.block!(bob)
get :index, params: { status_id: status.id, limit: 2 }
expect(body_as_json.size).to eq 1 subject
expect(body_as_json[0][:id]).to eq alice.id.to_s
expect(body_as_json.size)
.to eq 1
expect(body_as_json.first[:id]).to eq(alice.id.to_s)
end end
end end
end end
context 'without an oauth token' do context 'without an oauth token' do
before do subject do
allow(controller).to receive(:doorkeeper_token).and_return(nil) get "/api/v1/statuses/#{status.id}/reblogged_by", params: { limit: 2 }
end end
context 'with a private status' do context 'with a private status' do
@ -57,7 +66,8 @@ RSpec.describe Api::V1::Statuses::RebloggedByAccountsController do
end end
it 'returns http unauthorized' do it 'returns http unauthorized' do
get :index, params: { status_id: status.id } subject
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
end end
end end
@ -72,7 +82,8 @@ RSpec.describe Api::V1::Statuses::RebloggedByAccountsController do
end end
it 'returns http success' do it 'returns http success' do
get :index, params: { status_id: status.id } subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
end end