1
0

account_migration_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountMigration do
  4. describe 'Normalizations' do
  5. describe 'acct' do
  6. it { is_expected.to normalize(:acct).from(' @username@domain ').to('username@domain') }
  7. end
  8. end
  9. describe 'Validations' do
  10. subject { Fabricate.build :account_migration, account: source_account }
  11. let(:source_account) { Fabricate(:account) }
  12. let(:target_acct) { target_account.acct }
  13. context 'with valid properties' do
  14. let(:target_account) { Fabricate(:account, username: 'target', domain: 'remote.org') }
  15. before do
  16. target_account.aliases.create!(acct: source_account.acct)
  17. service_double = instance_double(ResolveAccountService)
  18. allow(ResolveAccountService).to receive(:new).and_return(service_double)
  19. allow(service_double).to receive(:call).with(target_acct, anything).and_return(target_account)
  20. end
  21. it { is_expected.to allow_value(target_account.acct).for(:acct) }
  22. end
  23. context 'with unresolvable account' do
  24. let(:target_acct) { 'target@remote' }
  25. before do
  26. service_double = instance_double(ResolveAccountService)
  27. allow(ResolveAccountService).to receive(:new).and_return(service_double)
  28. allow(service_double).to receive(:call).with(target_acct, anything).and_return(nil)
  29. end
  30. it { is_expected.to_not allow_value(target_acct).for(:acct) }
  31. end
  32. context 'with a space in the domain part' do
  33. let(:target_acct) { 'target@remote. org' }
  34. it { is_expected.to_not allow_value(target_acct).for(:acct) }
  35. end
  36. end
  37. end