2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-08-20 19:53:33 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe UnsuspendAccountService, type: :service do
|
2023-05-12 17:25:43 +10:00
|
|
|
shared_context 'with common context' do
|
2023-02-20 15:24:14 +11:00
|
|
|
subject { described_class.new.call(account) }
|
|
|
|
|
2021-08-20 19:53:33 +10:00
|
|
|
let!(:local_follower) { Fabricate(:user, current_sign_in_at: 1.hour.ago).account }
|
|
|
|
let!(:list) { Fabricate(:list, account: local_follower) }
|
|
|
|
|
|
|
|
before do
|
2023-08-22 17:31:40 +10:00
|
|
|
allow(FeedManager.instance).to receive_messages(merge_into_home: nil, merge_into_list: nil)
|
2021-08-20 19:53:33 +10:00
|
|
|
|
|
|
|
local_follower.follow!(account)
|
|
|
|
list.accounts << account
|
|
|
|
|
2023-01-05 23:47:21 +11:00
|
|
|
account.unsuspend!
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unsuspending a local account' do
|
|
|
|
def match_update_actor_request(req, account)
|
|
|
|
json = JSON.parse(req.body)
|
|
|
|
actor_id = ActivityPub::TagManager.instance.uri_for(account)
|
|
|
|
json['type'] == 'Update' && json['actor'] == actor_id && json['object']['id'] == actor_id && !json['object']['suspended']
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_request(:post, 'https://alice.com/inbox').to_return(status: 201)
|
|
|
|
stub_request(:post, 'https://bob.com/inbox').to_return(status: 201)
|
|
|
|
end
|
|
|
|
|
2023-01-05 23:47:21 +11:00
|
|
|
it 'does not change the “suspended” flag' do
|
2023-05-24 19:23:40 +10:00
|
|
|
expect { subject }.to_not change(account, :suspended?)
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
|
2023-05-12 17:25:43 +10:00
|
|
|
include_examples 'with common context' do
|
2021-08-20 19:53:33 +10:00
|
|
|
let!(:account) { Fabricate(:account) }
|
2023-07-21 02:23:48 +10:00
|
|
|
let!(:remote_follower) { Fabricate(:account, uri: 'https://alice.com', inbox_url: 'https://alice.com/inbox', protocol: :activitypub, domain: 'alice.com') }
|
|
|
|
let!(:remote_reporter) { Fabricate(:account, uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub, domain: 'bob.com') }
|
2021-08-20 19:53:33 +10:00
|
|
|
|
|
|
|
before do
|
2023-12-22 01:23:53 +11:00
|
|
|
Fabricate(:report, account: remote_reporter, target_account: account)
|
2021-08-20 19:53:33 +10:00
|
|
|
remote_follower.follow!(account)
|
|
|
|
end
|
|
|
|
|
2024-01-10 22:06:58 +11:00
|
|
|
it 'merges back into feeds of local followers and sends update', :sidekiq_inline do
|
2022-03-28 21:43:58 +11:00
|
|
|
subject
|
2023-12-06 19:44:07 +11:00
|
|
|
|
|
|
|
expect_feeds_merged
|
|
|
|
expect_updates_sent
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_feeds_merged
|
2021-08-20 19:53:33 +10:00
|
|
|
expect(FeedManager.instance).to have_received(:merge_into_home).with(account, local_follower)
|
|
|
|
expect(FeedManager.instance).to have_received(:merge_into_list).with(account, list)
|
|
|
|
end
|
|
|
|
|
2023-12-06 19:44:07 +11:00
|
|
|
def expect_updates_sent
|
2021-08-20 19:53:33 +10:00
|
|
|
expect(a_request(:post, remote_follower.inbox_url).with { |req| match_update_actor_request(req, account) }).to have_been_made.once
|
|
|
|
expect(a_request(:post, remote_reporter.inbox_url).with { |req| match_update_actor_request(req, account) }).to have_been_made.once
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'unsuspending a remote account' do
|
2023-05-12 17:25:43 +10:00
|
|
|
include_examples 'with common context' do
|
2021-08-20 19:53:33 +10:00
|
|
|
let!(:account) { Fabricate(:account, domain: 'bob.com', uri: 'https://bob.com', inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
|
2023-06-22 22:55:22 +10:00
|
|
|
let!(:resolve_account_service) { instance_double(ResolveAccountService) }
|
2021-08-20 19:53:33 +10:00
|
|
|
|
|
|
|
before do
|
2022-03-07 08:51:40 +11:00
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(resolve_account_service)
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the account is not remotely suspended' do
|
|
|
|
before do
|
2022-03-07 08:51:40 +11:00
|
|
|
allow(resolve_account_service).to receive(:call).with(account).and_return(account)
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
|
2023-12-06 19:44:07 +11:00
|
|
|
it 're-fetches the account, merges feeds, and preserves suspended' do
|
|
|
|
expect { subject }
|
|
|
|
.to_not change_suspended_flag
|
|
|
|
expect_feeds_merged
|
2022-03-07 08:51:40 +11:00
|
|
|
expect(resolve_account_service).to have_received(:call).with(account)
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
|
2023-12-06 19:44:07 +11:00
|
|
|
def expect_feeds_merged
|
2021-08-20 19:53:33 +10:00
|
|
|
expect(FeedManager.instance).to have_received(:merge_into_home).with(account, local_follower)
|
|
|
|
expect(FeedManager.instance).to have_received(:merge_into_list).with(account, list)
|
|
|
|
end
|
|
|
|
|
2023-12-06 19:44:07 +11:00
|
|
|
def change_suspended_flag
|
|
|
|
change(account, :suspended?)
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the account is remotely suspended' do
|
|
|
|
before do
|
2022-03-07 08:51:40 +11:00
|
|
|
allow(resolve_account_service).to receive(:call).with(account) do |account|
|
2021-08-20 19:53:33 +10:00
|
|
|
account.suspend!(origin: :remote)
|
|
|
|
account
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-12-06 19:44:07 +11:00
|
|
|
it 're-fetches the account, does not merge feeds, marks suspended' do
|
|
|
|
expect { subject }
|
|
|
|
.to change_suspended_to_true
|
2022-03-07 08:51:40 +11:00
|
|
|
expect(resolve_account_service).to have_received(:call).with(account)
|
2023-12-06 19:44:07 +11:00
|
|
|
expect_feeds_not_merged
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
|
2023-12-06 19:44:07 +11:00
|
|
|
def expect_feeds_not_merged
|
2021-08-20 19:53:33 +10:00
|
|
|
expect(FeedManager.instance).to_not have_received(:merge_into_home).with(account, local_follower)
|
|
|
|
expect(FeedManager.instance).to_not have_received(:merge_into_list).with(account, list)
|
|
|
|
end
|
|
|
|
|
2023-12-06 19:44:07 +11:00
|
|
|
def change_suspended_to_true
|
|
|
|
change(account, :suspended?).from(false).to(true)
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the account is remotely deleted' do
|
|
|
|
before do
|
2022-03-07 08:51:40 +11:00
|
|
|
allow(resolve_account_service).to receive(:call).with(account).and_return(nil)
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
|
2023-12-06 19:44:07 +11:00
|
|
|
it 're-fetches the account and does not merge feeds' do
|
2022-03-28 21:43:58 +11:00
|
|
|
subject
|
2023-12-06 19:44:07 +11:00
|
|
|
|
2022-03-07 08:51:40 +11:00
|
|
|
expect(resolve_account_service).to have_received(:call).with(account)
|
2023-12-06 19:44:07 +11:00
|
|
|
expect_feeds_not_merged
|
2021-08-20 19:53:33 +10:00
|
|
|
end
|
|
|
|
|
2023-12-06 19:44:07 +11:00
|
|
|
def expect_feeds_not_merged
|
2021-08-20 19:53:33 +10:00
|
|
|
expect(FeedManager.instance).to_not have_received(:merge_into_home).with(account, local_follower)
|
|
|
|
expect(FeedManager.instance).to_not have_received(:merge_into_list).with(account, list)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|