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.

94 lines
2.4 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_at: nil)
  11. Fabricate(:report, action_taken_at: Time.now.utc)
  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_at: Time.now.utc)
  20. Fabricate(:report, action_taken_at: nil)
  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 'POST #resolve' do
  37. it 'resolves the report' do
  38. report = Fabricate(:report)
  39. put :resolve, params: { id: report }
  40. expect(response).to redirect_to(admin_reports_path)
  41. report.reload
  42. expect(report.action_taken_by_account).to eq user.account
  43. expect(report.action_taken?).to eq true
  44. end
  45. end
  46. describe 'POST #reopen' do
  47. it 'reopens the report' do
  48. report = Fabricate(:report)
  49. put :reopen, params: { id: report }
  50. expect(response).to redirect_to(admin_report_path(report))
  51. report.reload
  52. expect(report.action_taken_by_account).to eq nil
  53. expect(report.action_taken?).to eq false
  54. end
  55. end
  56. describe 'POST #assign_to_self' do
  57. it 'reopens the report' do
  58. report = Fabricate(:report)
  59. put :assign_to_self, params: { id: report }
  60. expect(response).to redirect_to(admin_report_path(report))
  61. report.reload
  62. expect(report.assigned_account).to eq user.account
  63. end
  64. end
  65. describe 'POST #unassign' do
  66. it 'reopens the report' do
  67. report = Fabricate(:report)
  68. put :unassign, params: { id: report }
  69. expect(response).to redirect_to(admin_report_path(report))
  70. report.reload
  71. expect(report.assigned_account).to eq nil
  72. end
  73. end
  74. end