2016-12-30 04:12:32 +09:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Api::V1::BlocksController, type: :controller do
|
|
|
|
render_views
|
|
|
|
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:user) { Fabricate(:user) }
|
2018-07-06 01:31:35 +09:00
|
|
|
let(:scopes) { 'read:blocks' }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
2016-12-30 04:12:32 +09:00
|
|
|
|
2017-10-10 00:30:31 +09:00
|
|
|
before { allow(controller).to receive(:doorkeeper_token) { token } }
|
2016-12-30 04:12:32 +09:00
|
|
|
|
|
|
|
describe 'GET #index' do
|
2017-10-10 00:30:31 +09:00
|
|
|
it 'limits according to limit parameter' do
|
|
|
|
2.times.map { Fabricate(:block, account: user.account) }
|
2017-06-01 03:34:51 +09:00
|
|
|
get :index, params: { limit: 1 }
|
2017-10-10 00:30:31 +09:00
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'queries blocks in range according to max_id' do
|
|
|
|
blocks = 2.times.map { Fabricate(:block, account: user.account) }
|
|
|
|
|
|
|
|
get :index, params: { max_id: blocks[1] }
|
|
|
|
|
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
expect(body_as_json[0][:id]).to eq blocks[0].target_account_id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'queries blocks in range according to since_id' do
|
|
|
|
blocks = 2.times.map { Fabricate(:block, account: user.account) }
|
2017-06-01 03:34:51 +09:00
|
|
|
|
2017-10-10 00:30:31 +09:00
|
|
|
get :index, params: { since_id: blocks[0] }
|
|
|
|
|
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
expect(body_as_json[0][:id]).to eq blocks[1].target_account_id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets pagination header for next path' do
|
|
|
|
blocks = 2.times.map { Fabricate(:block, account: user.account) }
|
|
|
|
get :index, params: { limit: 1, since_id: blocks[0] }
|
2023-02-20 14:14:10 +09: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-10 00:30:31 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets pagination header for previous path' do
|
|
|
|
block = Fabricate(:block, account: user.account)
|
|
|
|
get :index
|
2023-02-20 14:14:10 +09:00
|
|
|
expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq api_v1_blocks_url(since_id: block)
|
2017-10-10 00:30:31 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
get :index
|
2018-04-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2016-12-30 04:12:32 +09:00
|
|
|
end
|
2018-07-06 01:31:35 +09: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-30 04:12:32 +09:00
|
|
|
end
|
|
|
|
end
|