2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-19 18:58:19 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 03:49:53 +00:00
|
|
|
RSpec.describe AccountMigration do
|
2024-09-04 05:12:40 +00:00
|
|
|
describe 'Normalizations' do
|
|
|
|
describe 'acct' do
|
|
|
|
it { is_expected.to normalize(:acct).from(' @username@domain ').to('username@domain') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-25 08:02:13 +00:00
|
|
|
describe 'Validations' do
|
|
|
|
subject { Fabricate.build :account_migration, account: source_account }
|
2023-07-12 07:49:33 +00:00
|
|
|
|
2022-12-07 01:35:39 +00:00
|
|
|
let(:source_account) { Fabricate(:account) }
|
|
|
|
let(:target_acct) { target_account.acct }
|
2019-09-19 18:58:19 +00:00
|
|
|
|
2022-12-07 01:35:39 +00:00
|
|
|
context 'with valid properties' do
|
|
|
|
let(:target_account) { Fabricate(:account, username: 'target', domain: 'remote.org') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
target_account.aliases.create!(acct: source_account.acct)
|
|
|
|
|
2023-06-22 12:55:22 +00:00
|
|
|
service_double = instance_double(ResolveAccountService)
|
2022-12-07 01:35:39 +00:00
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(service_double)
|
|
|
|
allow(service_double).to receive(:call).with(target_acct, anything).and_return(target_account)
|
|
|
|
end
|
|
|
|
|
2024-10-25 08:02:13 +00:00
|
|
|
it { is_expected.to allow_value(target_account.acct).for(:acct) }
|
2022-12-07 01:35:39 +00:00
|
|
|
end
|
|
|
|
|
2023-05-19 15:13:29 +00:00
|
|
|
context 'with unresolvable account' do
|
2022-12-07 01:35:39 +00:00
|
|
|
let(:target_acct) { 'target@remote' }
|
|
|
|
|
|
|
|
before do
|
2023-06-22 12:55:22 +00:00
|
|
|
service_double = instance_double(ResolveAccountService)
|
2022-12-07 01:35:39 +00:00
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(service_double)
|
|
|
|
allow(service_double).to receive(:call).with(target_acct, anything).and_return(nil)
|
|
|
|
end
|
|
|
|
|
2024-10-25 08:02:13 +00:00
|
|
|
it { is_expected.to_not allow_value(target_acct).for(:acct) }
|
2022-12-07 01:35:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a space in the domain part' do
|
|
|
|
let(:target_acct) { 'target@remote. org' }
|
|
|
|
|
2024-10-25 08:02:13 +00:00
|
|
|
it { is_expected.to_not allow_value(target_acct).for(:acct) }
|
2022-12-07 01:35:39 +00:00
|
|
|
end
|
|
|
|
end
|
2019-09-19 18:58:19 +00:00
|
|
|
end
|