account_reach_finder_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountReachFinder do
  4. let(:account) { Fabricate(:account) }
  5. let(:ap_follower_example_com) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-1', domain: 'example.com') }
  6. let(:ap_follower_example_org) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.org/inbox-2', domain: 'example.org') }
  7. let(:ap_follower_with_shared) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/users/a/inbox', domain: 'foo.bar', shared_inbox_url: 'https://foo.bar/inbox') }
  8. let(:ap_mentioned_with_shared) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/users/b/inbox', domain: 'foo.bar', shared_inbox_url: 'https://foo.bar/inbox') }
  9. let(:ap_mentioned_example_com) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-3', domain: 'example.com') }
  10. let(:ap_mentioned_example_org) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.org/inbox-4', domain: 'example.org') }
  11. let(:unrelated_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/unrelated-inbox', domain: 'example.com') }
  12. before do
  13. ap_follower_example_com.follow!(account)
  14. ap_follower_example_org.follow!(account)
  15. ap_follower_with_shared.follow!(account)
  16. Fabricate(:status, account: account).tap do |status|
  17. status.mentions << Mention.new(account: ap_follower_example_com)
  18. status.mentions << Mention.new(account: ap_mentioned_with_shared)
  19. end
  20. Fabricate(:status, account: account)
  21. Fabricate(:status, account: account).tap do |status|
  22. status.mentions << Mention.new(account: ap_mentioned_example_com)
  23. status.mentions << Mention.new(account: ap_mentioned_example_org)
  24. end
  25. Fabricate(:status).tap do |status|
  26. status.mentions << Mention.new(account: unrelated_account)
  27. end
  28. end
  29. describe '#inboxes' do
  30. subject { described_class.new(account).inboxes }
  31. it 'includes the preferred inbox URL of followers and recently mentioned accounts but not unrelated users' do
  32. expect(subject)
  33. .to include(*follower_inbox_urls)
  34. .and include(*mentioned_account_inbox_urls)
  35. .and not_include(unrelated_account.preferred_inbox_url)
  36. end
  37. def follower_inbox_urls
  38. [ap_follower_example_com, ap_follower_example_org, ap_follower_with_shared]
  39. .map(&:preferred_inbox_url)
  40. end
  41. def mentioned_account_inbox_urls
  42. [ap_mentioned_with_shared, ap_mentioned_example_com, ap_mentioned_example_org]
  43. .map(&:preferred_inbox_url)
  44. end
  45. end
  46. end