Fix follow suggestions potentially including silenced or blocked accounts (#29306)
This commit is contained in:
parent
68600893d2
commit
ee8d0b9447
5 changed files with 107 additions and 34 deletions
|
@ -0,0 +1,82 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AccountSuggestions::FriendsOfFriendsSource do
|
||||
describe '#get' do
|
||||
subject { described_class.new }
|
||||
|
||||
let!(:bob) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||
let!(:alice) { Fabricate(:account, discoverable: true, hide_collections: true) }
|
||||
let!(:eve) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||
let!(:mallory) { Fabricate(:account, discoverable: false, hide_collections: false) }
|
||||
let!(:eugen) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||
let!(:john) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||
let!(:jerk) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||
let!(:neil) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||
let!(:larry) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
||||
|
||||
context 'with follows and blocks' do
|
||||
before do
|
||||
bob.block!(jerk)
|
||||
FollowRecommendationMute.create!(account: bob, target_account: neil)
|
||||
|
||||
# bob follows eugen, alice and larry
|
||||
[eugen, alice, larry].each { |account| bob.follow!(account) }
|
||||
|
||||
# alice follows eve and mallory
|
||||
[john, mallory].each { |account| alice.follow!(account) }
|
||||
|
||||
# eugen follows eve, john, jerk, larry and neil
|
||||
[eve, mallory, jerk, larry, neil].each { |account| eugen.follow!(account) }
|
||||
end
|
||||
|
||||
it 'returns eligible accounts', :aggregate_failures do
|
||||
results = subject.get(bob)
|
||||
|
||||
# eve is returned through eugen
|
||||
expect(results).to include([eve.id, :friends_of_friends])
|
||||
|
||||
# john is not reachable because alice hides who she follows
|
||||
expect(results).to_not include([john.id, :friends_of_friends])
|
||||
|
||||
# mallory is not discoverable
|
||||
expect(results).to_not include([mallory.id, :friends_of_friends])
|
||||
|
||||
# larry is not included because he's followed already
|
||||
expect(results).to_not include([larry.id, :friends_of_friends])
|
||||
|
||||
# jerk is blocked
|
||||
expect(results).to_not include([jerk.id, :friends_of_friends])
|
||||
|
||||
# the suggestion for neil has already been rejected
|
||||
expect(results).to_not include([neil.id, :friends_of_friends])
|
||||
end
|
||||
end
|
||||
|
||||
context 'with deterministic order' do
|
||||
before do
|
||||
# bob follows eve and mallory
|
||||
[eve, mallory].each { |account| bob.follow!(account) }
|
||||
|
||||
# eve follows eugen, john, and jerk
|
||||
[jerk, eugen, john].each { |account| eve.follow!(account) }
|
||||
|
||||
# mallory follows eugen, john, and neil
|
||||
[neil, eugen, john].each { |account| mallory.follow!(account) }
|
||||
|
||||
john.follow!(eugen)
|
||||
john.follow!(neil)
|
||||
end
|
||||
|
||||
it 'returns eligible accounts in the expected order' do
|
||||
expect(subject.get(bob)).to eq [
|
||||
[eugen.id, :friends_of_friends], # followed by 2 friends, 3 followers total
|
||||
[john.id, :friends_of_friends], # followed by 2 friends, 2 followers total
|
||||
[neil.id, :friends_of_friends], # followed by 1 friend, 2 followers total
|
||||
[jerk.id, :friends_of_friends], # followed by 1 friend, 1 follower total
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -11,14 +11,16 @@ RSpec.describe AccountSuggestions::Source do
|
|||
end
|
||||
|
||||
context 'with follows and follow requests' do
|
||||
let!(:account_domain_blocked_account) { Fabricate(:account, domain: 'blocked.host') }
|
||||
let!(:account) { Fabricate(:account) }
|
||||
let!(:blocked_account) { Fabricate(:account) }
|
||||
let!(:eligible_account) { Fabricate(:account) }
|
||||
let!(:follow_recommendation_muted_account) { Fabricate(:account) }
|
||||
let!(:follow_requested_account) { Fabricate(:account) }
|
||||
let!(:following_account) { Fabricate(:account) }
|
||||
let!(:moved_account) { Fabricate(:account, moved_to_account: Fabricate(:account)) }
|
||||
let!(:account_domain_blocked_account) { Fabricate(:account, domain: 'blocked.host', discoverable: true) }
|
||||
let!(:account) { Fabricate(:account, discoverable: true) }
|
||||
let!(:blocked_account) { Fabricate(:account, discoverable: true) }
|
||||
let!(:eligible_account) { Fabricate(:account, discoverable: true) }
|
||||
let!(:follow_recommendation_muted_account) { Fabricate(:account, discoverable: true) }
|
||||
let!(:follow_requested_account) { Fabricate(:account, discoverable: true) }
|
||||
let!(:following_account) { Fabricate(:account, discoverable: true) }
|
||||
let!(:moved_account) { Fabricate(:account, moved_to_account: Fabricate(:account), discoverable: true) }
|
||||
let!(:silenced_account) { Fabricate(:account, silenced: true, discoverable: true) }
|
||||
let!(:undiscoverable_account) { Fabricate(:account, discoverable: false) }
|
||||
|
||||
before do
|
||||
Fabricate :account_domain_block, account: account, domain: account_domain_blocked_account.domain
|
||||
|
@ -40,6 +42,8 @@ RSpec.describe AccountSuggestions::Source do
|
|||
.and not_include(follow_requested_account)
|
||||
.and not_include(following_account)
|
||||
.and not_include(moved_account)
|
||||
.and not_include(silenced_account)
|
||||
.and not_include(undiscoverable_account)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue