Skip to content

Commit

Permalink
feat(environments): allow environments endpoint to be searched by name
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 28, 2021
1 parent 31f859c commit ce4b188
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/pact_broker/api/resources/environments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ def uuid
end

def environments
@environments ||= environment_service.find_all
@environments ||= if request.query['name']
[environment_service.find_by_name(request.query['name'])]
else
environment_service.find_all
end
end

def schema
Expand Down
10 changes: 10 additions & 0 deletions spec/features/get_environments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@
subject
expect(response_body[:_embedded][:environments].size).to be 2
end

context "by name" do
let(:path) { PactBroker::Api::PactBrokerUrls.environments_url + "?name=test" }

it "returns the environment with the matching name" do
subject
expect(response_body[:_embedded][:environments].size).to be 1
expect(response_body[:_embedded][:environments].first[:name]).to eq "test"
end
end
end

0 comments on commit ce4b188

Please sign in to comment.