2023-05-12 11:13:04 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe AccountReachFinder do
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
|
2023-07-20 16:23:48 +00:00
|
|
|
let(:ap_follower_example_com) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-1', domain: 'example.com') }
|
|
|
|
let(:ap_follower_example_org) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.org/inbox-2', domain: 'example.org') }
|
|
|
|
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') }
|
2023-05-12 11:13:04 +00:00
|
|
|
|
2023-07-20 16:23:48 +00:00
|
|
|
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') }
|
|
|
|
let(:ap_mentioned_example_com) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-3', domain: 'example.com') }
|
|
|
|
let(:ap_mentioned_example_org) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.org/inbox-4', domain: 'example.org') }
|
2023-05-12 11:13:04 +00:00
|
|
|
|
2023-07-20 16:23:48 +00:00
|
|
|
let(:unrelated_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/unrelated-inbox', domain: 'example.com') }
|
2023-05-12 11:13:04 +00:00
|
|
|
|
|
|
|
before do
|
2023-06-14 14:44:37 +00:00
|
|
|
ap_follower_example_com.follow!(account)
|
|
|
|
ap_follower_example_org.follow!(account)
|
|
|
|
ap_follower_with_shared.follow!(account)
|
2023-05-12 11:13:04 +00:00
|
|
|
|
|
|
|
Fabricate(:status, account: account).tap do |status|
|
2023-06-14 14:44:37 +00:00
|
|
|
status.mentions << Mention.new(account: ap_follower_example_com)
|
|
|
|
status.mentions << Mention.new(account: ap_mentioned_with_shared)
|
2023-05-12 11:13:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Fabricate(:status, account: account)
|
|
|
|
|
|
|
|
Fabricate(:status, account: account).tap do |status|
|
2023-06-14 14:44:37 +00:00
|
|
|
status.mentions << Mention.new(account: ap_mentioned_example_com)
|
|
|
|
status.mentions << Mention.new(account: ap_mentioned_example_org)
|
2023-05-12 11:13:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Fabricate(:status).tap do |status|
|
|
|
|
status.mentions << Mention.new(account: unrelated_account)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#inboxes' do
|
2024-10-15 13:18:57 +00:00
|
|
|
subject { described_class.new(account).inboxes }
|
|
|
|
|
|
|
|
it 'includes the preferred inbox URL of followers and recently mentioned accounts but not unrelated users' do
|
|
|
|
expect(subject)
|
|
|
|
.to include(*follower_inbox_urls)
|
|
|
|
.and include(*mentioned_account_inbox_urls)
|
|
|
|
.and not_include(unrelated_account.preferred_inbox_url)
|
2023-05-12 11:13:04 +00:00
|
|
|
end
|
|
|
|
|
2024-10-15 13:18:57 +00:00
|
|
|
def follower_inbox_urls
|
|
|
|
[ap_follower_example_com, ap_follower_example_org, ap_follower_with_shared]
|
|
|
|
.map(&:preferred_inbox_url)
|
2023-05-12 11:13:04 +00:00
|
|
|
end
|
|
|
|
|
2024-10-15 13:18:57 +00:00
|
|
|
def mentioned_account_inbox_urls
|
|
|
|
[ap_mentioned_with_shared, ap_mentioned_example_com, ap_mentioned_example_org]
|
|
|
|
.map(&:preferred_inbox_url)
|
2023-05-12 11:13:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|