1
0

preferences_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Preferences' do
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  7. describe 'GET /api/v1/preferences' do
  8. context 'when not authorized' do
  9. it 'returns http unauthorized' do
  10. get api_v1_preferences_path
  11. expect(response)
  12. .to have_http_status(401)
  13. expect(response.content_type)
  14. .to start_with('application/json')
  15. end
  16. end
  17. context 'with wrong scope' do
  18. before do
  19. get api_v1_preferences_path, headers: headers
  20. end
  21. it_behaves_like 'forbidden for wrong scope', 'write write:accounts'
  22. end
  23. context 'with correct scope' do
  24. let(:scopes) { 'read:accounts' }
  25. it 'returns http success' do
  26. get api_v1_preferences_path, headers: headers
  27. expect(response)
  28. .to have_http_status(200)
  29. expect(response.content_type)
  30. .to start_with('application/json')
  31. expect(response.parsed_body)
  32. .to be_present
  33. end
  34. end
  35. end
  36. end