diff --git a/lib/pact_broker/api/decorators/environments_decorator.rb b/lib/pact_broker/api/decorators/environments_decorator.rb index aceb66b82..5f25ae190 100644 --- a/lib/pact_broker/api/decorators/environments_decorator.rb +++ b/lib/pact_broker/api/decorators/environments_decorator.rb @@ -9,6 +9,16 @@ class EnvironmentsDecorator < BaseDecorator collection :entries, :as => :environments, :class => PactBroker::Deployments::Environment, :extend => PactBroker::Api::Decorators::EnvironmentDecorator, embedded: true + links :'pb:environments' do | user_options | + represented.collect do | environment | + { + title: "Environment", + name: environment.name, + href: environment_url(environment, user_options.fetch(:base_url)) + } + end + end + link :self do | options | { title: 'Environments', diff --git a/spec/service_consumers/hal_relation_proxy_app.rb b/spec/service_consumers/hal_relation_proxy_app.rb index b0f44f58a..f054ca167 100644 --- a/spec/service_consumers/hal_relation_proxy_app.rb +++ b/spec/service_consumers/hal_relation_proxy_app.rb @@ -11,7 +11,13 @@ class HalRelationProxyApp '/HAL-REL-PLACEHOLDER-PB-WEBHOOKS' => '/webhooks', '/HAL-REL-PLACEHOLDER-INDEX-PB-PACTICIPANT-VERSION-Foo-26f353580936ad3b9baddb17b00e84f33c69e7cb' => - '/pacticipants/Foo/versions/26f353580936ad3b9baddb17b00e84f33c69e7cb' + '/pacticipants/Foo/versions/26f353580936ad3b9baddb17b00e84f33c69e7cb', + '/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS' => + '/environments', + '/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30' => + '/pacticipants/Foo/versions/5556b8149bf8bac76bc30f50a8a2dd4c22c85f30', + '/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST' => + '/pacticipants/Foo/versions/5556b8149bf8bac76bc30f50a8a2dd4c22c85f30/deployed-versions/environment/cb632df3-0a0d-4227-aac3-60114dd36479' } RESPONSE_BODY_REPLACEMENTS = { diff --git a/spec/service_consumers/provider_states_for_pact_broker_client_2.rb b/spec/service_consumers/provider_states_for_pact_broker_client_2.rb new file mode 100644 index 000000000..7ef20cf41 --- /dev/null +++ b/spec/service_consumers/provider_states_for_pact_broker_client_2.rb @@ -0,0 +1,36 @@ +Pact.provider_states_for "Pact Broker Client" do + + provider_state "the pb:pacticipant-version and pb:environments relations exist in the index resource" do + no_op + end + + provider_state "an environment with name test exists" do + set_up do + TestDataBuilder.new + .create_environment("test") + end + end + + provider_state "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment" do + set_up do + TestDataBuilder.new + .create_consumer("Foo") + .create_consumer_version("5556b8149bf8bac76bc30f50a8a2dd4c22c85f30") + .create_environment("test", uuid: "cb632df3-0a0d-4227-aac3-60114dd36479") + end + end + + provider_state "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo does not exist" do + no_op + end + + provider_state "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with 2 environments that aren't test available for deployment" do + set_up do + TestDataBuilder.new + .create_consumer("Foo") + .create_consumer_version("5556b8149bf8bac76bc30f50a8a2dd4c22c85f30") + .create_environment("prod") + .create_environment("dev") + end + end +end