Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `.github/workflows/build-image.yml`: Upstream entirely refactored this, while we changed the docker repository to upload to and disabled the “latest” tag. Applied the repository change to `.github/workflows/build-*.yml`, as well as disabling native ARMv64 builds. - `README.md`: We have a completely different README. Kept ours. - `app/views/admin/settings/shared/_links.html.haml`: Upstream refactored, we had an extra item. Refactored as upstream did. - `spec/controllers/api/v1/timelines/public_controller_spec.rb`: Upstream deleted this file, to be replaced by a request spec at `spec/requests/api/v1/timelines/public_spec.rb`. We had an extra bit about enabling the public timelines because we have different defaults than upstream. Moved that bit to `spec/requests/api/v1/timelines/public_spec.rb`
This commit is contained in:
61
spec/requests/api/v1/bookmarks_spec.rb
Normal file
61
spec/requests/api/v1/bookmarks_spec.rb
Normal file
@ -0,0 +1,61 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Bookmarks' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:bookmarks' }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
describe 'GET /api/v1/bookmarks' do
|
||||
subject do
|
||||
get '/api/v1/bookmarks', headers: headers, params: params
|
||||
end
|
||||
|
||||
let(:params) { {} }
|
||||
let!(:bookmarks) { Fabricate.times(3, :bookmark, account: user.account) }
|
||||
|
||||
let(:expected_response) do
|
||||
bookmarks.map do |bookmark|
|
||||
a_hash_including(id: bookmark.status.id.to_s, account: a_hash_including(id: bookmark.status.account.id.to_s))
|
||||
end
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write'
|
||||
|
||||
it 'returns http success' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns the bookmarked statuses' do
|
||||
subject
|
||||
|
||||
expect(body_as_json).to match_array(expected_response)
|
||||
end
|
||||
|
||||
context 'with limit param' do
|
||||
let(:params) { { limit: 2 } }
|
||||
|
||||
it 'paginates correctly', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(body_as_json.size).to eq(params[:limit])
|
||||
expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq(api_v1_bookmarks_url(limit: params[:limit], min_id: bookmarks.last.id))
|
||||
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq(api_v1_bookmarks_url(limit: params[:limit], max_id: bookmarks[1].id))
|
||||
end
|
||||
end
|
||||
|
||||
context 'without the authorization header' do
|
||||
let(:headers) { {} }
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(401)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
90
spec/requests/api/v1/mutes_spec.rb
Normal file
90
spec/requests/api/v1/mutes_spec.rb
Normal file
@ -0,0 +1,90 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Mutes' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'read:mutes' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
describe 'GET /api/v1/mutes' do
|
||||
subject do
|
||||
get '/api/v1/mutes', headers: headers, params: params
|
||||
end
|
||||
|
||||
let!(:mutes) { Fabricate.times(3, :mute, account: user.account) }
|
||||
let(:params) { {} }
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write write:mutes'
|
||||
|
||||
it 'returns http success' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'returns the muted accounts' do
|
||||
subject
|
||||
|
||||
muted_accounts = mutes.map(&:target_account)
|
||||
|
||||
expect(body_as_json.pluck(:id)).to match_array(muted_accounts.map { |account| account.id.to_s })
|
||||
end
|
||||
|
||||
context 'with limit param' do
|
||||
let(:params) { { limit: 2 } }
|
||||
|
||||
it 'returns only the requested number of muted accounts' do
|
||||
subject
|
||||
|
||||
expect(body_as_json.size).to eq(params[:limit])
|
||||
end
|
||||
|
||||
it 'sets the correct pagination headers', :aggregate_failures do
|
||||
subject
|
||||
|
||||
headers = response.headers['Link']
|
||||
|
||||
expect(headers.find_link(%w(rel prev)).href).to eq(api_v1_mutes_url(limit: params[:limit], since_id: mutes[2].id.to_s))
|
||||
expect(headers.find_link(%w(rel next)).href).to eq(api_v1_mutes_url(limit: params[:limit], max_id: mutes[1].id.to_s))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with max_id param' do
|
||||
let(:params) { { max_id: mutes[1].id } }
|
||||
|
||||
it 'queries mutes in range according to max_id', :aggregate_failures do
|
||||
subject
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body.size).to eq 1
|
||||
expect(body[0][:id]).to eq mutes[0].target_account_id.to_s
|
||||
end
|
||||
end
|
||||
|
||||
context 'with since_id param' do
|
||||
let(:params) { { since_id: mutes[0].id } }
|
||||
|
||||
it 'queries mutes in range according to since_id', :aggregate_failures do
|
||||
subject
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body.size).to eq 2
|
||||
expect(body[0][:id]).to eq mutes[2].target_account_id.to_s
|
||||
end
|
||||
end
|
||||
|
||||
context 'without an authentication header' do
|
||||
let(:headers) { {} }
|
||||
|
||||
it 'returns http unauthorized' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(401)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
113
spec/requests/api/v1/timelines/public_spec.rb
Normal file
113
spec/requests/api/v1/timelines/public_spec.rb
Normal file
@ -0,0 +1,113 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Public' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
shared_examples 'a successful request to the public timeline' do
|
||||
it 'returns the expected statuses successfully', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.pluck(:id)).to match_array(expected_statuses.map { |status| status.id.to_s })
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/timelines/public' do
|
||||
subject do
|
||||
get '/api/v1/timelines/public', headers: headers, params: params
|
||||
end
|
||||
|
||||
let!(:private_status) { Fabricate(:status, visibility: :private) } # rubocop:disable RSpec/LetSetup
|
||||
let!(:local_status) { Fabricate(:status, account: Fabricate.build(:account, domain: nil)) }
|
||||
let!(:remote_status) { Fabricate(:status, account: Fabricate.build(:account, domain: 'example.com')) }
|
||||
let!(:media_status) { Fabricate(:status, media_attachments: [Fabricate.build(:media_attachment)]) }
|
||||
|
||||
let(:params) { {} }
|
||||
|
||||
context 'when the instance allows public preview' do
|
||||
let(:expected_statuses) { [local_status, remote_status, media_status] }
|
||||
|
||||
before do
|
||||
Setting.timeline_preview = true
|
||||
end
|
||||
|
||||
context 'with an authorized user' do
|
||||
it_behaves_like 'a successful request to the public timeline'
|
||||
end
|
||||
|
||||
context 'with an anonymous user' do
|
||||
let(:headers) { {} }
|
||||
|
||||
it_behaves_like 'a successful request to the public timeline'
|
||||
end
|
||||
|
||||
context 'with local param' do
|
||||
let(:params) { { local: true } }
|
||||
let(:expected_statuses) { [local_status, media_status] }
|
||||
|
||||
it_behaves_like 'a successful request to the public timeline'
|
||||
end
|
||||
|
||||
context 'with remote param' do
|
||||
let(:params) { { remote: true } }
|
||||
let(:expected_statuses) { [remote_status] }
|
||||
|
||||
it_behaves_like 'a successful request to the public timeline'
|
||||
end
|
||||
|
||||
context 'with only_media param' do
|
||||
let(:params) { { only_media: true } }
|
||||
let(:expected_statuses) { [media_status] }
|
||||
|
||||
it_behaves_like 'a successful request to the public timeline'
|
||||
end
|
||||
|
||||
context 'with limit param' do
|
||||
let(:params) { { limit: 1 } }
|
||||
|
||||
it 'returns only the requested number of statuses', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to eq(params[:limit])
|
||||
end
|
||||
|
||||
it 'sets the correct pagination headers', :aggregate_failures do
|
||||
subject
|
||||
|
||||
headers = response.headers['Link']
|
||||
|
||||
expect(headers.find_link(%w(rel prev)).href).to eq(api_v1_timelines_public_url(limit: 1, min_id: media_status.id.to_s))
|
||||
expect(headers.find_link(%w(rel next)).href).to eq(api_v1_timelines_public_url(limit: 1, max_id: media_status.id.to_s))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the instance does not allow public preview' do
|
||||
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 unauthenticated user' do
|
||||
let(:headers) { {} }
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user