闭社主体 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.

86 lines
2.6 KiB

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