Files
jcoffey-dev 319ed76dbd
Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Import Mastodon v4.7.3
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from
https://github.com/mastodon/mastodon, unmodified.
2026-10-05 22:03:13 -07:00

95 lines
3.3 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ActivityPub::Activity::Move do
RSpec::Matchers.define_negated_matcher :not_be_following, :be_following
RSpec::Matchers.define_negated_matcher :not_be_requested, :be_requested
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 }
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
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)
service_stub = instance_double(ActivityPub::FetchRemoteAccountService)
allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
allow(service_stub).to receive(:call).and_return(returned_account)
end
describe '#perform' do
subject { described_class.new(json, old_account) }
before do
subject.perform
end
context 'when all conditions are met', :inline_jobs do
it 'sets moved on old account, followers unfollow old account, followers request the new account' do
expect(old_account.reload.moved_to_account_id)
.to eq new_account.id
expect(follower)
.to not_be_following(old_account)
.and be_requested(new_account)
end
end
context "when the new account can't be resolved" do
let(:returned_account) { nil }
it 'does not set moved on old account, does not unfollow old, does not follow request new' do
expect(old_account.reload.moved_to_account_id)
.to be_nil
expect(follower)
.to be_following(old_account)
.and not_be_requested(new_account)
end
end
context 'when the new account does not references the old account' do
let(:also_known_as) { [] }
it 'does not set moved on old account, does not unfollow old, does not follow request new' do
expect(old_account.reload.moved_to_account_id)
.to be_nil
expect(follower)
.to be_following(old_account)
.and not_be_requested(new_account)
end
end
context 'when a Move has been recently processed' do
around do |example|
redis.set("move_in_progress:#{old_account.id}", true, nx: true, ex: 7.days.seconds)
example.run
redis.del("move_in_progress:#{old_account.id}")
end
it 'does not set moved on old account, does not unfollow old, does not follow request new' do
expect(old_account.reload.moved_to_account_id)
.to be_nil
expect(follower)
.to be_following(old_account)
.and not_be_requested(new_account)
end
end
end
end