From af44c20d50a03b559c4fbb553ef378aeadfe5dc9 Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 11 Sep 2023 17:08:12 +0900 Subject: [PATCH] Add circle/mutuals test --- .../concerns/account_interactions_spec.rb | 18 ++++++++++++++++++ spec/services/post_status_service_spec.rb | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/spec/models/concerns/account_interactions_spec.rb b/spec/models/concerns/account_interactions_spec.rb index 84e2c91a85..0b8825135d 100644 --- a/spec/models/concerns/account_interactions_spec.rb +++ b/spec/models/concerns/account_interactions_spec.rb @@ -9,6 +9,8 @@ describe AccountInteractions do let(:target_account) { Fabricate(:account, username: 'target') } let(:target_account_id) { target_account.id } let(:target_account_ids) { [target_account_id] } + let(:follower_account) { Fabricate(:account, username: 'follower') } + let(:followee_account) { Fabricate(:account, username: 'followee') } describe '.following_map' do subject { Account.following_map(target_account_ids, account_id) } @@ -711,4 +713,20 @@ describe AccountInteractions do expect(account.lists_for_local_distribution.to_a).to contain_exactly(follower_list, self_list) end end + + describe '#mutuals' do + subject { account.mutuals } + + context 'when following target_account' do + it 'mutual one' do + account.follow!(target_account) + target_account.follow!(account) + follower_account.follow!(account) + account.follow!(followee_account) + + expect(subject.count).to eq 1 + expect(subject.first.id).to eq target_account.id + end + end + end end diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb index c6c0b2d3ef..3b953b9fc1 100644 --- a/spec/services/post_status_service_spec.rb +++ b/spec/services/post_status_service_spec.rb @@ -188,6 +188,24 @@ RSpec.describe PostStatusService, type: :service do expect(status.mentioned_accounts.first.id).to eq mutual_account.id end + it 'circle visibility' do + account = Fabricate(:account) + circle_account = Fabricate(:account) + other_account = Fabricate(:account) + circle = Fabricate(:circle, account: account) + text = 'This is an English text.' + + circle_account.follow!(account) + other_account.follow!(account) + circle.accounts << circle_account + status = subject.call(account, text: text, visibility: 'circle', circle_id: circle.id) + + expect(status.visibility).to eq 'limited' + expect(status.limited_scope).to eq 'circle' + expect(status.mentioned_accounts.count).to eq 1 + expect(status.mentioned_accounts.first.id).to eq circle_account.id + end + it 'safeguards mentions' do account = Fabricate(:account) mentioned_account = Fabricate(:account, username: 'alice')