Align tests with documentation for public timeline access

pull/30625/head
Emelia Smith 2024-06-09 18:19:43 +02:00
parent 7875c06388
commit 3c886a05bc
No known key found for this signature in database
3 changed files with 40 additions and 27 deletions

View File

@ -95,37 +95,28 @@ describe 'Public' do
end
context 'when the instance does not allow public preview' do
let(:expected_statuses) { [local_status, remote_status, media_status] }
before do
Form::AdminSettings.new(timeline_preview: false).save
end
context 'with an authenticated user' do
let(:expected_statuses) { [local_status, remote_status, media_status] }
it_behaves_like 'a successful request to the public timeline'
end
context 'with an authenticated user but using the wrong scope' do
it_behaves_like 'forbidden for wrong scope', 'follow'
end
context 'with an authenticated application' do
let(:client_app) { Fabricate(:application) }
let(:token) { Fabricate(:accessible_access_token, application: client_app, scopes: scopes) }
# it_behaves_like 'a successful request to the public timeline'
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
end
it_behaves_like 'a successful request to the public timeline'
end
context 'with an unauthenticated user' do
let(:headers) { {} }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
end
end
it_behaves_like 'unauthorized for invalid token'
end
end
end

View File

@ -8,16 +8,6 @@ RSpec.describe 'Filters' do
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
shared_examples 'unauthorized for invalid token' do
let(:headers) { { 'Authorization' => '' } }
it 'returns http unauthorized' do
subject
expect(response).to have_http_status(401)
end
end
describe 'GET /api/v2/filters' do
subject do
get '/api/v2/filters', headers: headers

View File

@ -21,3 +21,35 @@ shared_examples 'forbidden for wrong role' do |wrong_role|
expect(response).to have_http_status(403)
end
end
shared_examples 'unprocessable entity' do
it 'returns http unprocessable entity' do
# Some examples have a subject which needs to be called to make a request
subject if request.nil?
expect(response).to have_http_status(422)
end
end
shared_examples 'unauthorized for invalid token' do
context 'with empty Authorization header' do
let(:headers) { { 'Authorization' => '' } }
it 'returns http unauthorized' do
# Some examples have a subject which needs to be called to make a request
subject if request.nil?
expect(response).to have_http_status(401)
end
end
context 'without Authorization header' do
let(:headers) { {} }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(401)
end
end
end