闭社主体 forked from https://github.com/tootsuite/mastodon
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.

88 lines
2.6 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. allow(Report).to receive(:unresolved).and_return(Report.all)
  11. get :index
  12. expect(response).to have_http_status(:success)
  13. expect(Report).to have_received(:unresolved)
  14. end
  15. it 'returns http success with resolved filter' do
  16. allow(Report).to receive(:resolved).and_return(Report.all)
  17. get :index, params: { resolved: 1 }
  18. expect(response).to have_http_status(:success)
  19. expect(Report).to have_received(:resolved)
  20. end
  21. end
  22. describe 'GET #show' do
  23. it 'returns http success' do
  24. report = Fabricate(:report)
  25. get :show, params: { id: report }
  26. expect(response).to have_http_status(:success)
  27. end
  28. end
  29. describe 'PUT #update' do
  30. describe 'with an unknown outcome' do
  31. it 'rejects the change' do
  32. report = Fabricate(:report)
  33. put :update, params: { id: report, outcome: 'unknown' }
  34. expect(response).to have_http_status(:missing)
  35. end
  36. end
  37. describe 'with an outcome of `resolve`' do
  38. it 'resolves the report' do
  39. report = Fabricate(:report)
  40. put :update, params: { id: report, outcome: 'resolve' }
  41. expect(response).to redirect_to(admin_report_path(report))
  42. report.reload
  43. expect(report.action_taken_by_account).to eq user.account
  44. expect(report.action_taken).to eq true
  45. end
  46. end
  47. describe 'with an outcome of `suspend`' do
  48. it 'suspends the reported account' do
  49. report = Fabricate(:report)
  50. allow(Admin::SuspensionWorker).to receive(:perform_async)
  51. put :update, params: { id: report, outcome: 'suspend' }
  52. expect(response).to redirect_to(admin_report_path(report))
  53. report.reload
  54. expect(report.action_taken_by_account).to eq user.account
  55. expect(report.action_taken).to eq true
  56. expect(Admin::SuspensionWorker).
  57. to have_received(:perform_async).with(report.target_account_id)
  58. end
  59. end
  60. describe 'with an outsome of `silence`' do
  61. it 'silences the reported account' do
  62. report = Fabricate(:report)
  63. put :update, params: { id: report, outcome: 'silence' }
  64. expect(response).to redirect_to(admin_report_path(report))
  65. report.reload
  66. expect(report.action_taken_by_account).to eq user.account
  67. expect(report.action_taken).to eq true
  68. expect(report.target_account).to be_silenced
  69. end
  70. end
  71. end
  72. end