~cytrogen/masto-fe

ref: b9e2eb5184f3f2c92836f6aec68d0500e8de23ae masto-fe/spec/models/account_migration_spec.rb -rw-r--r-- 1.5 KiB
b9e2eb51 — renovate[bot] Update dependency @material-design-icons/svg to v0.14.12 (#26832) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe AccountMigration do
  describe 'validations' do
    subject { described_class.new(account: source_account, acct: target_acct) }

    let(:source_account) { Fabricate(:account) }
    let(:target_acct)    { target_account.acct }

    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)

        service_double = instance_double(ResolveAccountService)
        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

    context 'with unresolvable account' do
      let(:target_acct) { 'target@remote' }

      before do
        service_double = instance_double(ResolveAccountService)
        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
end