about summary refs log tree commit diff
path: root/spec/presenters/familiar_followers_presenter_spec.rb
blob: 607e3002f872bf9e841446b5b07dbe7f1f1fdeef (plain) (blame)
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
51
52
53
54
55
56
57
58
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe FamiliarFollowersPresenter do
  describe '#accounts' do
    subject { described_class.new(requested_accounts, account.id) }

    let(:account) { Fabricate(:account) }
    let(:familiar_follower) { Fabricate(:account) }
    let(:requested_accounts) { Fabricate.times(2, :account) }

    before do
      familiar_follower.follow!(requested_accounts.first)
      account.follow!(familiar_follower)
    end

    it 'returns a result for each requested account' do
      expect(subject.accounts.map(&:id)).to eq requested_accounts.map(&:id)
    end

    it 'returns followers you follow' do
      result = subject.accounts.first

      expect(result).to_not be_nil
      expect(result.id).to eq requested_accounts.first.id
      expect(result.accounts).to match_array([familiar_follower])
    end

    context 'when requested account hides followers' do
      before do
        requested_accounts.first.update(hide_collections: true)
      end

      it 'does not return followers you follow' do
        result = subject.accounts.first

        expect(result).to_not be_nil
        expect(result.id).to eq requested_accounts.first.id
        expect(result.accounts).to be_empty
      end
    end

    context 'when familiar follower hides follows' do
      before do
        familiar_follower.update(hide_collections: true)
      end

      it 'does not return followers you follow' do
        result = subject.accounts.first

        expect(result).to_not be_nil
        expect(result.id).to eq requested_accounts.first.id
        expect(result.accounts).to be_empty
      end
    end
  end
end