0
0
Fork 0

Change Move handler to also move list memberships (#24808)

This commit is contained in:
Claire 2023-05-03 14:03:38 +02:00 committed by GitHub
parent 9a52a7f7a0
commit c98b012583
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 16 deletions

View file

@ -5,22 +5,28 @@ require 'rails_helper'
describe MoveWorker do
subject { described_class.new }
let(:local_follower) { Fabricate(:account) }
let(:local_follower) { Fabricate(:account, domain: nil) }
let(:blocking_account) { Fabricate(:account) }
let(:muting_account) { Fabricate(:account) }
let(:source_account) { Fabricate(:account, protocol: :activitypub, domain: 'example.com') }
let(:target_account) { Fabricate(:account, protocol: :activitypub, domain: 'example.com') }
let(:source_account) { Fabricate(:account, protocol: :activitypub, domain: 'example.com', uri: 'https://example.org/a', inbox_url: 'https://example.org/a/inbox') }
let(:target_account) { Fabricate(:account, protocol: :activitypub, domain: 'example.com', uri: 'https://example.org/b', inbox_url: 'https://example.org/b/inbox') }
let(:local_user) { Fabricate(:user) }
let(:comment) { 'old note prior to move' }
let!(:account_note) { Fabricate(:account_note, account: local_user.account, target_account: source_account, comment: comment) }
let(:list) { Fabricate(:list, account: local_follower) }
let(:block_service) { double }
before do
stub_request(:post, 'https://example.org/a/inbox').to_return(status: 200)
stub_request(:post, 'https://example.org/b/inbox').to_return(status: 200)
local_follower.follow!(source_account)
blocking_account.block!(source_account)
muting_account.mute!(source_account)
list.accounts << source_account
allow(BlockService).to receive(:new).and_return(block_service)
allow(block_service).to receive(:call)
end
@ -86,16 +92,27 @@ describe MoveWorker do
end
end
shared_examples 'lists handling' do
it 'updates lists' do
subject.perform(source_account.id, target_account.id)
expect(list.accounts.include?(target_account)).to be true
end
end
context 'both accounts are distant' do
describe 'perform' do
it 'calls UnfollowFollowWorker' do
expect_push_bulk_to_match(UnfollowFollowWorker, [[local_follower.id, source_account.id, target_account.id, false]])
subject.perform(source_account.id, target_account.id)
Sidekiq::Testing.fake! do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, false)
Sidekiq::Worker.drain_all
end
end
include_examples 'user note handling'
include_examples 'block and mute handling'
include_examples 'followers count handling'
include_examples 'lists handling'
end
end
@ -104,13 +121,17 @@ describe MoveWorker do
describe 'perform' do
it 'calls UnfollowFollowWorker' do
expect_push_bulk_to_match(UnfollowFollowWorker, [[local_follower.id, source_account.id, target_account.id, true]])
subject.perform(source_account.id, target_account.id)
Sidekiq::Testing.fake! do
subject.perform(source_account.id, target_account.id)
expect(UnfollowFollowWorker).to have_enqueued_sidekiq_job(local_follower.id, source_account.id, target_account.id, true)
Sidekiq::Worker.clear_all
end
end
include_examples 'user note handling'
include_examples 'block and mute handling'
include_examples 'followers count handling'
include_examples 'lists handling'
end
end
@ -127,6 +148,7 @@ describe MoveWorker do
include_examples 'user note handling'
include_examples 'block and mute handling'
include_examples 'followers count handling'
include_examples 'lists handling'
it 'does not fail when a local user is already following both accounts' do
double_follower = Fabricate(:account)