Misc spec coverage for `Admin::` area controllers (#25282)

pull/62/head
Matt Jankowski 2023-06-06 07:57:00 -04:00 committed by GitHub
parent eb6f8181e1
commit 1e243e2df7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 277 additions and 0 deletions

View File

@ -20,4 +20,16 @@ describe Admin::AccountActionsController do
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
end end
describe 'POST #create' do
let(:account) { Fabricate(:account) }
it 'records the account action' do
expect do
post :create, params: { account_id: account.id, admin_account_action: { type: 'silence' } }
end.to change { account.strikes.count }.by(1)
expect(response).to redirect_to(admin_account_path(account.id))
end
end
end end

View File

@ -309,4 +309,128 @@ RSpec.describe Admin::AccountsController do
end end
end end
end end
describe 'POST #unsensitive' do
subject { post :unsensitive, params: { id: account.id } }
let(:current_user) { Fabricate(:user, role: role) }
let(:account) { Fabricate(:account, sensitized_at: 1.year.ago) }
context 'when user is admin' do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'marks accounts not sensitized' do
subject
expect(account.reload).to_not be_sensitized
expect(response).to redirect_to admin_account_path(account.id)
end
end
context 'when user is not admin' do
let(:role) { UserRole.everyone }
it 'fails to change account' do
subject
expect(response).to have_http_status 403
end
end
end
describe 'POST #unsilence' do
subject { post :unsilence, params: { id: account.id } }
let(:current_user) { Fabricate(:user, role: role) }
let(:account) { Fabricate(:account, silenced_at: 1.year.ago) }
context 'when user is admin' do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'marks accounts not silenced' do
subject
expect(account.reload).to_not be_silenced
expect(response).to redirect_to admin_account_path(account.id)
end
end
context 'when user is not admin' do
let(:role) { UserRole.everyone }
it 'fails to change account' do
subject
expect(response).to have_http_status 403
end
end
end
describe 'POST #unsuspend' do
subject { post :unsuspend, params: { id: account.id } }
let(:current_user) { Fabricate(:user, role: role) }
let(:account) { Fabricate(:account) }
before do
account.suspend!
end
context 'when user is admin' do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'marks accounts not suspended' do
subject
expect(account.reload).to_not be_suspended
expect(response).to redirect_to admin_account_path(account.id)
end
end
context 'when user is not admin' do
let(:role) { UserRole.everyone }
it 'fails to change account' do
subject
expect(response).to have_http_status 403
end
end
end
describe 'POST #destroy' do
subject { post :destroy, params: { id: account.id } }
let(:current_user) { Fabricate(:user, role: role) }
let(:account) { Fabricate(:account) }
before do
account.suspend!
end
context 'when user is admin' do
let(:role) { UserRole.find_by(name: 'Admin') }
before do
allow(Admin::AccountDeletionWorker).to receive(:perform_async).with(account.id)
end
it 'destroys the account' do
subject
expect(Admin::AccountDeletionWorker).to have_received(:perform_async).with(account.id)
expect(response).to redirect_to admin_account_path(account.id)
end
end
context 'when user is not admin' do
let(:role) { UserRole.everyone }
it 'fails to change account' do
subject
expect(response).to have_http_status 403
end
end
end
end end

View File

@ -73,4 +73,30 @@ describe Admin::AnnouncementsController do
expect(flash.notice).to match(I18n.t('admin.announcements.destroyed_msg')) expect(flash.notice).to match(I18n.t('admin.announcements.destroyed_msg'))
end end
end end
describe 'POST #publish' do
subject { post :publish, params: { id: announcement.id } }
let(:announcement) { Fabricate(:announcement, published_at: nil) }
it 'marks announcement published' do
subject
expect(announcement.reload).to be_published
expect(response).to redirect_to admin_announcements_path
end
end
describe 'POST #unpublish' do
subject { post :unpublish, params: { id: announcement.id } }
let(:announcement) { Fabricate(:announcement, published_at: 4.days.ago) }
it 'marks announcement as not published' do
subject
expect(announcement.reload).to_not be_published
expect(response).to redirect_to admin_announcements_path
end
end
end end

View File

@ -56,4 +56,45 @@ describe Admin::RelaysController do
end end
end end
end end
describe 'DELETE #destroy' do
let(:relay) { Fabricate(:relay) }
it 'deletes an existing relay' do
delete :destroy, params: { id: relay.id }
expect { relay.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(response).to redirect_to(admin_relays_path)
end
end
describe 'POST #enable' do
let(:relay) { Fabricate(:relay, state: :idle) }
before do
stub_request(:post, /example.com/).to_return(status: 200)
end
it 'updates a relay from idle to pending' do
post :enable, params: { id: relay.id }
expect(relay.reload).to be_pending
expect(response).to redirect_to(admin_relays_path)
end
end
describe 'POST #disable' do
let(:relay) { Fabricate(:relay, state: :pending) }
before do
stub_request(:post, /example.com/).to_return(status: 200)
end
it 'updates a relay from pending to idle' do
post :disable, params: { id: relay.id }
expect(relay.reload).to be_idle
expect(response).to redirect_to(admin_relays_path)
end
end
end end

View File

@ -41,6 +41,16 @@ describe Admin::StatusesController do
end end
end end
describe 'GET #show' do
before do
get :show, params: { account_id: account.id, id: status.id }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
describe 'POST #batch' do describe 'POST #batch' do
before do before do
post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } } post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } }

View File

@ -18,4 +18,68 @@ describe Admin::WarningPresetsController do
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
end end
describe 'GET #edit' do
let(:account_warning_preset) { Fabricate(:account_warning_preset) }
it 'returns http success and renders edit' do
get :edit, params: { id: account_warning_preset.id }
expect(response).to have_http_status(:success)
expect(response).to render_template(:edit)
end
end
describe 'POST #create' do
context 'with valid data' do
it 'creates a new account_warning_preset and redirects' do
expect do
post :create, params: { account_warning_preset: { text: 'The account_warning_preset text.' } }
end.to change(AccountWarningPreset, :count).by(1)
expect(response).to redirect_to(admin_warning_presets_path)
end
end
context 'with invalid data' do
it 'does creates a new account_warning_preset and renders index' do
expect do
post :create, params: { account_warning_preset: { text: '' } }
end.to_not change(AccountWarningPreset, :count)
expect(response).to render_template(:index)
end
end
end
describe 'PUT #update' do
let(:account_warning_preset) { Fabricate(:account_warning_preset, text: 'Original text') }
context 'with valid data' do
it 'updates the account_warning_preset and redirects' do
put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: 'Updated text.' } }
expect(response).to redirect_to(admin_warning_presets_path)
end
end
context 'with invalid data' do
it 'does not update the account_warning_preset and renders index' do
put :update, params: { id: account_warning_preset.id, account_warning_preset: { text: '' } }
expect(response).to render_template(:edit)
end
end
end
describe 'DELETE #destroy' do
let!(:account_warning_preset) { Fabricate(:account_warning_preset) }
it 'destroys the account_warning_preset and redirects' do
delete :destroy, params: { id: account_warning_preset.id }
expect { account_warning_preset.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(response).to redirect_to(admin_warning_presets_path)
end
end
end end