account_reach_finder_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountReachFinder do
  4. let(:account) { Fabricate(:account) }
  5. let(:follower1) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-1') }
  6. let(:follower2) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-2') }
  7. let(:follower3) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/users/a/inbox', shared_inbox_url: 'https://foo.bar/inbox') }
  8. let(:mentioned1) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/users/b/inbox', shared_inbox_url: 'https://foo.bar/inbox') }
  9. let(:mentioned2) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-3') }
  10. let(:mentioned3) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-4') }
  11. let(:unrelated_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/unrelated-inbox') }
  12. before do
  13. follower1.follow!(account)
  14. follower2.follow!(account)
  15. follower3.follow!(account)
  16. Fabricate(:status, account: account).tap do |status|
  17. status.mentions << Mention.new(account: follower1)
  18. status.mentions << Mention.new(account: mentioned1)
  19. end
  20. Fabricate(:status, account: account)
  21. Fabricate(:status, account: account).tap do |status|
  22. status.mentions << Mention.new(account: mentioned2)
  23. status.mentions << Mention.new(account: mentioned3)
  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. it 'includes the preferred inbox URL of followers' do
  31. expect(described_class.new(account).inboxes).to include(*[follower1, follower2, follower3].map(&:preferred_inbox_url))
  32. end
  33. it 'includes the preferred inbox URL of recently-mentioned accounts' do
  34. expect(described_class.new(account).inboxes).to include(*[mentioned1, mentioned2, mentioned3].map(&:preferred_inbox_url))
  35. end
  36. it 'does not include the inbox of unrelated users' do
  37. expect(described_class.new(account).inboxes).to_not include(unrelated_account.preferred_inbox_url)
  38. end
  39. end
  40. end