diff --git a/spec/requests/api/v1/timelines/public_spec.rb b/spec/requests/api/v1/timelines/public_spec.rb index 6f6dec8bf8..c9ecaf6b7a 100644 --- a/spec/requests/api/v1/timelines/public_spec.rb +++ b/spec/requests/api/v1/timelines/public_spec.rb @@ -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 diff --git a/spec/requests/api/v2/filters_spec.rb b/spec/requests/api/v2/filters_spec.rb index fd0483abbe..d5dbeeeaed 100644 --- a/spec/requests/api/v2/filters_spec.rb +++ b/spec/requests/api/v2/filters_spec.rb @@ -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 diff --git a/spec/support/examples/api.rb b/spec/support/examples/api.rb index d531860abf..5f3b45af59 100644 --- a/spec/support/examples/api.rb +++ b/spec/support/examples/api.rb @@ -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