diff --git a/lib/pact_broker/api/resources/environments.rb b/lib/pact_broker/api/resources/environments.rb index 4eb80a7b5..55669e239 100644 --- a/lib/pact_broker/api/resources/environments.rb +++ b/lib/pact_broker/api/resources/environments.rb @@ -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 diff --git a/spec/features/get_environments_spec.rb b/spec/features/get_environments_spec.rb index 3ebb9455e..8b74453b6 100644 --- a/spec/features/get_environments_spec.rb +++ b/spec/features/get_environments_spec.rb @@ -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