Skip to content

Commit

Permalink
Try to add tests even though I don't know how to do that...
Browse files Browse the repository at this point in the history
  • Loading branch information
jsgoldstein committed Jul 19, 2023
1 parent 8441b95 commit da2cf57
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions spec/lib/search_query_transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,58 @@
expect(transformer.filter_clauses.first).to be_nil
end
end

describe '#apply' do
subject(:applied_query) do
described_class.new(
SearchQueryParser.new.parse('query')
).apply(query)
end

let(:query) { { bool: {} } }
let(:search_string) { 'search string' }
let(:term) { { term: { field_name: search_string } } }

context 'when query is just a bool' do
it 'does not modify the query' do
expect(applied_query).to eq(query)
end
end

context 'when should_clauses are present' do
let(:should) { { bool: { should: [term] } } }

it 'adds should clauses to the query' do
expect(applied_query[:bool][:should]).to include(term)
end

it 'sets minimum_should_match to 1' do
expect(applied_query[:minimum_should_match]).to eq(1)
end
end

context 'when must_clauses are present' do
let(:must) { { bool: { must: [term] } } }

it 'adds must clauses to the query' do
expect(applied_query[:bool][:must]).to include(term)
end
end

context 'when must_not_clauses are present' do
let(:must_not) { { bool: { must_not: [term] } } }

it 'adds must_not clauses to the query' do
expect(applied_query[:bool][:must_not]).to include(term)
end
end

context 'when filter_clauses are present' do
let(:filter) { { bool: { filter: [term] } } }

it 'adds filter clauses to the query' do
expect(applied_query[:bool][:filter]).to include(term)
end
end
end
end

0 comments on commit da2cf57

Please sign in to comment.