retention_spec.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. 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. end
  15. end
  16. context 'with correct scope' do
  17. let(:scopes) { 'admin:read' }
  18. it 'returns http success and status json' do
  19. post '/api/v1/admin/retention', params: { account_id: account.id, limit: 2 }, headers: headers
  20. expect(response)
  21. .to have_http_status(200)
  22. expect(body_as_json)
  23. .to be_an(Array)
  24. end
  25. end
  26. end
  27. end