2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-20 04:58:19 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 13:49:53 +10:00
|
|
|
RSpec.describe AccountMigration do
|
2024-09-04 15:12:40 +10:00
|
|
|
describe 'Normalizations' do
|
|
|
|
describe 'acct' do
|
|
|
|
it { is_expected.to normalize(:acct).from(' @username@domain ').to('username@domain') }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-07 12:35:39 +11:00
|
|
|
describe 'validations' do
|
2023-07-12 17:49:33 +10:00
|
|
|
subject { described_class.new(account: source_account, acct: target_acct) }
|
|
|
|
|
2022-12-07 12:35:39 +11:00
|
|
|
let(:source_account) { Fabricate(:account) }
|
|
|
|
let(:target_acct) { target_account.acct }
|
2019-09-20 04:58:19 +10:00
|
|
|
|
2022-12-07 12:35:39 +11: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 22:55:22 +10:00
|
|
|
service_double = instance_double(ResolveAccountService)
|
2022-12-07 12:35:39 +11: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
|
|
|
|
|
|
|
|
it 'passes validations' do
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-20 01:13:29 +10:00
|
|
|
context 'with unresolvable account' do
|
2022-12-07 12:35:39 +11:00
|
|
|
let(:target_acct) { 'target@remote' }
|
|
|
|
|
|
|
|
before do
|
2023-06-22 22:55:22 +10:00
|
|
|
service_double = instance_double(ResolveAccountService)
|
2022-12-07 12:35:39 +11:00
|
|
|
allow(ResolveAccountService).to receive(:new).and_return(service_double)
|
|
|
|
allow(service_double).to receive(:call).with(target_acct, anything).and_return(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has errors on acct field' do
|
|
|
|
expect(subject).to model_have_error_on_field(:acct)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a space in the domain part' do
|
|
|
|
let(:target_acct) { 'target@remote. org' }
|
|
|
|
|
|
|
|
it 'has errors on acct field' do
|
|
|
|
expect(subject).to model_have_error_on_field(:acct)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-20 04:58:19 +10:00
|
|
|
end
|