Skip to content

Commit

Permalink
Add some more tests for account discoverability
Browse files Browse the repository at this point in the history
  • Loading branch information
jsgoldstein committed Sep 7, 2023
1 parent 9884835 commit 7051e99
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
52 changes: 52 additions & 0 deletions spec/search/models/concerns/account_search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

require 'rails_helper'

describe AccountSearch do
describe 'a non-discoverable account becoming discoverable' do
let(:account) { Account.find_by(username: 'search_test_account_1') }

context 'when picking a non-discoverable account' do
it 'its bio is not in the AccountsIndex' do
results = AccountsIndex.filter(term: { username: account.username })
expect(results.count).to eq(1)
expect(results.first.text).to be_nil
end
end

context 'when the non-discoverable account becomes discoverable' do
it 'its bio is added to the AccountsIndex' do
account.discoverable = true
account.save!
AccountsIndex.import

results = AccountsIndex.filter(term: { username: account.username })
expect(results.count).to eq(1)
expect(results.first.text).to eq(account.note)
end
end
end

describe 'a discoverable account becoming non-discoverable' do
let(:account) { Account.find_by(username: 'search_test_account_0') }

context 'when picking an discoverable account' do
it 'has its bio in the AccountsIndex' do
results = AccountsIndex.filter(term: { username: account.username })
expect(results.count).to eq(1)
expect(results.first.text).to eq(account.note)
end
end

context 'when the discoverable account becomes non-discoverable' do
it 'its bio is removed from the AccountsIndex' do
account.discoverable = false
account.save!

results = AccountsIndex.filter(term: { username: account.username })
expect(results.count).to eq(1)
expect(results.first.text).to be_nil
end
end
end
end
10 changes: 4 additions & 6 deletions spec/search/models/concerns/account_statuses_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
require 'rails_helper'

describe AccountStatusesSearch do
before do
allow(Chewy).to receive(:enabled?).and_return(true)
end

describe 'a non-indexable account becoming indexable' do
let(:account) { Account.find_by(username: 'search_test_account_2') }
let(:account) { Account.find_by(username: 'search_test_account_1') }

context 'when picking a non-indexable account' do
it 'has no statuses in the PublicStatusesIndex' do
Expand All @@ -24,14 +20,15 @@
it 'adds the public statuses to the PublicStatusesIndex' do
account.indexable = true
account.save!

expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.where(visibility: :public).count)
expect(StatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.count)
end
end
end

describe 'an indexable account becoming non-indexable' do
let(:account) { Account.find_by(username: 'search_test_account_1') }
let(:account) { Account.find_by(username: 'search_test_account_0') }

context 'when picking an indexable account' do
it 'has statuses in the PublicStatusesIndex' do
Expand All @@ -47,6 +44,7 @@
it 'removes the statuses from the PublicStatusesIndex' do
account.indexable = false
account.save!

expect(PublicStatusesIndex.filter(term: { account_id: account.id }).count).to eq(0)
expect(StatusesIndex.filter(term: { account_id: account.id }).count).to eq(account.statuses.count)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def stop
class SearchDataManager
def prepare_test_data
4.times do |i|
username = "search_test_account_#{i + 1}"
account = Fabricate.create(:account, username: username, indexable: i.even?)
username = "search_test_account_#{i}"
account = Fabricate.create(:account, username: username, indexable: i.even?, discoverable: i.even?, note: "Lover of #{i}.")
2.times do |j|
Fabricate.create(:status, account: account, text: "#{username}'s #{j + 1} post", visibility: j.even? ? :public : :private)
Fabricate.create(:status, account: account, text: "#{username}'s #{j} post", visibility: j.even? ? :public : :private)
end
end

Expand Down

0 comments on commit 7051e99

Please sign in to comment.