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.

102 lines
2.7 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 '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. it 'sets trust level when the report is an antispam one' do
  46. report = Fabricate(:report, account: Account.representative)
  47. put :resolve, params: { id: report }
  48. report.reload
  49. expect(report.target_account.trust_level).to eq Account::TRUST_LEVELS[:trusted]
  50. end
  51. end
  52. describe 'POST #reopen' do
  53. it 'reopens the report' do
  54. report = Fabricate(:report)
  55. put :reopen, params: { id: report }
  56. expect(response).to redirect_to(admin_report_path(report))
  57. report.reload
  58. expect(report.action_taken_by_account).to eq nil
  59. expect(report.action_taken).to eq false
  60. end
  61. end
  62. describe 'POST #assign_to_self' do
  63. it 'reopens the report' do
  64. report = Fabricate(:report)
  65. put :assign_to_self, params: { id: report }
  66. expect(response).to redirect_to(admin_report_path(report))
  67. report.reload
  68. expect(report.assigned_account).to eq user.account
  69. end
  70. end
  71. describe 'POST #unassign' do
  72. it 'reopens the report' do
  73. report = Fabricate(:report)
  74. put :unassign, params: { id: report }
  75. expect(response).to redirect_to(admin_report_path(report))
  76. report.reload
  77. expect(report.assigned_account).to eq nil
  78. end
  79. end
  80. end