2024-03-04 17:35:20 +11:00
|
|
|
# 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) }
|
2024-03-12 19:38:32 +11:00
|
|
|
let!(:neil) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
2024-03-04 17:35:20 +11:00
|
|
|
let!(:john) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
|
|
|
let!(:jerk) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
|
|
|
let!(:larry) { Fabricate(:account, discoverable: true, hide_collections: false) }
|
2024-08-20 01:55:42 +10:00
|
|
|
let!(:morty) { Fabricate(:account, discoverable: true, hide_collections: false, memorial: true) }
|
2024-03-04 17:35:20 +11:00
|
|
|
|
|
|
|
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) }
|
|
|
|
|
2024-08-20 01:55:42 +10:00
|
|
|
# eugen follows eve, john, jerk, larry, neil and morty
|
|
|
|
[eve, mallory, jerk, larry, neil, morty].each { |account| eugen.follow!(account) }
|
2024-03-04 17:35:20 +11:00
|
|
|
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])
|
2024-08-20 01:55:42 +10:00
|
|
|
|
|
|
|
# morty is not included because his account is in memoriam
|
|
|
|
expect(results).to_not include([morty.id, :friends_of_friends])
|
2024-03-04 17:35:20 +11:00
|
|
|
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
|
2024-03-12 19:38:32 +11:00
|
|
|
expect(subject.get(bob)).to eq expected_results
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains correct underlying source data' do
|
|
|
|
expect(source_query_values)
|
|
|
|
.to contain_exactly(
|
2024-03-18 23:57:21 +11:00
|
|
|
[john.id, 2, 2], # Followed by 2 friends of bob (eve, mallory), 2 followers total (breaks tie)
|
|
|
|
[eugen.id, 2, 3], # Followed by 2 friends of bob (eve, mallory), 3 followers total
|
|
|
|
[jerk.id, 1, 1], # Followed by 1 friends of bob (eve), 1 followers total (breaks tie)
|
|
|
|
[neil.id, 1, 2] # Followed by 1 friends of bob (mallory), 2 followers total
|
2024-03-12 19:38:32 +11:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expected_results
|
|
|
|
[
|
|
|
|
[john.id, :friends_of_friends],
|
2024-03-18 23:57:21 +11:00
|
|
|
[eugen.id, :friends_of_friends],
|
2024-03-12 19:38:32 +11:00
|
|
|
[jerk.id, :friends_of_friends],
|
2024-03-18 23:57:21 +11:00
|
|
|
[neil.id, :friends_of_friends],
|
2024-03-04 17:35:20 +11:00
|
|
|
]
|
|
|
|
end
|
2024-03-12 19:38:32 +11:00
|
|
|
|
|
|
|
def source_query_values
|
|
|
|
subject.source_query(bob).to_a
|
|
|
|
end
|
2024-03-04 17:35:20 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|