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.

118 lines
3.3 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 outsome of `silence`' do
  55. it 'silences the reported account' do
  56. report = Fabricate(:report)
  57. put :update, params: { id: report, outcome: 'silence' }
  58. expect(response).to redirect_to(admin_reports_path)
  59. report.reload
  60. expect(report.action_taken_by_account).to eq user.account
  61. expect(report.action_taken).to eq true
  62. expect(report.target_account).to be_silenced
  63. end
  64. end
  65. describe 'with an outsome of `reopen`' do
  66. it 'reopens the report' do
  67. report = Fabricate(:report)
  68. put :update, params: { id: report, outcome: 'reopen' }
  69. expect(response).to redirect_to(admin_report_path(report))
  70. report.reload
  71. expect(report.action_taken_by_account).to eq nil
  72. expect(report.action_taken).to eq false
  73. end
  74. end
  75. describe 'with an outsome of `assign_to_self`' do
  76. it 'reopens the report' do
  77. report = Fabricate(:report)
  78. put :update, params: { id: report, outcome: 'assign_to_self' }
  79. expect(response).to redirect_to(admin_report_path(report))
  80. report.reload
  81. expect(report.assigned_account).to eq user.account
  82. end
  83. end
  84. describe 'with an outsome of `unassign`' do
  85. it 'reopens the report' do
  86. report = Fabricate(:report)
  87. put :update, params: { id: report, outcome: 'unassign' }
  88. expect(response).to redirect_to(admin_report_path(report))
  89. report.reload
  90. expect(report.assigned_account).to eq nil
  91. end
  92. end
  93. end
  94. end