123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- # frozen_string_literal: true
- require 'rails_helper'
- describe Admin::Reports::ActionsController do
- render_views
- let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
- before do
- sign_in user, scope: :user
- end
- describe 'POST #preview' do
- let(:report) { Fabricate(:report) }
- before do
- post :preview, params: { :report_id => report.id, action => '' }
- end
- context 'when the action is "suspend"' do
- let(:action) { 'suspend' }
- it 'returns http success' do
- expect(response).to have_http_status(200)
- end
- end
- context 'when the action is "silence"' do
- let(:action) { 'silence' }
- it 'returns http success' do
- expect(response).to have_http_status(200)
- end
- end
- context 'when the action is "delete"' do
- let(:action) { 'delete' }
- it 'returns http success' do
- expect(response).to have_http_status(200)
- end
- end
- context 'when the action is "mark_as_sensitive"' do
- let(:action) { 'mark_as_sensitive' }
- it 'returns http success' do
- expect(response).to have_http_status(200)
- end
- end
- end
- describe 'POST #create' do
- let(:target_account) { Fabricate(:account) }
- let(:statuses) { [Fabricate(:status, account: target_account), Fabricate(:status, account: target_account)] }
- let(:report) { Fabricate(:report, target_account: target_account, status_ids: statuses.map(&:id)) }
- let(:text) { 'hello' }
- let(:common_params) do
- { report_id: report.id, text: text }
- end
- before do
- _media = Fabricate(:media_attachment, account: target_account, status: statuses[0])
- end
- shared_examples 'common behavior' do
- it 'closes the report and redirects' do
- expect { subject }.to mark_report_action_taken.and create_target_account_strike
- expect(report.target_account.strikes.last.text).to eq text
- expect(response).to redirect_to(admin_reports_path)
- end
- context 'when text is unset' do
- let(:common_params) do
- { report_id: report.id }
- end
- it 'closes the report and redirects' do
- expect { subject }.to mark_report_action_taken.and create_target_account_strike
- expect(report.target_account.strikes.last.text).to eq ''
- expect(response).to redirect_to(admin_reports_path)
- end
- end
- def mark_report_action_taken
- change { report.reload.action_taken? }.from(false).to(true)
- end
- def create_target_account_strike
- change { report.target_account.strikes.count }.by(1)
- end
- end
- shared_examples 'all action types' do
- context 'when the action is "suspend"' do
- let(:action) { 'suspend' }
- it_behaves_like 'common behavior'
- it 'suspends the target account' do
- expect { subject }.to change { report.target_account.reload.suspended? }.from(false).to(true)
- end
- end
- context 'when the action is "silence"' do
- let(:action) { 'silence' }
- it_behaves_like 'common behavior'
- it 'suspends the target account' do
- expect { subject }.to change { report.target_account.reload.silenced? }.from(false).to(true)
- end
- end
- context 'when the action is "delete"' do
- let(:action) { 'delete' }
- it_behaves_like 'common behavior'
- end
- context 'when the action is "mark_as_sensitive"' do
- let(:action) { 'mark_as_sensitive' }
- let(:statuses) { [media_attached_status, media_attached_deleted_status] }
- let(:media_attached_status) { Fabricate(:status, account: target_account) }
- let(:media_attached_deleted_status) { Fabricate(:status, account: target_account, deleted_at: 1.day.ago) }
- let(:last_media_attached_status) { Fabricate(:status, account: target_account) }
- before do
- _last_media_attachment = Fabricate(:media_attachment, account: target_account, status: last_media_attached_status)
- _last_status = Fabricate(:status, account: target_account)
- _media_attachment = Fabricate(:media_attachment, account: target_account, status: media_attached_status)
- _media_attachment2 = Fabricate(:media_attachment, account: target_account, status: media_attached_deleted_status)
- _status = Fabricate(:status, account: target_account)
- end
- it_behaves_like 'common behavior'
- it 'marks the non-deleted as sensitive' do
- subject
- expect(media_attached_status.reload.sensitive).to be true
- end
- end
- end
- context 'with action as submit button' do
- subject { post :create, params: common_params.merge({ action => '' }) }
- it_behaves_like 'all action types'
- end
- context 'with moderation action as an extra field' do
- subject { post :create, params: common_params.merge({ moderation_action: action }) }
- it_behaves_like 'all action types'
- end
- end
- end
|