preferences_spec.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. 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. end
  14. end
  15. context 'with wrong scope' do
  16. before do
  17. get api_v1_preferences_path, headers: headers
  18. end
  19. it_behaves_like 'forbidden for wrong scope', 'write write:accounts'
  20. end
  21. context 'with correct scope' do
  22. let(:scopes) { 'read:accounts' }
  23. it 'returns http success' do
  24. get api_v1_preferences_path, headers: headers
  25. expect(response)
  26. .to have_http_status(200)
  27. expect(body_as_json)
  28. .to be_present
  29. end
  30. end
  31. end
  32. end