2023-02-21 19:55:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-29 14:12:32 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-03 23:49:53 -04:00
|
|
|
RSpec.describe Api::V1::BlocksController do
|
2016-12-29 14:12:32 -05:00
|
|
|
render_views
|
|
|
|
|
2022-01-27 18:46:42 -05:00
|
|
|
let(:user) { Fabricate(:user) }
|
2018-07-05 12:31:35 -04:00
|
|
|
let(:scopes) { 'read:blocks' }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
2016-12-29 14:12:32 -05:00
|
|
|
|
2017-10-09 11:30:31 -04:00
|
|
|
before { allow(controller).to receive(:doorkeeper_token) { token } }
|
2016-12-29 14:12:32 -05:00
|
|
|
|
|
|
|
describe 'GET #index' do
|
2023-10-13 08:42:09 -04:00
|
|
|
it 'limits according to limit parameter', :aggregate_failures do
|
2023-05-02 12:07:16 -04:00
|
|
|
Array.new(2) { Fabricate(:block, account: user.account) }
|
2017-05-31 14:34:51 -04:00
|
|
|
get :index, params: { limit: 1 }
|
2023-10-13 08:42:09 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2017-10-09 11:30:31 -04:00
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
end
|
|
|
|
|
2023-10-13 08:42:09 -04:00
|
|
|
it 'queries blocks in range according to max_id', :aggregate_failures do
|
2023-05-02 12:07:16 -04:00
|
|
|
blocks = Array.new(2) { Fabricate(:block, account: user.account) }
|
2017-10-09 11:30:31 -04:00
|
|
|
|
|
|
|
get :index, params: { max_id: blocks[1] }
|
|
|
|
|
2023-10-13 08:42:09 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2017-10-09 11:30:31 -04:00
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
expect(body_as_json[0][:id]).to eq blocks[0].target_account_id.to_s
|
|
|
|
end
|
|
|
|
|
2023-10-13 08:42:09 -04:00
|
|
|
it 'queries blocks in range according to since_id', :aggregate_failures do
|
2023-05-02 12:07:16 -04:00
|
|
|
blocks = Array.new(2) { Fabricate(:block, account: user.account) }
|
2017-05-31 14:34:51 -04:00
|
|
|
|
2017-10-09 11:30:31 -04:00
|
|
|
get :index, params: { since_id: blocks[0] }
|
|
|
|
|
2023-10-13 08:42:09 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2017-10-09 11:30:31 -04:00
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
expect(body_as_json[0][:id]).to eq blocks[1].target_account_id.to_s
|
|
|
|
end
|
|
|
|
|
2023-10-13 08:42:09 -04:00
|
|
|
it 'sets pagination header for next path', :aggregate_failures do
|
2023-05-02 12:07:16 -04:00
|
|
|
blocks = Array.new(2) { Fabricate(:block, account: user.account) }
|
2017-10-09 11:30:31 -04:00
|
|
|
get :index, params: { limit: 1, since_id: blocks[0] }
|
2023-10-13 08:42:09 -04:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2023-02-20 00:14:10 -05:00
|
|
|
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
|
2017-10-09 11:30:31 -04:00
|
|
|
end
|
|
|
|
|
2023-10-13 08:42:09 -04:00
|
|
|
it 'sets pagination header for previous path', :aggregate_failures do
|
2017-10-09 11:30:31 -04:00
|
|
|
block = Fabricate(:block, account: user.account)
|
|
|
|
get :index
|
|
|
|
|
2018-04-21 15:35:07 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2023-10-13 08:42:09 -04:00
|
|
|
expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq api_v1_blocks_url(since_id: block)
|
2016-12-29 14:12:32 -05:00
|
|
|
end
|
2018-07-05 12:31:35 -04:00
|
|
|
|
|
|
|
context 'with wrong scopes' do
|
|
|
|
let(:scopes) { 'write:blocks' }
|
|
|
|
|
|
|
|
it 'returns http forbidden' do
|
|
|
|
get :index
|
|
|
|
expect(response).to have_http_status(403)
|
|
|
|
end
|
|
|
|
end
|
2016-12-29 14:12:32 -05:00
|
|
|
end
|
|
|
|
end
|