2023-02-22 09:55:31 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-29 10:24:36 +09:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe ActivityPub::Activity::Move do
|
2021-02-02 22:49:57 +09:00
|
|
|
let(:follower) { Fabricate(:account) }
|
|
|
|
let(:old_account) { Fabricate(:account, uri: 'https://example.org/alice', domain: 'example.org', protocol: :activitypub, inbox_url: 'https://example.org/inbox') }
|
|
|
|
let(:new_account) { Fabricate(:account, uri: 'https://example.com/alice', domain: 'example.com', protocol: :activitypub, inbox_url: 'https://example.com/inbox', also_known_as: also_known_as) }
|
|
|
|
let(:also_known_as) { [old_account.uri] }
|
|
|
|
let(:returned_account) { new_account }
|
2018-12-29 10:24:36 +09:00
|
|
|
|
|
|
|
let(:json) do
|
|
|
|
{
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
id: 'foo',
|
|
|
|
type: 'Move',
|
|
|
|
actor: old_account.uri,
|
|
|
|
object: old_account.uri,
|
|
|
|
target: new_account.uri,
|
|
|
|
}.with_indifferent_access
|
|
|
|
end
|
|
|
|
|
2021-02-02 22:49:57 +09:00
|
|
|
before do
|
|
|
|
follower.follow!(old_account)
|
|
|
|
|
|
|
|
stub_request(:post, old_account.inbox_url).to_return(status: 200)
|
|
|
|
stub_request(:post, new_account.inbox_url).to_return(status: 200)
|
|
|
|
|
2023-06-22 21:55:22 +09:00
|
|
|
service_stub = instance_double(ActivityPub::FetchRemoteAccountService)
|
2021-02-02 22:49:57 +09:00
|
|
|
allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
|
|
|
|
allow(service_stub).to receive(:call).and_return(returned_account)
|
|
|
|
end
|
|
|
|
|
2018-12-29 10:24:36 +09:00
|
|
|
describe '#perform' do
|
|
|
|
subject { described_class.new(json, old_account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.perform
|
|
|
|
end
|
|
|
|
|
2024-07-09 01:01:08 +09:00
|
|
|
context 'when all conditions are met', :inline_jobs do
|
2021-02-02 22:49:57 +09:00
|
|
|
it 'sets moved account on old account' do
|
|
|
|
expect(old_account.reload.moved_to_account_id).to eq new_account.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes followers unfollow old account' do
|
|
|
|
expect(follower.following?(old_account)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes followers follow-request the new account' do
|
|
|
|
expect(follower.requested?(new_account)).to be true
|
|
|
|
end
|
2018-12-29 10:24:36 +09:00
|
|
|
end
|
|
|
|
|
2021-02-02 22:49:57 +09:00
|
|
|
context "when the new account can't be resolved" do
|
|
|
|
let(:returned_account) { nil }
|
|
|
|
|
|
|
|
it 'does not set moved account on old account' do
|
|
|
|
expect(old_account.reload.moved_to_account_id).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not make followers unfollow old account' do
|
|
|
|
expect(follower.following?(old_account)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not make followers follow-request the new account' do
|
|
|
|
expect(follower.requested?(new_account)).to be false
|
|
|
|
end
|
2018-12-29 10:24:36 +09:00
|
|
|
end
|
|
|
|
|
2021-02-02 22:49:57 +09:00
|
|
|
context 'when the new account does not references the old account' do
|
|
|
|
let(:also_known_as) { [] }
|
|
|
|
|
|
|
|
it 'does not set moved account on old account' do
|
|
|
|
expect(old_account.reload.moved_to_account_id).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not make followers unfollow old account' do
|
|
|
|
expect(follower.following?(old_account)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not make followers follow-request the new account' do
|
|
|
|
expect(follower.requested?(new_account)).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a Move has been recently processed' do
|
|
|
|
around do |example|
|
2022-04-29 00:47:34 +09:00
|
|
|
redis.set("move_in_progress:#{old_account.id}", true, nx: true, ex: 7.days.seconds)
|
2021-02-02 22:49:57 +09:00
|
|
|
example.run
|
2022-04-29 00:47:34 +09:00
|
|
|
redis.del("move_in_progress:#{old_account.id}")
|
2021-02-02 22:49:57 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not set moved account on old account' do
|
|
|
|
expect(old_account.reload.moved_to_account_id).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not make followers unfollow old account' do
|
|
|
|
expect(follower.following?(old_account)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not make followers follow-request the new account' do
|
|
|
|
expect(follower.requested?(new_account)).to be false
|
|
|
|
end
|
2018-12-29 10:24:36 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|