2023-02-22 09:55:31 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-01-13 18:46:52 +09:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 14:12:25 +09:00
|
|
|
RSpec.describe Admin::Reports::ActionsController do
|
2023-01-13 18:46:52 +09:00
|
|
|
render_views
|
|
|
|
|
|
|
|
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user, scope: :user
|
|
|
|
end
|
|
|
|
|
2023-01-19 00:40:09 +09:00
|
|
|
describe 'POST #preview' do
|
|
|
|
let(:report) { Fabricate(:report) }
|
2023-01-13 18:46:52 +09:00
|
|
|
|
|
|
|
before do
|
2023-05-04 12:54:26 +09:00
|
|
|
post :preview, params: { :report_id => report.id, action => '' }
|
2023-01-19 00:40:09 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the action is "suspend"' do
|
|
|
|
let(:action) { 'suspend' }
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2023-01-13 18:46:52 +09:00
|
|
|
end
|
|
|
|
|
2023-01-19 00:40:09 +09:00
|
|
|
context 'when the action is "silence"' do
|
|
|
|
let(:action) { 'silence' }
|
2023-01-13 18:46:52 +09:00
|
|
|
|
2023-01-19 00:40:09 +09:00
|
|
|
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
|
2023-01-13 18:46:52 +09:00
|
|
|
let(:action) { 'mark_as_sensitive' }
|
|
|
|
|
2023-01-19 00:40:09 +09:00
|
|
|
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' }
|
2023-03-04 04:50:46 +09:00
|
|
|
let(:common_params) do
|
|
|
|
{ report_id: report.id, text: text }
|
|
|
|
end
|
2023-01-19 00:40:09 +09:00
|
|
|
|
2023-10-31 17:22:19 +09:00
|
|
|
before do
|
|
|
|
_media = Fabricate(:media_attachment, account: target_account, status: statuses[0])
|
|
|
|
end
|
|
|
|
|
2023-01-19 00:40:09 +09:00
|
|
|
shared_examples 'common behavior' do
|
2023-06-22 21:53:13 +09:00
|
|
|
it 'closes the report and redirects' do
|
|
|
|
expect { subject }.to mark_report_action_taken.and create_target_account_strike
|
2023-01-13 18:46:52 +09:00
|
|
|
|
2023-01-19 00:40:09 +09:00
|
|
|
expect(report.target_account.strikes.last.text).to eq text
|
|
|
|
expect(response).to redirect_to(admin_reports_path)
|
|
|
|
end
|
2023-03-04 04:50:46 +09:00
|
|
|
|
|
|
|
context 'when text is unset' do
|
|
|
|
let(:common_params) do
|
|
|
|
{ report_id: report.id }
|
|
|
|
end
|
|
|
|
|
2023-06-22 21:53:13 +09:00
|
|
|
it 'closes the report and redirects' do
|
|
|
|
expect { subject }.to mark_report_action_taken.and create_target_account_strike
|
2023-03-04 04:50:46 +09:00
|
|
|
|
|
|
|
expect(report.target_account.strikes.last.text).to eq ''
|
|
|
|
expect(response).to redirect_to(admin_reports_path)
|
|
|
|
end
|
|
|
|
end
|
2023-06-22 21:53:13 +09:00
|
|
|
|
|
|
|
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
|
2023-01-19 00:40:09 +09:00
|
|
|
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) }
|
2023-10-31 17:22:19 +09:00
|
|
|
|
|
|
|
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
|
2023-01-19 00:40:09 +09:00
|
|
|
|
|
|
|
it_behaves_like 'common behavior'
|
|
|
|
|
|
|
|
it 'marks the non-deleted as sensitive' do
|
|
|
|
subject
|
2023-02-20 14:14:50 +09:00
|
|
|
expect(media_attached_status.reload.sensitive).to be true
|
2023-01-19 00:40:09 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-12 19:25:32 +09:00
|
|
|
context 'with action as submit button' do
|
2023-03-04 04:50:46 +09:00
|
|
|
subject { post :create, params: common_params.merge({ action => '' }) }
|
2023-02-20 10:46:00 +09:00
|
|
|
|
2023-01-19 00:40:09 +09:00
|
|
|
it_behaves_like 'all action types'
|
|
|
|
end
|
|
|
|
|
2023-05-12 19:25:32 +09:00
|
|
|
context 'with moderation action as an extra field' do
|
2023-03-04 04:50:46 +09:00
|
|
|
subject { post :create, params: common_params.merge({ moderation_action: action }) }
|
2023-02-20 10:46:00 +09:00
|
|
|
|
2023-01-19 00:40:09 +09:00
|
|
|
it_behaves_like 'all action types'
|
2023-01-13 18:46:52 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|