Merge remote-tracking branch 'parent/main' into upstream-20231221
This commit is contained in:
commit
a6b57e3890
154 changed files with 7762 additions and 1748 deletions
|
@ -9,7 +9,7 @@ describe 'Custom Emojis' do
|
|||
|
||||
describe 'GET /api/v1/custom_emojis' do
|
||||
before do
|
||||
Fabricate(:custom_emoji, domain: nil, disabled: false, visible_in_picker: true)
|
||||
Fabricate(:custom_emoji, domain: nil, disabled: false, visible_in_picker: true, shortcode: 'coolcat')
|
||||
end
|
||||
|
||||
context 'when logged out' do
|
||||
|
|
139
spec/requests/api/v1/directories_spec.rb
Normal file
139
spec/requests/api/v1/directories_spec.rb
Normal file
|
@ -0,0 +1,139 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Directories API' do
|
||||
let(:user) { Fabricate(:user, confirmed_at: nil) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:follows' }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
describe 'GET /api/v1/directories' do
|
||||
context 'with no params' do
|
||||
before do
|
||||
local_unconfirmed_account = Fabricate(
|
||||
:account,
|
||||
domain: nil,
|
||||
user: Fabricate(:user, confirmed_at: nil, approved: true),
|
||||
username: 'local_unconfirmed'
|
||||
)
|
||||
local_unconfirmed_account.create_account_stat!
|
||||
|
||||
local_unapproved_account = Fabricate(
|
||||
:account,
|
||||
domain: nil,
|
||||
user: Fabricate(:user, confirmed_at: 10.days.ago),
|
||||
username: 'local_unapproved'
|
||||
)
|
||||
local_unapproved_account.create_account_stat!
|
||||
local_unapproved_account.user.update(approved: false)
|
||||
|
||||
local_undiscoverable_account = Fabricate(
|
||||
:account,
|
||||
domain: nil,
|
||||
user: Fabricate(:user, confirmed_at: 10.days.ago, approved: true),
|
||||
discoverable: false,
|
||||
username: 'local_undiscoverable'
|
||||
)
|
||||
local_undiscoverable_account.create_account_stat!
|
||||
|
||||
excluded_from_timeline_account = Fabricate(
|
||||
:account,
|
||||
domain: 'host.example',
|
||||
discoverable: true,
|
||||
username: 'remote_excluded_from_timeline'
|
||||
)
|
||||
excluded_from_timeline_account.create_account_stat!
|
||||
Fabricate(:block, account: user.account, target_account: excluded_from_timeline_account)
|
||||
|
||||
domain_blocked_account = Fabricate(
|
||||
:account,
|
||||
domain: 'test.example',
|
||||
discoverable: true,
|
||||
username: 'remote_domain_blocked'
|
||||
)
|
||||
domain_blocked_account.create_account_stat!
|
||||
Fabricate(:account_domain_block, account: user.account, domain: 'test.example')
|
||||
|
||||
local_discoverable_account.create_account_stat!
|
||||
eligible_remote_account.create_account_stat!
|
||||
end
|
||||
|
||||
let(:local_discoverable_account) do
|
||||
Fabricate(
|
||||
:account,
|
||||
domain: nil,
|
||||
user: Fabricate(:user, confirmed_at: 10.days.ago, approved: true),
|
||||
discoverable: true,
|
||||
username: 'local_discoverable'
|
||||
)
|
||||
end
|
||||
|
||||
let(:eligible_remote_account) do
|
||||
Fabricate(
|
||||
:account,
|
||||
domain: 'host.example',
|
||||
discoverable: true,
|
||||
username: 'eligible_remote'
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns the local discoverable account and the remote discoverable account' do
|
||||
get '/api/v1/directory', headers: headers
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to eq(2)
|
||||
expect(body_as_json.pluck(:id)).to contain_exactly(eligible_remote_account.id.to_s, local_discoverable_account.id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when asking for local accounts only' do
|
||||
let(:user) { Fabricate(:user, confirmed_at: 10.days.ago, approved: true) }
|
||||
let(:local_account) { Fabricate(:account, domain: nil, user: user) }
|
||||
let(:remote_account) { Fabricate(:account, domain: 'host.example') }
|
||||
|
||||
before do
|
||||
local_account.create_account_stat!
|
||||
remote_account.create_account_stat!
|
||||
end
|
||||
|
||||
it 'returns only the local accounts' do
|
||||
get '/api/v1/directory', headers: headers, params: { local: '1' }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to eq(1)
|
||||
expect(body_as_json.first[:id]).to include(local_account.id.to_s)
|
||||
expect(response.body).to_not include(remote_account.id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ordered by active' do
|
||||
it 'returns accounts in order of most recent status activity' do
|
||||
old_stat = Fabricate(:account_stat, last_status_at: 1.day.ago)
|
||||
new_stat = Fabricate(:account_stat, last_status_at: 1.minute.ago)
|
||||
|
||||
get '/api/v1/directory', headers: headers, params: { order: 'active' }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to eq(2)
|
||||
expect(body_as_json.first[:id]).to include(new_stat.account_id.to_s)
|
||||
expect(body_as_json.second[:id]).to include(old_stat.account_id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ordered by new' do
|
||||
it 'returns accounts in order of creation' do
|
||||
account_old = Fabricate(:account_stat).account
|
||||
travel_to 10.seconds.from_now
|
||||
account_new = Fabricate(:account_stat).account
|
||||
|
||||
get '/api/v1/directory', headers: headers, params: { order: 'new' }
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.size).to eq(2)
|
||||
expect(body_as_json.first[:id]).to include(account_new.id.to_s)
|
||||
expect(body_as_json.second[:id]).to include(account_old.id.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,12 +4,6 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe 'Activity' do
|
||||
describe 'GET /api/v1/instance/activity' do
|
||||
around do |example|
|
||||
original = Setting.activity_api_enabled
|
||||
example.run
|
||||
Setting.activity_api_enabled = original
|
||||
end
|
||||
|
||||
context 'with activity api enabled' do
|
||||
before { Setting.activity_api_enabled = true }
|
||||
|
||||
|
|
|
@ -4,12 +4,6 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe 'Domain Blocks' do
|
||||
describe 'GET /api/v1/instance/domain_blocks' do
|
||||
around do |example|
|
||||
original = Setting.show_domain_blocks
|
||||
example.run
|
||||
Setting.show_domain_blocks = original
|
||||
end
|
||||
|
||||
before do
|
||||
Fabricate(:domain_block)
|
||||
end
|
||||
|
|
|
@ -4,12 +4,6 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe 'Peers' do
|
||||
describe 'GET /api/v1/instance/peers' do
|
||||
around do |example|
|
||||
original = Setting.peers_api_enabled
|
||||
example.run
|
||||
Setting.peers_api_enabled = original
|
||||
end
|
||||
|
||||
context 'with peers api enabled' do
|
||||
before { Setting.peers_api_enabled = true }
|
||||
|
||||
|
|
|
@ -13,13 +13,12 @@ RSpec.describe 'Suggestions' do
|
|||
get '/api/v1/suggestions', headers: headers, params: params
|
||||
end
|
||||
|
||||
let(:bob) { Fabricate(:account) }
|
||||
let(:jeff) { Fabricate(:account) }
|
||||
let(:bob) { Fabricate(:account) }
|
||||
let(:jeff) { Fabricate(:account) }
|
||||
let(:params) { {} }
|
||||
|
||||
before do
|
||||
PotentialFriendshipTracker.record(user.account_id, bob.id, :reblog)
|
||||
PotentialFriendshipTracker.record(user.account_id, jeff.id, :favourite)
|
||||
Setting.bootstrap_timeline_accounts = [bob, jeff].map(&:acct).join(',')
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write'
|
||||
|
@ -65,17 +64,15 @@ RSpec.describe 'Suggestions' do
|
|||
delete "/api/v1/suggestions/#{jeff.id}", headers: headers
|
||||
end
|
||||
|
||||
let(:suggestions_source) { instance_double(AccountSuggestions::PastInteractionsSource, remove: nil) }
|
||||
let(:bob) { Fabricate(:account) }
|
||||
let(:jeff) { Fabricate(:account) }
|
||||
let(:bob) { Fabricate(:account) }
|
||||
let(:jeff) { Fabricate(:account) }
|
||||
let(:scopes) { 'write' }
|
||||
|
||||
before do
|
||||
PotentialFriendshipTracker.record(user.account_id, bob.id, :reblog)
|
||||
PotentialFriendshipTracker.record(user.account_id, jeff.id, :favourite)
|
||||
allow(AccountSuggestions::PastInteractionsSource).to receive(:new).and_return(suggestions_source)
|
||||
Setting.bootstrap_timeline_accounts = [bob, jeff].map(&:acct).join(',')
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write'
|
||||
it_behaves_like 'forbidden for wrong scope', 'read'
|
||||
|
||||
it 'returns http success' do
|
||||
subject
|
||||
|
@ -86,8 +83,7 @@ RSpec.describe 'Suggestions' do
|
|||
it 'removes the specified suggestion' do
|
||||
subject
|
||||
|
||||
expect(suggestions_source).to have_received(:remove).with(user.account, jeff.id.to_s).once
|
||||
expect(suggestions_source).to_not have_received(:remove).with(user.account, bob.id.to_s)
|
||||
expect(FollowRecommendationMute.exists?(account: user.account, target_account: jeff)).to be true
|
||||
end
|
||||
|
||||
context 'without an authorization header' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue