2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-15 06:59:26 +11:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-04-14 19:10:28 +10:00
|
|
|
describe Report do
|
|
|
|
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-15 06:59:26 +11:00
|
|
|
|
2017-04-14 19:10:28 +10:00
|
|
|
expect(report.statuses).to eq [status]
|
|
|
|
end
|
|
|
|
end
|
2017-05-01 02:15:49 +10:00
|
|
|
|
2022-03-09 19:06:17 +11: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-05-01 02:15:49 +10:00
|
|
|
|
2022-03-09 19:06:17 +11:00
|
|
|
expect(report.media_attachments_count).to eq 3
|
2017-05-01 02:15:49 +10:00
|
|
|
end
|
|
|
|
end
|
2017-09-07 17:55:42 +10:00
|
|
|
|
2018-05-03 18:42:36 +10: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 15:00:48 +11:00
|
|
|
expect(subject).to eq current_account.id
|
2018-05-03 18:42:36 +10: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 15:00:48 +11:00
|
|
|
expect(subject).to be_nil
|
2018-05-03 18:42:36 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'resolve!' do
|
2022-01-17 19:41:33 +11:00
|
|
|
subject(:report) { Fabricate(:report, action_taken_at: nil, action_taken_by_account_id: nil) }
|
2018-05-03 18:42:36 +10:00
|
|
|
|
|
|
|
let(:acting_account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
report.resolve!(acting_account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'records action taken' do
|
2022-01-17 19:41:33 +11:00
|
|
|
expect(report.action_taken?).to be true
|
|
|
|
expect(report.action_taken_by_account_id).to eq acting_account.id
|
2018-05-03 18:42:36 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unresolve!' do
|
2022-01-17 19:41:33 +11:00
|
|
|
subject(:report) { Fabricate(:report, action_taken_at: Time.now.utc, action_taken_by_account_id: acting_account.id) }
|
2018-05-03 18:42:36 +10:00
|
|
|
|
|
|
|
let(:acting_account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
report.unresolve!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'unresolves' do
|
2022-01-17 19:41:33 +11:00
|
|
|
expect(report.action_taken?).to be false
|
|
|
|
expect(report.action_taken_by_account_id).to be_nil
|
2018-05-03 18:42:36 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unresolved?' do
|
|
|
|
subject { report.unresolved? }
|
|
|
|
|
2022-01-17 19:41:33 +11:00
|
|
|
let(:report) { Fabricate(:report, action_taken_at: action_taken) }
|
2018-05-03 18:42:36 +10:00
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when action is taken' do
|
2022-01-17 19:41:33 +11:00
|
|
|
let(:action_taken) { Time.now.utc }
|
2018-05-03 18:42:36 +10:00
|
|
|
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
|
|
|
|
2023-05-04 13:49:08 +10:00
|
|
|
context 'when action not is taken' do
|
2022-01-17 19:41:33 +11:00
|
|
|
let(:action_taken) { nil }
|
2018-05-03 18:42:36 +10:00
|
|
|
|
|
|
|
it { is_expected.to be true }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'history' do
|
|
|
|
subject(:action_logs) { report.history }
|
|
|
|
|
|
|
|
let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id], created_at: 3.days.ago, updated_at: 1.day.ago) }
|
|
|
|
let(:target_account) { Fabricate(:account) }
|
|
|
|
let(:status) { Fabricate(:status) }
|
|
|
|
|
|
|
|
before do
|
2023-11-29 21:39:59 +11:00
|
|
|
Fabricate(:action_log, target_type: 'Report', account_id: target_account.id, target_id: report.id, created_at: 2.days.ago)
|
|
|
|
Fabricate(:action_log, target_type: 'Account', account_id: target_account.id, target_id: report.target_account_id, created_at: 2.days.ago)
|
|
|
|
Fabricate(:action_log, target_type: 'Status', account_id: target_account.id, target_id: status.id, created_at: 2.days.ago)
|
2018-05-03 18:42:36 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns right logs' do
|
|
|
|
expect(action_logs.count).to eq 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-07 08:51:40 +11:00
|
|
|
describe 'validations' do
|
2023-05-22 21:15:21 +10:00
|
|
|
let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
|
|
|
|
|
|
|
|
it 'is invalid if comment is longer than 1000 characters only if reporter is local' do
|
2019-08-06 23:33:03 +10:00
|
|
|
report = Fabricate.build(:report, comment: Faker::Lorem.characters(number: 1001))
|
2023-05-22 21:15:21 +10:00
|
|
|
expect(report.valid?).to be false
|
2017-09-07 17:55:42 +10:00
|
|
|
expect(report).to model_have_error_on_field(:comment)
|
|
|
|
end
|
2023-05-22 21:15:21 +10:00
|
|
|
|
|
|
|
it 'is valid if comment is longer than 1000 characters and reporter is not local' do
|
|
|
|
report = Fabricate.build(:report, account: remote_account, comment: Faker::Lorem.characters(number: 1001))
|
|
|
|
expect(report.valid?).to be true
|
|
|
|
end
|
2017-09-07 17:55:42 +10:00
|
|
|
end
|
2017-02-15 06:59:26 +11:00
|
|
|
end
|