reports_controller_spec.rb 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. require 'rails_helper'
  2. RSpec.describe Api::V1::Admin::ReportsController, type: :controller do
  3. render_views
  4. let(:role) { 'moderator' }
  5. let(:user) { Fabricate(:user, role: role, account: Fabricate(:account, username: 'alice')) }
  6. let(:scopes) { 'admin:read admin:write' }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  8. let(:report) { Fabricate(:report) }
  9. before do
  10. allow(controller).to receive(:doorkeeper_token) { token }
  11. end
  12. shared_examples 'forbidden for wrong scope' do |wrong_scope|
  13. let(:scopes) { wrong_scope }
  14. it 'returns http forbidden' do
  15. expect(response).to have_http_status(403)
  16. end
  17. end
  18. shared_examples 'forbidden for wrong role' do |wrong_role|
  19. let(:role) { wrong_role }
  20. it 'returns http forbidden' do
  21. expect(response).to have_http_status(403)
  22. end
  23. end
  24. describe 'GET #index' do
  25. before do
  26. get :index
  27. end
  28. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  29. it_behaves_like 'forbidden for wrong role', 'user'
  30. it 'returns http success' do
  31. expect(response).to have_http_status(200)
  32. end
  33. end
  34. describe 'GET #show' do
  35. before do
  36. get :show, params: { id: report.id }
  37. end
  38. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  39. it_behaves_like 'forbidden for wrong role', 'user'
  40. it 'returns http success' do
  41. expect(response).to have_http_status(200)
  42. end
  43. end
  44. describe 'POST #resolve' do
  45. before do
  46. post :resolve, params: { id: report.id }
  47. end
  48. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  49. it_behaves_like 'forbidden for wrong role', 'user'
  50. it 'returns http success' do
  51. expect(response).to have_http_status(200)
  52. end
  53. end
  54. describe 'POST #reopen' do
  55. before do
  56. post :reopen, params: { id: report.id }
  57. end
  58. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  59. it_behaves_like 'forbidden for wrong role', 'user'
  60. it 'returns http success' do
  61. expect(response).to have_http_status(200)
  62. end
  63. end
  64. describe 'POST #assign_to_self' do
  65. before do
  66. post :assign_to_self, params: { id: report.id }
  67. end
  68. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  69. it_behaves_like 'forbidden for wrong role', 'user'
  70. it 'returns http success' do
  71. expect(response).to have_http_status(200)
  72. end
  73. end
  74. describe 'POST #unassign' do
  75. before do
  76. post :unassign, params: { id: report.id }
  77. end
  78. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  79. it_behaves_like 'forbidden for wrong role', 'user'
  80. it 'returns http success' do
  81. expect(response).to have_http_status(200)
  82. end
  83. end
  84. end