Merge remote-tracking branch 'parent/main' into upstream-20240201
This commit is contained in:
commit
92ef42d697
179 changed files with 1218 additions and 2902 deletions
|
@ -153,13 +153,9 @@ RSpec.describe Admin::AccountsController do
|
|||
context 'when user is admin' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
|
||||
it 'succeeds in approving account' do
|
||||
it 'succeeds in approving account and logs action' do
|
||||
expect(subject).to redirect_to admin_accounts_path(status: 'pending')
|
||||
expect(user.reload).to be_approved
|
||||
end
|
||||
|
||||
it 'logs action' do
|
||||
expect(subject).to have_http_status 302
|
||||
|
||||
expect(latest_admin_action_log)
|
||||
.to be_present
|
||||
|
@ -195,12 +191,8 @@ RSpec.describe Admin::AccountsController do
|
|||
context 'when user is admin' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
|
||||
it 'succeeds in rejecting account' do
|
||||
it 'succeeds in rejecting account and logs action' do
|
||||
expect(subject).to redirect_to admin_accounts_path(status: 'pending')
|
||||
end
|
||||
|
||||
it 'logs action' do
|
||||
expect(subject).to have_http_status 302
|
||||
|
||||
expect(latest_admin_action_log)
|
||||
.to be_present
|
||||
|
@ -286,12 +278,9 @@ RSpec.describe Admin::AccountsController do
|
|||
context 'when user is admin' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
|
||||
it 'succeeds in removing email blocks' do
|
||||
it 'succeeds in removing email blocks and redirects to admin account path' do
|
||||
expect { subject }.to change { CanonicalEmailBlock.where(reference_account: account).count }.from(1).to(0)
|
||||
end
|
||||
|
||||
it 'redirects to admin account path' do
|
||||
subject
|
||||
expect(response).to redirect_to admin_account_path(account.id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -60,16 +60,14 @@ describe Admin::StatusesController do
|
|||
shared_examples 'when action is report' do
|
||||
let(:action) { 'report' }
|
||||
|
||||
it 'creates a report' do
|
||||
it 'creates a report and redirects to report page' do
|
||||
subject
|
||||
|
||||
report = Report.last
|
||||
expect(report.target_account_id).to eq account.id
|
||||
expect(report.status_ids).to eq status_ids
|
||||
end
|
||||
|
||||
it 'redirects to report page' do
|
||||
subject
|
||||
expect(Report.last)
|
||||
.to have_attributes(
|
||||
target_account_id: eq(account.id),
|
||||
status_ids: eq(status_ids)
|
||||
)
|
||||
|
||||
expect(response).to redirect_to(admin_report_path(Report.last.id))
|
||||
end
|
||||
|
|
|
@ -39,11 +39,14 @@ describe Api::V1::Accounts::StatusesController do
|
|||
end
|
||||
|
||||
it 'returns posts along with self replies', :aggregate_failures do
|
||||
json = body_as_json
|
||||
post_ids = json.map { |item| item[:id].to_i }.sort
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(post_ids).to eq [status.id, status_self_reply.id]
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(body_as_json)
|
||||
.to have_attributes(size: 2)
|
||||
.and contain_exactly(
|
||||
include(id: status.id.to_s),
|
||||
include(id: status_self_reply.id.to_s)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Admin::Trends::Links::PreviewCardProvidersController do
|
||||
render_views
|
||||
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
let(:user) { Fabricate(:user, role: role) }
|
||||
let(:scopes) { 'admin:read admin:write' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:preview_card_provider) { Fabricate(:preview_card_provider) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
it 'returns http success' do
|
||||
get :index, params: { account_id: account.id, limit: 2 }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #approve' do
|
||||
before do
|
||||
post :approve, params: { id: preview_card_provider.id }
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
it_behaves_like 'forbidden for wrong role', ''
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #reject' do
|
||||
before do
|
||||
post :reject, params: { id: preview_card_provider.id }
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
it_behaves_like 'forbidden for wrong role', ''
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Statuses::HistoriesController do
|
||||
render_views
|
||||
|
||||
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) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
get :show, params: { status_id: status.id }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to_not be 0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,78 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::Statuses::MentionedAccountsController do
|
||||
render_views
|
||||
|
||||
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, application: app, scopes: 'read:accounts') }
|
||||
let(:alice) { Fabricate(:account) }
|
||||
let(:bob) { Fabricate(:account) }
|
||||
let(:ohagi) { Fabricate(:account) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
Mention.create!(account: bob, status: status)
|
||||
Mention.create!(account: ohagi, status: status)
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :index, params: { status_id: status.id, limit: 2 }
|
||||
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
|
||||
get :index, params: { status_id: status.id, limit: 2 }
|
||||
expect(body_as_json.size).to eq 2
|
||||
expect([body_as_json[0][:id], body_as_json[1][:id]]).to contain_exactly(bob.id.to_s, ohagi.id.to_s)
|
||||
end
|
||||
|
||||
it 'does not return blocked users' do
|
||||
user.account.block!(ohagi)
|
||||
get :index, params: { status_id: status.id, limit: 2 }
|
||||
expect(body_as_json.size).to eq 1
|
||||
expect(body_as_json[0][:id]).to eq bob.id.to_s
|
||||
end
|
||||
|
||||
context 'when other accounts status' do
|
||||
let(:status) { Fabricate(:status, account: alice) }
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
get :index, params: { status_id: status.id }
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token).and_return(nil)
|
||||
end
|
||||
|
||||
context 'with a public status' do
|
||||
let(:status) { Fabricate(:status, account: user.account, visibility: :public) }
|
||||
|
||||
describe 'GET #index' do
|
||||
before do
|
||||
Mention.create!(account: bob, status: status)
|
||||
end
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
get :index, params: { status_id: status.id }
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Statuses::MutesController do
|
||||
render_views
|
||||
|
||||
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) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
post :create, params: { status_id: status.id }
|
||||
end
|
||||
|
||||
it 'creates a conversation mute', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(ConversationMute.find_by(account: user.account, conversation_id: status.conversation_id)).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #destroy' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
user.account.mute_conversation!(status.conversation)
|
||||
post :destroy, params: { status_id: status.id }
|
||||
end
|
||||
|
||||
it 'destroys the conversation mute', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(ConversationMute.find_by(account: user.account, conversation_id: status.conversation_id)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,110 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Statuses::ReblogsController do
|
||||
render_views
|
||||
|
||||
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) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
post :create, params: { status_id: status.id }
|
||||
end
|
||||
|
||||
context 'with public status' do
|
||||
it 'reblogs the status', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
expect(status.reblogs.count).to eq 1
|
||||
|
||||
expect(user.account.reblogged?(status)).to be true
|
||||
|
||||
hash_body = body_as_json
|
||||
|
||||
expect(hash_body[:reblog][:id]).to eq status.id.to_s
|
||||
expect(hash_body[:reblog][:reblogs_count]).to eq 1
|
||||
expect(hash_body[:reblog][:reblogged]).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'with private status of not-followed account' do
|
||||
let(:status) { Fabricate(:status, visibility: :private) }
|
||||
|
||||
it 'returns http not found' do
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #destroy', :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 }
|
||||
end
|
||||
|
||||
it 'destroys the reblog', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
expect(status.reblogs.count).to eq 0
|
||||
|
||||
expect(user.account.reblogged?(status)).to be false
|
||||
|
||||
hash_body = body_as_json
|
||||
|
||||
expect(hash_body[:id]).to eq status.id.to_s
|
||||
expect(hash_body[:reblogs_count]).to eq 0
|
||||
expect(hash_body[:reblogged]).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'with public status when blocked by its author' do
|
||||
let(:status) { Fabricate(:status, account: user.account) }
|
||||
|
||||
before do
|
||||
ReblogService.new.call(user.account, status)
|
||||
status.account.block!(user.account)
|
||||
post :destroy, params: { status_id: status.id }
|
||||
end
|
||||
|
||||
it 'destroys the reblog', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
expect(status.reblogs.count).to eq 0
|
||||
|
||||
expect(user.account.reblogged?(status)).to be false
|
||||
|
||||
hash_body = body_as_json
|
||||
|
||||
expect(hash_body[:id]).to eq status.id.to_s
|
||||
expect(hash_body[:reblogs_count]).to eq 0
|
||||
expect(hash_body[:reblogged]).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'with private status that was not reblogged' do
|
||||
let(:status) { Fabricate(:status, visibility: :private) }
|
||||
|
||||
before do
|
||||
post :destroy, params: { status_id: status.id }
|
||||
end
|
||||
|
||||
it 'returns http not found' do
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,33 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Statuses::TranslationsController do
|
||||
render_views
|
||||
|
||||
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) }
|
||||
|
||||
context 'with an oauth token' do
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'POST #create' 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 }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,56 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Timelines::AntennaController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:antenna) { Fabricate(:antenna, account: user.account) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
context 'with a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:lists') }
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
account = Fabricate(:account)
|
||||
antenna.antenna_accounts.create!(account: account)
|
||||
PostStatusService.new.call(account, text: 'New status for user home timeline.')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: antenna.id }
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the wrong user context' do
|
||||
let(:other_user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: other_user.id, scopes: 'read') }
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http not found' do
|
||||
get :show, params: { id: antenna.id }
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: nil, scopes: 'read') }
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http unprocessable entity' do
|
||||
get :show, params: { id: antenna.id }
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.headers['Link']).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,56 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Timelines::ListController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:list) { Fabricate(:list, account: user.account) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
context 'with a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:lists') }
|
||||
|
||||
describe 'GET #show' do
|
||||
before do
|
||||
follow = Fabricate(:follow, account: user.account)
|
||||
list.accounts << follow.target_account
|
||||
PostStatusService.new.call(follow.target_account, text: 'New status for user home timeline.')
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
get :show, params: { id: list.id }
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the wrong user context' do
|
||||
let(:other_user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: other_user.id, scopes: 'read') }
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http not found' do
|
||||
get :show, params: { id: list.id }
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without a user context' do
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: nil, scopes: 'read') }
|
||||
|
||||
describe 'GET #show' do
|
||||
it 'returns http unprocessable entity' do
|
||||
get :show, params: { id: list.id }
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.headers['Link']).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,78 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Api::V1::Timelines::PublicController do
|
||||
render_views
|
||||
|
||||
let!(:account) { Fabricate(:account) }
|
||||
let!(:user) { Fabricate(:user, account: account) }
|
||||
let!(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read') }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
subject do
|
||||
get :show
|
||||
body_as_json
|
||||
end
|
||||
|
||||
let!(:local_account) { Fabricate(:account, domain: nil) }
|
||||
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
|
||||
let!(:local_status) { Fabricate(:status, account: local_account, text: 'ohagi is good') }
|
||||
let!(:remote_status) { Fabricate(:status, account: remote_account, text: 'ohagi is ohagi') }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
json = subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(json).to be_an Array
|
||||
expect(json.any? { |status| status[:id] == local_status.id.to_s }).to be true
|
||||
expect(json.any? { |status| status[:id] == remote_status.id.to_s }).to be true
|
||||
end
|
||||
|
||||
context 'with filter' do
|
||||
subject do
|
||||
get :show
|
||||
body_as_json.filter { |status| status[:filtered].empty? || status[:filtered][0][:filter][:id] != filter.id.to_s }.map { |status| status[:id].to_i }
|
||||
end
|
||||
|
||||
before do
|
||||
Fabricate(:custom_filter_keyword, custom_filter: filter, keyword: 'ohagi')
|
||||
Fabricate(:follow, account: account, target_account: remote_account)
|
||||
end
|
||||
|
||||
let(:exclude_follows) { false }
|
||||
let(:exclude_localusers) { false }
|
||||
let!(:filter) { Fabricate(:custom_filter, account: account, exclude_follows: exclude_follows, exclude_localusers: exclude_localusers) }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to_not include(local_status.id)
|
||||
expect(ids).to_not include(remote_status.id)
|
||||
end
|
||||
|
||||
context 'when exclude_followers' do
|
||||
let(:exclude_follows) { true }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to_not include(local_status.id)
|
||||
expect(ids).to include(remote_status.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when exclude_localusers' do
|
||||
let(:exclude_localusers) { true }
|
||||
|
||||
it 'load statuses', :aggregate_failures do
|
||||
ids = subject
|
||||
expect(ids).to include(local_status.id)
|
||||
expect(ids).to_not include(remote_status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,39 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::Trends::LinksController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
context 'when trends are disabled' do
|
||||
before { Setting.trends = false }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when trends are enabled' do
|
||||
before { Setting.trends = true }
|
||||
|
||||
it 'returns http success' do
|
||||
prepare_trends
|
||||
stub_const('Api::V1::Trends::LinksController::DEFAULT_LINKS_LIMIT', 2)
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to include('Link')
|
||||
end
|
||||
|
||||
def prepare_trends
|
||||
Fabricate.times(3, :preview_card, trendable: true, language: 'en').each do |link|
|
||||
2.times { |i| Trends.links.add(link, i) }
|
||||
end
|
||||
Trends::Links.new(threshold: 1).refresh
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,39 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::Trends::StatusesController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
context 'when trends are disabled' do
|
||||
before { Setting.trends = false }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when trends are enabled' do
|
||||
before { Setting.trends = true }
|
||||
|
||||
it 'returns http success' do
|
||||
prepare_trends
|
||||
stub_const('Api::BaseController::DEFAULT_STATUSES_LIMIT', 2)
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to include('Link')
|
||||
end
|
||||
|
||||
def prepare_trends
|
||||
Fabricate.times(3, :status, trendable: true, language: 'en').each do |status|
|
||||
2.times { |i| Trends.statuses.add(status, i) }
|
||||
end
|
||||
Trends::Statuses.new(threshold: 1, decay_threshold: -1).refresh
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V1::Trends::TagsController do
|
||||
render_views
|
||||
|
||||
describe 'GET #index' do
|
||||
context 'when trends are disabled' do
|
||||
before { Setting.trends = false }
|
||||
|
||||
it 'returns http success' do
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to_not include('Link')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when trends are enabled' do
|
||||
before { Setting.trends = true }
|
||||
|
||||
it 'returns http success' do
|
||||
prepare_trends
|
||||
stub_const('Api::V1::Trends::TagsController::DEFAULT_TAGS_LIMIT', 2)
|
||||
get :index
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers).to include('Link')
|
||||
end
|
||||
|
||||
def prepare_trends
|
||||
Fabricate.times(3, :tag, trendable: true).each do |tag|
|
||||
2.times { |i| Trends.tags.add(tag, i) }
|
||||
end
|
||||
Trends::Tags.new(threshold: 1).refresh
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,95 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::V2::Admin::AccountsController do
|
||||
render_views
|
||||
|
||||
let(:role) { UserRole.find_by(name: 'Moderator') }
|
||||
let(:user) { Fabricate(:user, role: role) }
|
||||
let(:scopes) { 'admin:read admin:write' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:doorkeeper_token) { token }
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
let!(:remote_account) { Fabricate(:account, domain: 'example.org') }
|
||||
let!(:other_remote_account) { Fabricate(:account, domain: 'foo.bar') }
|
||||
let!(:suspended_account) { Fabricate(:account, suspended: true) }
|
||||
let!(:suspended_remote) { Fabricate(:account, domain: 'foo.bar', suspended: true) }
|
||||
let!(:disabled_account) { Fabricate(:user, disabled: true).account }
|
||||
let!(:pending_account) { Fabricate(:user, approved: false).account }
|
||||
let!(:admin_account) { user.account }
|
||||
|
||||
let(:params) { {} }
|
||||
|
||||
before do
|
||||
pending_account.user.update(approved: false)
|
||||
get :index, params: params
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
||||
it_behaves_like 'forbidden for wrong role', ''
|
||||
|
||||
context 'when called with status active and origin local and permissions staff' do
|
||||
let(:params) { { status: 'active', origin: 'local', permissions: 'staff' } }
|
||||
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to eq([admin_account.id])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when called with by_domain value and origin remote' do
|
||||
let(:params) { { by_domain: 'example.org', origin: 'remote' } }
|
||||
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to include(remote_account.id)
|
||||
expect(body_json_ids).to_not include(other_remote_account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when called with status suspended' do
|
||||
let(:params) { { status: 'suspended' } }
|
||||
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to include(suspended_remote.id, suspended_account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when called with status disabled' do
|
||||
let(:params) { { status: 'disabled' } }
|
||||
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to include(disabled_account.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when called with status pending' do
|
||||
let(:params) { { status: 'pending' } }
|
||||
|
||||
it 'returns the correct accounts' do
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_json_ids).to include(pending_account.id)
|
||||
end
|
||||
end
|
||||
|
||||
def body_json_ids
|
||||
body_as_json.map { |a| a[:id].to_i }
|
||||
end
|
||||
|
||||
context 'with limit param' do
|
||||
let(:params) { { limit: 1 } }
|
||||
|
||||
it 'sets the correct pagination headers' do
|
||||
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v2_admin_accounts_url(limit: 1, max_id: admin_account.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -22,13 +22,10 @@ describe ApplicationController do
|
|||
end
|
||||
|
||||
shared_examples 'respond_with_error' do |code|
|
||||
it "returns http #{code} for http" do
|
||||
subject
|
||||
expect(response).to have_http_status(code)
|
||||
end
|
||||
|
||||
it 'renders template for http' do
|
||||
it "returns http #{code} for http and renders template" do
|
||||
expect(subject).to render_template("errors/#{code}", layout: 'error')
|
||||
|
||||
expect(response).to have_http_status(code)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -49,22 +49,21 @@ describe AccountControllerConcern do
|
|||
end
|
||||
|
||||
context 'when account is not suspended' do
|
||||
it 'assigns @account' do
|
||||
account = Fabricate(:account)
|
||||
let(:account) { Fabricate(:account, username: 'username') }
|
||||
|
||||
it 'assigns @account, returns success, and sets link headers' do
|
||||
get 'success', params: { account_username: account.username }
|
||||
|
||||
expect(assigns(:account)).to eq account
|
||||
end
|
||||
|
||||
it 'sets link headers' do
|
||||
Fabricate(:account, username: 'username')
|
||||
get 'success', params: { account_username: 'username' }
|
||||
expect(response.headers['Link'].to_s).to eq '<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/jrd+json", <https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"'
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
account = Fabricate(:account)
|
||||
get 'success', params: { account_username: account.username }
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Link'].to_s).to eq(expected_link_headers)
|
||||
end
|
||||
|
||||
def expected_link_headers
|
||||
[
|
||||
'<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/jrd+json"',
|
||||
'<https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"',
|
||||
].join(', ')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,30 +12,20 @@ RSpec.describe InstanceActorsController do
|
|||
get :show, params: { format: format }
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
it 'returns http success with correct media type, headers, and session values' do
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns application/activity+json' do
|
||||
expect(response.media_type).to eq 'application/activity+json'
|
||||
end
|
||||
|
||||
it 'does not set cookies' do
|
||||
expect(response.cookies).to be_empty
|
||||
expect(response.headers['Set-Cookies']).to be_nil
|
||||
end
|
||||
|
||||
it 'does not set sessions' do
|
||||
expect(session).to be_empty
|
||||
end
|
||||
|
||||
it 'returns public Cache-Control header' do
|
||||
expect(response.headers['Cache-Control']).to include 'public'
|
||||
end
|
||||
|
||||
it 'renders account' do
|
||||
json = body_as_json
|
||||
expect(json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
|
||||
expect(body_as_json)
|
||||
.to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue