Skip to content

Commit

Permalink
Add searchability elasticsearch test
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 13, 2023
1 parent 59fa430 commit 42eeb62
Showing 1 changed file with 177 additions and 0 deletions.
177 changes: 177 additions & 0 deletions spec/search/services/statuses_search_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# frozen_string_literal: true

require 'rails_helper'

describe StatusesSearchService do
describe 'a local user posts with searchability' do
subject do
described_class.new.call('ohagi', account, limit: 10, searchability: searchability).map(&:id)
end

let(:alice) { Fabricate(:user).account }
let(:following) { Fabricate(:user).account }
let(:reacted) { Fabricate(:user).account }
let(:other) { Fabricate(:user).account }
let(:account) { nil }
let(:searchability) { :public }
let!(:status) { Fabricate(:status, text: 'Hello, ohagi', account: alice, searchability: searchability) }

before do
alice.update!(indexable: true)
following.follow!(alice)
Fabricate(:favourite, account: reacted, status: status)
PublicStatusesIndex.import!
StatusesIndex.import!
end

context 'when public searchability' do
let(:searchability) { :public }
let(:account) { other }

context 'with other account' do
it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end

context 'with follower' do
let(:account) { following }

it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end

context 'with reacted user' do
let(:account) { reacted }

it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end

context 'with self' do
let(:account) { alice }

it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end
end

context 'when private searchability' do
let(:searchability) { :private }
let(:account) { other }

context 'with other account' do
it 'search status' do
expect(subject.count).to eq 0
end
end

context 'with follower' do
let(:account) { following }

it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end

context 'with reacted user' do
let(:account) { reacted }

it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end

context 'with self' do
let(:account) { alice }

it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end
end

context 'when direct searchability' do
let(:searchability) { :direct }
let(:account) { other }

context 'with other account' do
it 'search status' do
expect(subject.count).to eq 0
end
end

context 'with follower' do
let(:account) { following }

it 'search status' do
expect(subject.count).to eq 0
end
end

context 'with reacted user' do
let(:account) { reacted }

it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end

context 'with self' do
let(:account) { alice }

it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end
end

context 'when limited searchability' do
let(:searchability) { :limited }
let(:account) { other }

context 'with other account' do
it 'search status' do
expect(subject.count).to eq 0
end
end

context 'with follower' do
let(:account) { following }

it 'search status' do
expect(subject.count).to eq 0
end
end

context 'with reacted user' do
let(:account) { reacted }

it 'search status' do
expect(subject.count).to eq 0
end
end

context 'with self' do
let(:account) { alice }

it 'search status' do
expect(subject.count).to eq 1
expect(subject).to include status.id
end
end
end
end
end

0 comments on commit 42eeb62

Please sign in to comment.