From b0064ddda764226230424b1134bfbeb098b03339 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 23 Feb 2024 04:59:29 -0500 Subject: [PATCH] Add basic coverage for `MoveService` class (#29301) --- spec/services/move_service_spec.rb | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 spec/services/move_service_spec.rb diff --git a/spec/services/move_service_spec.rb b/spec/services/move_service_spec.rb new file mode 100644 index 00000000000..e63818f67ed --- /dev/null +++ b/spec/services/move_service_spec.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe MoveService do + subject { described_class.new.call(migration) } + + context 'with a valid migration record' do + let(:migration) { Fabricate(:account_migration, account: source_account, target_account: target_account) } + let(:source_account) { Fabricate(:account) } + let(:target_account) { Fabricate(:account, also_known_as: [source_account_uri]) } + + it 'migrates the account to a new account' do + expect { subject } + .to change_source_moved_value + .and process_local_updates + .and distribute_updates + .and distribute_move + end + end + + def source_account_uri + ActivityPub::TagManager + .instance + .uri_for(source_account) + end + + def change_source_moved_value + change(source_account.reload, :moved_to_account) + .from(nil) + .to(target_account) + end + + def process_local_updates + enqueue_sidekiq_job(MoveWorker) + .with(source_account.id, target_account.id) + end + + def distribute_updates + enqueue_sidekiq_job(ActivityPub::UpdateDistributionWorker) + .with(source_account.id) + end + + def distribute_move + enqueue_sidekiq_job(ActivityPub::MoveDistributionWorker) + .with(migration.id) + end +end