appeals_controller_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::Disputes::AppealsController do
  4. render_views
  5. before do
  6. sign_in current_user, scope: :user
  7. target_account.suspend!
  8. end
  9. let(:target_account) { Fabricate(:account) }
  10. let(:strike) { Fabricate(:account_warning, target_account: target_account, action: :suspend) }
  11. let(:appeal) { Fabricate(:appeal, strike: strike, account: target_account) }
  12. describe 'POST #approve' do
  13. let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  14. before do
  15. allow(UserMailer).to receive(:appeal_approved)
  16. .and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil))
  17. post :approve, params: { id: appeal.id }
  18. end
  19. it 'unsuspends a suspended account' do
  20. expect(target_account.reload.suspended?).to be false
  21. end
  22. it 'redirects back to the strike page' do
  23. expect(response).to redirect_to(disputes_strike_path(appeal.strike))
  24. end
  25. it 'notifies target account about approved appeal' do
  26. expect(UserMailer).to have_received(:appeal_approved).with(target_account.user, appeal)
  27. end
  28. end
  29. describe 'POST #reject' do
  30. let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  31. before do
  32. allow(UserMailer).to receive(:appeal_rejected)
  33. .and_return(instance_double(ActionMailer::MessageDelivery, deliver_later: nil))
  34. post :reject, params: { id: appeal.id }
  35. end
  36. it 'redirects back to the strike page' do
  37. expect(response).to redirect_to(disputes_strike_path(appeal.strike))
  38. end
  39. it 'notifies target account about rejected appeal' do
  40. expect(UserMailer).to have_received(:appeal_rejected).with(target_account.user, appeal)
  41. end
  42. end
  43. end