Skip to content

Commit

Permalink
test(search): add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasalexandre9 committed Jan 24, 2025
1 parent b508b89 commit 947e0a1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,59 @@ module Search
datasource.add_collection(collection_address)
end

context 'when disable search' do
it 'mark schema as dirty' do
collection = collection_build(
schema: {
fields: { 'foo' => column_build(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
search_collection_decorator.disable_search

expect(search_collection_decorator.last_schema).to be_nil
end

it 'sets the schema not searchable' do
collection = collection_build(
schema: {
fields: { 'foo' => column_build(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
unsearchable_schema = { searchable: true }
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: true })
search_collection_decorator.disable_search
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: false })
end
end

context 'when replace search' do
it 'mark schema as dirty' do
collection = collection_build(
schema: {
fields: { 'foo' => column_build(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
search_collection_decorator.replace_search(proc {})

expect(search_collection_decorator.last_schema).to be_nil
end

it 'sets the schema searchable' do
collection = collection_build(
schema: {
fields: { 'foo' => column_build(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
search_collection_decorator.replace_search(proc {})

expect(search_collection_decorator.schema[:searchable]).to be(true)
end
end

context 'when refine_schema' do
it 'sets the schema searchable' do
collection = build_collection(
Expand All @@ -80,21 +133,6 @@ module Search
unsearchable_schema = { searchable: false }
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: true })
end

context 'when disable search' do
it 'sets the schema not searchable' do
collection = build_collection(
schema: {
fields: { 'foo' => build_column(filter_operators: [Operators::EQUAL]) }
}
)
search_collection_decorator = described_class.new(collection, datasource)
unsearchable_schema = { searchable: true }
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: true })
search_collection_decorator.disable_search
expect(search_collection_decorator.refine_schema(unsearchable_schema)).to eq({ searchable: false })
end
end
end

context 'when refine_filter' do
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8eb0fd19608c3e5609086db683b5d6b9b6861f62399a439f5107f2fcdc2dfd0acdf09efc62589584064b83444a80a9fb88a6d4c8288df4a4f9f87404b05e1e96

0 comments on commit 947e0a1

Please sign in to comment.