approve_appeal_service_spec.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ApproveAppealService do
  4. describe '#call' do
  5. let(:appeal) { Fabricate(:appeal) }
  6. let(:account) { Fabricate(:account) }
  7. it 'processes the appeal approval' do
  8. expect { subject.call(appeal, account) }
  9. .to mark_overruled
  10. .and record_approver
  11. end
  12. context 'with an appeal about then-deleted posts marked as sensitive by moderators' do
  13. let(:target_account) { Fabricate(:account) }
  14. let(:appeal) { Fabricate(:appeal, strike: strike, account: target_account) }
  15. let(:deleted_media) { Fabricate(:media_attachment, type: :video, status: Fabricate(:status, account: target_account), account: target_account) }
  16. let(:kept_media) { Fabricate(:media_attachment, type: :video, status: Fabricate(:status, account: target_account), account: target_account) }
  17. let(:strike) { Fabricate(:account_warning, target_account: target_account, action: :mark_statuses_as_sensitive, status_ids: [deleted_media.status.id, kept_media.status.id]) }
  18. before do
  19. target_account.unsuspend!
  20. deleted_media.status.discard!
  21. end
  22. it 'approves the appeal, marks the statuses as not sensitive and notifies target account about the approval', :inline_jobs do
  23. emails = capture_emails { subject.call(appeal, account) }
  24. expect(appeal.reload).to be_approved
  25. expect(strike.reload).to be_overruled
  26. expect(kept_media.status.reload).to_not be_sensitive
  27. expect(emails.size)
  28. .to eq(1)
  29. expect(emails.first)
  30. .to have_attributes(
  31. to: contain_exactly(target_account.user.email),
  32. subject: eq(I18n.t('user_mailer.appeal_approved.subject', date: I18n.l(appeal.created_at)))
  33. )
  34. end
  35. end
  36. def mark_overruled
  37. change(appeal.strike, :overruled_at)
  38. .from(nil)
  39. .to(be > 1.minute.ago)
  40. end
  41. def record_approver
  42. change(appeal, :approved_by_account)
  43. .from(nil)
  44. .to(account)
  45. end
  46. end
  47. end