2023-06-14 15:43:50 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Follow requests' do
|
|
|
|
let(:user) { Fabricate(:user, account_attributes: { locked: true }) }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
|
|
let(:scopes) { 'read:follows write:follows' }
|
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
|
|
|
|
|
|
|
describe 'GET /api/v1/follow_requests' do
|
|
|
|
subject do
|
|
|
|
get '/api/v1/follow_requests', headers: headers, params: params
|
|
|
|
end
|
|
|
|
|
2023-11-21 14:05:59 +01:00
|
|
|
let(:accounts) { Fabricate.times(2, :account) }
|
2023-06-14 15:43:50 +02:00
|
|
|
let(:params) { {} }
|
|
|
|
|
|
|
|
let(:expected_response) do
|
|
|
|
accounts.map do |account|
|
|
|
|
a_hash_including(
|
|
|
|
id: account.id.to_s,
|
|
|
|
username: account.username,
|
|
|
|
acct: account.acct
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
accounts.each { |account| FollowService.new.call(account, user.account) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'write write:follows'
|
|
|
|
|
2023-10-13 14:42:09 +02:00
|
|
|
it 'returns the expected content from accounts requesting to follow', :aggregate_failures do
|
2023-06-14 15:43:50 +02:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2024-09-20 15:13:04 +02:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2024-09-06 11:58:46 +02:00
|
|
|
expect(response.parsed_body).to match_array(expected_response)
|
2023-06-14 15:43:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with limit param' do
|
2023-11-21 14:05:59 +01:00
|
|
|
let(:params) { { limit: 1 } }
|
2023-06-14 15:43:50 +02:00
|
|
|
|
|
|
|
it 'returns only the requested number of follow requests' do
|
|
|
|
subject
|
|
|
|
|
2024-09-06 11:58:46 +02:00
|
|
|
expect(response.parsed_body.size).to eq(params[:limit])
|
2023-06-14 15:43:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST /api/v1/follow_requests/:account_id/authorize' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/follow_requests/#{follower.id}/authorize", headers: headers
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:follower) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
FollowService.new.call(follower, user.account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read read:follows'
|
|
|
|
|
2023-10-13 14:42:09 +02:00
|
|
|
it 'allows the requesting follower to follow', :aggregate_failures do
|
2023-06-14 15:43:50 +02:00
|
|
|
expect { subject }.to change { follower.following?(user.account) }.from(false).to(true)
|
2023-10-13 14:42:09 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2024-09-20 15:13:04 +02:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2024-09-06 11:58:46 +02:00
|
|
|
expect(response.parsed_body[:followed_by]).to be true
|
2023-06-14 15:43:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST /api/v1/follow_requests/:account_id/reject' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/follow_requests/#{follower.id}/reject", headers: headers
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:follower) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
FollowService.new.call(follower, user.account)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read read:follows'
|
|
|
|
|
2023-10-13 14:42:09 +02:00
|
|
|
it 'removes the follow request', :aggregate_failures do
|
2023-06-14 15:43:50 +02:00
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
2024-09-20 15:13:04 +02:00
|
|
|
expect(response.content_type)
|
|
|
|
.to start_with('application/json')
|
2023-06-14 15:43:50 +02:00
|
|
|
expect(FollowRequest.where(target_account: user.account, account: follower)).to_not exist
|
2024-09-06 11:58:46 +02:00
|
|
|
expect(response.parsed_body[:followed_by]).to be false
|
2023-06-14 15:43:50 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|