retention_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Admin Retention' do
  4. let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  7. let(:account) { Fabricate(:account) }
  8. describe 'GET /api/v1/admin/retention' do
  9. context 'when not authorized' do
  10. it 'returns http forbidden' do
  11. post '/api/v1/admin/retention', params: { account_id: account.id, limit: 2 }
  12. expect(response)
  13. .to have_http_status(403)
  14. expect(response.content_type)
  15. .to start_with('application/json')
  16. end
  17. end
  18. context 'with correct scope' do
  19. let(:scopes) { 'admin:read' }
  20. it 'returns http success and status json' do
  21. post '/api/v1/admin/retention', params: { account_id: account.id, limit: 2 }, headers: headers
  22. expect(response)
  23. .to have_http_status(200)
  24. expect(response.content_type)
  25. .to start_with('application/json')
  26. expect(response.parsed_body)
  27. .to be_an(Array)
  28. end
  29. end
  30. end
  31. end