report_spec.rb 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. require 'rails_helper'
  2. describe Report do
  3. describe 'statuses' do
  4. it 'returns the statuses for the report' do
  5. status = Fabricate(:status)
  6. _other = Fabricate(:status)
  7. report = Fabricate(:report, status_ids: [status.id])
  8. expect(report.statuses).to eq [status]
  9. end
  10. end
  11. describe 'media_attachments_count' do
  12. it 'returns count of media attachments in statuses' do
  13. status1 = Fabricate(:status, ordered_media_attachment_ids: [1, 2])
  14. status2 = Fabricate(:status, ordered_media_attachment_ids: [5])
  15. report = Fabricate(:report, status_ids: [status1.id, status2.id])
  16. expect(report.media_attachments_count).to eq 3
  17. end
  18. end
  19. describe 'assign_to_self!' do
  20. subject { report.assigned_account_id }
  21. let(:report) { Fabricate(:report, assigned_account_id: original_account) }
  22. let(:original_account) { Fabricate(:account) }
  23. let(:current_account) { Fabricate(:account) }
  24. before do
  25. report.assign_to_self!(current_account)
  26. end
  27. it 'assigns to a given account' do
  28. is_expected.to eq current_account.id
  29. end
  30. end
  31. describe 'unassign!' do
  32. subject { report.assigned_account_id }
  33. let(:report) { Fabricate(:report, assigned_account_id: account.id) }
  34. let(:account) { Fabricate(:account) }
  35. before do
  36. report.unassign!
  37. end
  38. it 'unassigns' do
  39. is_expected.to be_nil
  40. end
  41. end
  42. describe 'resolve!' do
  43. subject(:report) { Fabricate(:report, action_taken_at: nil, action_taken_by_account_id: nil) }
  44. let(:acting_account) { Fabricate(:account) }
  45. before do
  46. report.resolve!(acting_account)
  47. end
  48. it 'records action taken' do
  49. expect(report.action_taken?).to be true
  50. expect(report.action_taken_by_account_id).to eq acting_account.id
  51. end
  52. end
  53. describe 'unresolve!' do
  54. subject(:report) { Fabricate(:report, action_taken_at: Time.now.utc, action_taken_by_account_id: acting_account.id) }
  55. let(:acting_account) { Fabricate(:account) }
  56. before do
  57. report.unresolve!
  58. end
  59. it 'unresolves' do
  60. expect(report.action_taken?).to be false
  61. expect(report.action_taken_by_account_id).to be_nil
  62. end
  63. end
  64. describe 'unresolved?' do
  65. subject { report.unresolved? }
  66. let(:report) { Fabricate(:report, action_taken_at: action_taken) }
  67. context 'if action is taken' do
  68. let(:action_taken) { Time.now.utc }
  69. it { is_expected.to be false }
  70. end
  71. context 'if action not is taken' do
  72. let(:action_taken) { nil }
  73. it { is_expected.to be true }
  74. end
  75. end
  76. describe 'history' do
  77. subject(:action_logs) { report.history }
  78. let(:report) { Fabricate(:report, target_account_id: target_account.id, status_ids: [status.id], created_at: 3.days.ago, updated_at: 1.day.ago) }
  79. let(:target_account) { Fabricate(:account) }
  80. let(:status) { Fabricate(:status) }
  81. before do
  82. Fabricate('Admin::ActionLog', target_type: 'Report', account_id: target_account.id, target_id: report.id, created_at: 2.days.ago)
  83. Fabricate('Admin::ActionLog', target_type: 'Account', account_id: target_account.id, target_id: report.target_account_id, created_at: 2.days.ago)
  84. Fabricate('Admin::ActionLog', target_type: 'Status', account_id: target_account.id, target_id: status.id, created_at: 2.days.ago)
  85. end
  86. it 'returns right logs' do
  87. expect(action_logs.count).to eq 3
  88. end
  89. end
  90. describe 'validations' do
  91. it 'has a valid fabricator' do
  92. report = Fabricate(:report)
  93. report.valid?
  94. expect(report).to be_valid
  95. end
  96. let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
  97. it 'is invalid if comment is longer than 1000 characters only if reporter is local' do
  98. report = Fabricate.build(:report, comment: Faker::Lorem.characters(number: 1001))
  99. expect(report.valid?).to be false
  100. expect(report).to model_have_error_on_field(:comment)
  101. end
  102. it 'is valid if comment is longer than 1000 characters and reporter is not local' do
  103. report = Fabricate.build(:report, account: remote_account, comment: Faker::Lorem.characters(number: 1001))
  104. expect(report.valid?).to be true
  105. end
  106. end
  107. end