You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.9 KiB

  1. require 'rails_helper'
  2. describe Admin::ReportsController do
  3. render_views
  4. let(:user) { Fabricate(:user, admin: true) }
  5. before do
  6. sign_in user, scope: :user
  7. end
  8. describe 'GET #index' do
  9. it 'returns http success with no filters' do
  10. specified = Fabricate(:report, action_taken: false)
  11. Fabricate(:report, action_taken: true)
  12. get :index
  13. reports = assigns(:reports).to_a
  14. expect(reports.size).to eq 1
  15. expect(reports[0]).to eq specified
  16. expect(response).to have_http_status(:success)
  17. end
  18. it 'returns http success with resolved filter' do
  19. specified = Fabricate(:report, action_taken: true)
  20. Fabricate(:report, action_taken: false)
  21. get :index, params: { resolved: 1 }
  22. reports = assigns(:reports).to_a
  23. expect(reports.size).to eq 1
  24. expect(reports[0]).to eq specified
  25. expect(response).to have_http_status(:success)
  26. end
  27. end
  28. describe 'GET #show' do
  29. it 'renders report' do
  30. report = Fabricate(:report)
  31. get :show, params: { id: report }
  32. expect(assigns(:report)).to eq report
  33. expect(response).to have_http_status(:success)
  34. end
  35. end
  36. describe 'PUT #update' do
  37. describe 'with an unknown outcome' do
  38. it 'rejects the change' do
  39. report = Fabricate(:report)
  40. put :update, params: { id: report, outcome: 'unknown' }
  41. expect(response).to have_http_status(:missing)
  42. end
  43. end
  44. describe 'with an outcome of `resolve`' do
  45. it 'resolves the report' do
  46. report = Fabricate(:report)
  47. put :update, params: { id: report, outcome: 'resolve' }
  48. expect(response).to redirect_to(admin_report_path(report))
  49. report.reload
  50. expect(report.action_taken_by_account).to eq user.account
  51. expect(report.action_taken).to eq true
  52. end
  53. end
  54. describe 'with an outcome of `suspend`' do
  55. it 'suspends the reported account' do
  56. report = Fabricate(:report)
  57. allow(Admin::SuspensionWorker).to receive(:perform_async)
  58. put :update, params: { id: report, outcome: 'suspend' }
  59. expect(response).to redirect_to(admin_report_path(report))
  60. report.reload
  61. expect(report.action_taken_by_account).to eq user.account
  62. expect(report.action_taken).to eq true
  63. expect(Admin::SuspensionWorker).
  64. to have_received(:perform_async).with(report.target_account_id)
  65. end
  66. end
  67. describe 'with an outsome of `silence`' do
  68. it 'silences the reported account' do
  69. report = Fabricate(:report)
  70. put :update, params: { id: report, outcome: 'silence' }
  71. expect(response).to redirect_to(admin_report_path(report))
  72. report.reload
  73. expect(report.action_taken_by_account).to eq user.account
  74. expect(report.action_taken).to eq true
  75. expect(report.target_account).to be_silenced
  76. end
  77. end
  78. end
  79. end