move_service_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe MoveService do
  4. subject { described_class.new.call(migration) }
  5. context 'with a valid migration record' do
  6. let(:migration) { Fabricate(:account_migration, account: source_account, target_account: target_account) }
  7. let(:source_account) { Fabricate(:account) }
  8. let(:target_account) { Fabricate(:account, also_known_as: [source_account_uri]) }
  9. it 'migrates the account to a new account' do
  10. expect { subject }
  11. .to change_source_moved_value
  12. .and process_local_updates
  13. .and distribute_updates
  14. .and distribute_move
  15. end
  16. end
  17. def source_account_uri
  18. ActivityPub::TagManager
  19. .instance
  20. .uri_for(source_account)
  21. end
  22. def change_source_moved_value
  23. change(source_account.reload, :moved_to_account)
  24. .from(nil)
  25. .to(target_account)
  26. end
  27. def process_local_updates
  28. enqueue_sidekiq_job(MoveWorker)
  29. .with(source_account.id, target_account.id)
  30. end
  31. def distribute_updates
  32. enqueue_sidekiq_job(ActivityPub::UpdateDistributionWorker)
  33. .with(source_account.id)
  34. end
  35. def distribute_move
  36. enqueue_sidekiq_job(ActivityPub::MoveDistributionWorker)
  37. .with(migration.id)
  38. end
  39. end