Skip to content

Commit

Permalink
Add Tests to Filter service for fuzzy search
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Eric Garcia committed Jul 12, 2023
1 parent 846adf7 commit 6a38bd7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions backend/spec/services/filter_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@
expect(filtered_enrollments.map(&:id)).to match_array([@enrollment_franceconnect["id"], @enrollment_franceconnect2["id"]])
end
end

context "when global_search is used with fuzzy matching" do
it "returns items even when the search term is not exact" do
filters = [
{"key" => "global_search", "value" => "commune d clamart"}
].to_json
params = {filter: filters}
enrollments = Enrollment.all
filtered_enrollments = FilterService.call(params, enrollments)
expect(filtered_enrollments.map(&:id)).to match_array([@enrollment_franceconnect.id, @enrollment_api_entreprise.id])
end

it "returns no items when the search term has too much typos" do
filters = [
{"key" => "global_search", "value" => "commune d calmart"}
].to_json
params = {filter: filters}
enrollments = Enrollment.all
filtered_enrollments = FilterService.call(params, enrollments)
expect(filtered_enrollments.map(&:id)).to match_array([])
end
end
end

describe "#sanitize_value" do
Expand Down

0 comments on commit 6a38bd7

Please sign in to comment.