2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-14 19:59:26 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 05:12:25 +00:00
|
|
|
RSpec.describe Report do
|
2017-04-14 09:10:28 +00:00
|
|
|
describe 'statuses' do
|
|
|
|
it 'returns the statuses for the report' do
|
|
|
|
status = Fabricate(:status)
|
|
|
|
_other = Fabricate(:status)
|
|
|
|
report = Fabricate(:report, status_ids: [status.id])
|
2017-02-14 19:59:26 +00:00
|
|
|
|
2017-04-14 09:10:28 +00:00
|
|
|
expect(report.statuses).to eq [status]
|
|
|
|
end
|
|
|
|
end
|
2017-04-30 16:15:49 +00:00
|
|
|
|
2022-03-09 08:06:17 +00:00
|
|
|
describe 'media_attachments_count' do
|
|
|
|
it 'returns count of media attachments in statuses' do
|
|
|
|
status1 = Fabricate(:status, ordered_media_attachment_ids: [1, 2])
|
|
|
|
status2 = Fabricate(:status, ordered_media_attachment_ids: [5])
|
|
|
|
report = Fabricate(:report, status_ids: [status1.id, status2.id])
|
2017-04-30 16:15:49 +00:00
|
|
|
|
2022-03-09 08:06:17 +00:00
|
|
|
expect(report.media_attachments_count).to eq 3
|
2017-04-30 16:15:49 +00:00
|
|
|
end
|
|
|
|
end
|
2017-09-07 07:55:42 +00:00
|
|
|
|
2018-05-03 08:42:36 +00:00
|
|
|
describe 'assign_to_self!' do
|
|
|
|
subject { report.assigned_account_id }
|
|
|
|
|
|
|
|
let(:report) { Fabricate(:report, assigned_account_id: original_account) }
|
|
|
|
let(:original_account) { Fabricate(:account) }
|
|
|
|
let(:current_account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
report.assign_to_self!(current_account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns to a given account' do
|
2023-02-20 04:00:48 +00:00
|
|
|
expect(subject).to eq current_account.id
|
2018-05-03 08:42:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unassign!' do
|
|
|
|
subject { report.assigned_account_id }
|
|
|
|
|
|
|
|
let(:report) { Fabricate(:report, assigned_account_id: account.id) }
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
report.unassign!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'unassigns' do
|
2023-02-20 04:00:48 +00:00
|
|
|
expect(subject).to be_nil
|
2018-05-03 08:42:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'resolve!' do
|
2022-01-17 08:41:33 +00:00
|
|
|
subject(:report) { Fabricate(:report, action_taken_at: nil, action_taken_by_account_id: nil) }
|
2018-05-03 08:42:36 +00:00
|
|
|
|
|
|
|
let(:acting_account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
report.resolve!(acting_account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'records action taken' do
|
2022-01-17 08:41:33 +00:00
|
|
|
expect(report.action_taken?).to be true
|
|
|
|
expect(report.action_taken_by_account_id).to eq acting_account.id
|
2018-05-03 08:42:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unresolve!' do
|
2022-01-17 08:41:33 +00:00
|
|
|
subject(:report) { Fabricate(:report, action_taken_at: Time.now.utc, action_taken_by_account_id: acting_account.id) }
|
2018-05-03 08:42:36 +00:00
|
|
|
|
|
|
|
let(:acting_account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
report.unresolve!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'unresolves' do
|
2022-01-17 08:41:33 +00:00
|
|
|
expect(report.action_taken?).to be false
|
|
|
|
expect(report.action_taken_by_account_id).to be_nil
|
2018-05-03 08:42:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unresolved?' do
|
|
|
|
subject { report.unresolved? }
|
|
|
|
|
2022-01-17 08:41:33 +00:00
|
|
|
let(:report) { Fabricate(:report, action_taken_at: action_taken) }
|
2018-05-03 08:42:36 +00:00
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'when action is taken' do
|
2022-01-17 08:41:33 +00:00
|
|
|
let(:action_taken) { Time.now.utc }
|
2018-05-03 08:42:36 +00:00
|
|
|
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
|
|
|
|
2023-05-04 03:49:08 +00:00
|
|
|
context 'when action not is taken' do
|
2022-01-17 08:41:33 +00:00
|
|
|
let(:action_taken) { nil }
|
2018-05-03 08:42:36 +00:00
|
|
|
|
|
|
|
it { is_expected.to be true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'history' do
|
|
|
|
subject(:action_logs) { report.history }
|
|
|
|
|
2024-12-11 08:24:50 +00:00
|
|
|
let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id]) }
|
2018-05-03 08:42:36 +00:00
|
|
|
let(:target_account) { Fabricate(:account) }
|
|
|
|
let(:status) { Fabricate(:status) }
|
2024-11-20 07:52:00 +00:00
|
|
|
let(:account_warning) { Fabricate(:account_warning, report_id: report.id) }
|
2018-05-03 08:42:36 +00:00
|
|
|
|
2024-12-11 08:24:50 +00:00
|
|
|
let!(:matched_type_account_warning) { Fabricate(:action_log, target_type: 'AccountWarning', target_id: account_warning.id) }
|
|
|
|
let!(:matched_type_account) { Fabricate(:action_log, target_type: 'Account', target_id: report.target_account_id) }
|
|
|
|
let!(:matched_type_report) { Fabricate(:action_log, target_type: 'Report', target_id: report.id) }
|
|
|
|
let!(:matched_type_status) { Fabricate(:action_log, target_type: 'Status', target_id: status.id) }
|
|
|
|
|
|
|
|
let!(:unmatched_type_account_warning) { Fabricate(:action_log, target_type: 'AccountWarning') }
|
|
|
|
let!(:unmatched_type_account) { Fabricate(:action_log, target_type: 'Account') }
|
|
|
|
let!(:unmatched_type_report) { Fabricate(:action_log, target_type: 'Report') }
|
|
|
|
let!(:unmatched_type_status) { Fabricate(:action_log, target_type: 'Status') }
|
2018-05-03 08:42:36 +00:00
|
|
|
|
2024-11-20 07:52:00 +00:00
|
|
|
it 'returns expected logs' do
|
|
|
|
expect(action_logs)
|
|
|
|
.to have_attributes(count: 4)
|
2024-12-11 08:24:50 +00:00
|
|
|
.and include(matched_type_account_warning)
|
|
|
|
.and include(matched_type_account)
|
|
|
|
.and include(matched_type_report)
|
|
|
|
.and include(matched_type_status)
|
|
|
|
.and not_include(unmatched_type_account_warning)
|
|
|
|
.and not_include(unmatched_type_account)
|
|
|
|
.and not_include(unmatched_type_report)
|
|
|
|
.and not_include(unmatched_type_status)
|
2018-05-03 08:42:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-12-02 21:52:12 +00:00
|
|
|
describe '#unresolved_siblings?' do
|
|
|
|
subject { Fabricate :report }
|
|
|
|
|
|
|
|
context 'when the target account has other unresolved reports' do
|
|
|
|
before { Fabricate :report, action_taken_at: nil, target_account: subject.target_account }
|
|
|
|
|
|
|
|
it { is_expected.to be_unresolved_siblings }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the target account has a resolved report' do
|
|
|
|
before { Fabricate :report, action_taken_at: 3.days.ago, target_account: subject.target_account }
|
|
|
|
|
|
|
|
it { is_expected.to_not be_unresolved_siblings }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the target account has no other reports' do
|
|
|
|
before { described_class.where(target_account: subject.target_account).destroy_all }
|
|
|
|
|
|
|
|
it { is_expected.to_not be_unresolved_siblings }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-12-12 09:09:35 +00:00
|
|
|
describe 'Validations' do
|
2023-05-22 11:15:21 +00:00
|
|
|
let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
|
|
|
|
|
2024-06-10 15:04:01 +00:00
|
|
|
it 'is invalid if comment is longer than character limit and reporter is local' do
|
2024-12-12 09:09:35 +00:00
|
|
|
report = Fabricate.build(:report)
|
|
|
|
|
|
|
|
expect(report).to_not allow_value(comment_over_limit).for(:comment)
|
2017-09-07 07:55:42 +00:00
|
|
|
end
|
2023-05-22 11:15:21 +00:00
|
|
|
|
2024-06-10 15:04:01 +00:00
|
|
|
it 'is valid if comment is longer than character limit and reporter is not local' do
|
|
|
|
report = Fabricate.build(:report, account: remote_account, comment: comment_over_limit)
|
2023-05-22 11:15:21 +00:00
|
|
|
expect(report.valid?).to be true
|
|
|
|
end
|
2024-02-06 09:35:27 +00:00
|
|
|
|
|
|
|
it 'is invalid if it references invalid rules' do
|
2024-12-12 09:09:35 +00:00
|
|
|
report = Fabricate.build(:report, category: :violation)
|
|
|
|
|
|
|
|
expect(report).to_not allow_value([-1]).for(:rule_ids)
|
2024-02-06 09:35:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is invalid if it references rules but category is not "violation"' do
|
|
|
|
rule = Fabricate(:rule)
|
2024-12-12 09:09:35 +00:00
|
|
|
report = Fabricate.build(:report, category: :spam)
|
|
|
|
|
|
|
|
expect(report).to_not allow_value(rule.id).for(:rule_ids)
|
2024-02-06 09:35:27 +00:00
|
|
|
end
|
2024-06-10 15:04:01 +00:00
|
|
|
|
|
|
|
def comment_over_limit
|
|
|
|
'a' * described_class::COMMENT_SIZE_LIMIT * 2
|
|
|
|
end
|
2017-09-07 07:55:42 +00:00
|
|
|
end
|
2017-02-14 19:59:26 +00:00
|
|
|
end
|