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.

109 lines
2.7 KiB

  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