endorsements_spec.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Endorsements' 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/endorsements' do
  8. context 'when not authorized' do
  9. it 'returns http unauthorized' do
  10. get api_v1_endorsements_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_endorsements_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. context 'with endorsed accounts' do
  26. let!(:account_pin) { Fabricate(:account_pin, account: user.account) }
  27. it 'returns http success and accounts json' do
  28. get api_v1_endorsements_path, headers: headers
  29. expect(response)
  30. .to have_http_status(200)
  31. expect(response.content_type)
  32. .to start_with('application/json')
  33. expect(response.parsed_body)
  34. .to be_present
  35. .and have_attributes(
  36. first: include(acct: account_pin.target_account.acct)
  37. )
  38. end
  39. end
  40. context 'without endorsed accounts without json' do
  41. it 'returns http success' do
  42. get api_v1_endorsements_path, headers: headers
  43. expect(response)
  44. .to have_http_status(200)
  45. expect(response.content_type)
  46. .to start_with('application/json')
  47. expect(response.parsed_body)
  48. .to_not be_present
  49. end
  50. end
  51. end
  52. end
  53. end