~cytrogen/masto-fe

ref: 685270f3f7ea6d4a8a48ec641e8fdfd9fc2e2d7f masto-fe/spec/requests/api/v1/bookmarks_spec.rb -rw-r--r-- 1.7 KiB
685270f3 — Claire [Glitch] Fix clicking “Explore” or “Live feeds” column headers to scroll in advanced mode 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Bookmarks' do
  let(:user)    { Fabricate(:user) }
  let(:token)   { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  let(:scopes)  { 'read:bookmarks' }
  let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }

  describe 'GET /api/v1/bookmarks' do
    subject do
      get '/api/v1/bookmarks', headers: headers, params: params
    end

    let(:params)     { {} }
    let!(:bookmarks) { Fabricate.times(3, :bookmark, account: user.account) }

    let(:expected_response) do
      bookmarks.map do |bookmark|
        a_hash_including(id: bookmark.status.id.to_s, account: a_hash_including(id: bookmark.status.account.id.to_s))
      end
    end

    it_behaves_like 'forbidden for wrong scope', 'write'

    it 'returns http success' do
      subject

      expect(response).to have_http_status(200)
    end

    it 'returns the bookmarked statuses' do
      subject

      expect(body_as_json).to match_array(expected_response)
    end

    context 'with limit param' do
      let(:params) { { limit: 2 } }

      it 'paginates correctly', :aggregate_failures do
        subject

        expect(body_as_json.size).to eq(params[:limit])
        expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq(api_v1_bookmarks_url(limit: params[:limit], min_id: bookmarks.last.id))
        expect(response.headers['Link'].find_link(%w(rel next)).href).to eq(api_v1_bookmarks_url(limit: params[:limit], max_id: bookmarks[1].id))
      end
    end

    context 'without the authorization header' do
      let(:headers) { {} }

      it 'returns http unauthorized' do
        subject

        expect(response).to have_http_status(401)
      end
    end
  end
end