Skip to content

Commit

Permalink
feat: search pacticipants by display_name
Browse files Browse the repository at this point in the history
  • Loading branch information
vwong committed Jun 21, 2024
1 parent 758fef7 commit c594580
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/pact_broker/pacticipants/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,16 @@ def handle_multiple_pacticipants_found(name, pacticipants)

def search_by_name(pacticipant_name)
terms = pacticipant_name.split.map { |v| v.gsub("_", "\\_") }
string_match_query = Sequel.|( *terms.map { |term| Sequel.ilike(Sequel[:pacticipants][:name], "%#{term}%") })
columns = [:name, :display_name]
string_match_query = Sequel.|(
*terms.map do |term|
Sequel.|(
*columns.map do |column|
Sequel.ilike(Sequel[:pacticipants][column], "%#{term}%")
end
)
end
)
scope_for(PactBroker::Domain::Pacticipant).where(string_match_query)
end

Expand Down
12 changes: 10 additions & 2 deletions spec/lib/pact_broker/pacticipants/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ module Pacticipants

before do
td
.create_consumer(consumer_name)
.create_consumer(provider_name)
.create_consumer(consumer_name, { display_name: "Pretty Consumer" })
.create_consumer(provider_name, { display_name: "Fancy Provider" })
end

context "when there is a consumer/provider name which matches the search term" do
Expand All @@ -242,6 +242,14 @@ module Pacticipants
searched_dataset = Repository.new.search_by_name "TEST"
expect(searched_dataset.collect(&:name)).to include(*[consumer_name, provider_name])
end

it "searches by display_name" do
searched_dataset = Repository.new.search_by_name "Pretty"
expect(searched_dataset.collect(&:name)).to eq([consumer_name])

searched_dataset = Repository.new.search_by_name "Fancy"
expect(searched_dataset.collect(&:name)).to eq([provider_name])
end
end

context "when there is NO consumer/provider name which matches the search term" do
Expand Down

0 comments on commit c594580

Please sign in to comment.