bookmarks_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Bookmarks' do
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:scopes) { 'read:bookmarks' }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. describe 'GET /api/v1/bookmarks' do
  9. subject do
  10. get '/api/v1/bookmarks', headers: headers, params: params
  11. end
  12. let(:params) { {} }
  13. let!(:bookmarks) { Fabricate.times(2, :bookmark, account: user.account) }
  14. let(:expected_response) do
  15. bookmarks.map do |bookmark|
  16. a_hash_including(id: bookmark.status.id.to_s, account: a_hash_including(id: bookmark.status.account.id.to_s))
  17. end
  18. end
  19. it_behaves_like 'forbidden for wrong scope', 'write'
  20. it 'returns http success' do
  21. subject
  22. expect(response).to have_http_status(200)
  23. end
  24. it 'returns the bookmarked statuses' do
  25. subject
  26. expect(body_as_json).to match_array(expected_response)
  27. end
  28. context 'with limit param' do
  29. let(:params) { { limit: 1 } }
  30. it 'paginates correctly', :aggregate_failures do
  31. subject
  32. expect(body_as_json.size)
  33. .to eq(params[:limit])
  34. expect(response)
  35. .to include_pagination_headers(
  36. prev: api_v1_bookmarks_url(limit: params[:limit], min_id: bookmarks.last.id),
  37. next: api_v1_bookmarks_url(limit: params[:limit], max_id: bookmarks.second.id)
  38. )
  39. end
  40. end
  41. context 'without the authorization header' do
  42. let(:headers) { {} }
  43. it 'returns http unauthorized' do
  44. subject
  45. expect(response).to have_http_status(401)
  46. end
  47. end
  48. end
  49. end