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.

133 lines
3.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(200)
  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(200)
  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(200)
  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(404)
  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_reports_path)
  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_reports_path)
  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_reports_path)
  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. describe 'with an outsome of `reopen`' do
  79. it 'reopens the report' do
  80. report = Fabricate(:report)
  81. put :update, params: { id: report, outcome: 'reopen' }
  82. expect(response).to redirect_to(admin_report_path(report))
  83. report.reload
  84. expect(report.action_taken_by_account).to eq nil
  85. expect(report.action_taken).to eq false
  86. end
  87. end
  88. describe 'with an outsome of `assign_to_self`' do
  89. it 'reopens the report' do
  90. report = Fabricate(:report)
  91. put :update, params: { id: report, outcome: 'assign_to_self' }
  92. expect(response).to redirect_to(admin_report_path(report))
  93. report.reload
  94. expect(report.assigned_account).to eq user.account
  95. end
  96. end
  97. describe 'with an outsome of `unassign`' do
  98. it 'reopens the report' do
  99. report = Fabricate(:report)
  100. put :update, params: { id: report, outcome: 'unassign' }
  101. expect(response).to redirect_to(admin_report_path(report))
  102. report.reload
  103. expect(report.assigned_account).to eq nil
  104. end
  105. end
  106. end
  107. end