source_spec.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountSuggestions::Source do
  4. describe '#base_account_scope' do
  5. subject { FakeSource.new }
  6. before do
  7. stub_const 'FakeSource', fake_source_class
  8. end
  9. context 'with follows and follow requests' do
  10. let!(:account_domain_blocked_account) { Fabricate(:account, domain: 'blocked.host', discoverable: true) }
  11. let!(:account) { Fabricate(:account, discoverable: true) }
  12. let!(:blocked_account) { Fabricate(:account, discoverable: true) }
  13. let!(:eligible_account) { Fabricate(:account, discoverable: true) }
  14. let!(:follow_recommendation_muted_account) { Fabricate(:account, discoverable: true) }
  15. let!(:follow_requested_account) { Fabricate(:account, discoverable: true) }
  16. let!(:following_account) { Fabricate(:account, discoverable: true) }
  17. let!(:moved_account) { Fabricate(:account, moved_to_account: Fabricate(:account), discoverable: true) }
  18. let!(:silenced_account) { Fabricate(:account, silenced: true, discoverable: true) }
  19. let!(:undiscoverable_account) { Fabricate(:account, discoverable: false) }
  20. let!(:memorial_account) { Fabricate(:account, memorial: true, discoverable: true) }
  21. before do
  22. Fabricate :account_domain_block, account: account, domain: account_domain_blocked_account.domain
  23. Fabricate :block, account: account, target_account: blocked_account
  24. Fabricate :follow_recommendation_mute, account: account, target_account: follow_recommendation_muted_account
  25. Fabricate :follow_request, account: account, target_account: follow_requested_account
  26. Fabricate :follow, account: account, target_account: following_account
  27. end
  28. it 'returns eligible accounts' do
  29. results = subject.get(account)
  30. expect(results)
  31. .to include(eligible_account)
  32. .and not_include(account_domain_blocked_account)
  33. .and not_include(account)
  34. .and not_include(blocked_account)
  35. .and not_include(follow_recommendation_muted_account)
  36. .and not_include(follow_requested_account)
  37. .and not_include(following_account)
  38. .and not_include(moved_account)
  39. .and not_include(silenced_account)
  40. .and not_include(undiscoverable_account)
  41. .and not_include(memorial_account)
  42. end
  43. end
  44. end
  45. private
  46. def fake_source_class
  47. Class.new described_class do
  48. def get(account, limit: 10)
  49. base_account_scope(account)
  50. .limit(limit)
  51. end
  52. end
  53. end
  54. end