Skip to content

Commit

Permalink
Add basic coverage for MoveService class (mastodon#29301)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored and Ember-ruby committed Mar 19, 2024
1 parent 89d107f commit 84e3e65
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions spec/services/move_service_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 84e3e65

Please sign in to comment.