You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::BlocksController, type: :controller do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
  6. before { allow(controller).to receive(:doorkeeper_token) { token } }
  7. describe 'GET #index' do
  8. it 'limits according to limit parameter' do
  9. 2.times.map { Fabricate(:block, account: user.account) }
  10. get :index, params: { limit: 1 }
  11. expect(body_as_json.size).to eq 1
  12. end
  13. it 'queries blocks in range according to max_id' do
  14. blocks = 2.times.map { Fabricate(:block, account: user.account) }
  15. get :index, params: { max_id: blocks[1] }
  16. expect(body_as_json.size).to eq 1
  17. expect(body_as_json[0][:id]).to eq blocks[0].target_account_id.to_s
  18. end
  19. it 'queries blocks in range according to since_id' do
  20. blocks = 2.times.map { Fabricate(:block, account: user.account) }
  21. get :index, params: { since_id: blocks[0] }
  22. expect(body_as_json.size).to eq 1
  23. expect(body_as_json[0][:id]).to eq blocks[1].target_account_id.to_s
  24. end
  25. it 'sets pagination header for next path' do
  26. blocks = 2.times.map { Fabricate(:block, account: user.account) }
  27. get :index, params: { limit: 1, since_id: blocks[0] }
  28. expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
  29. end
  30. it 'sets pagination header for previous path' do
  31. block = Fabricate(:block, account: user.account)
  32. get :index
  33. expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_blocks_url(since_id: block)
  34. end
  35. it 'returns http success' do
  36. get :index
  37. expect(response).to have_http_status(:success)
  38. end
  39. end
  40. end