Skip to content

Commit

Permalink
feat: add relations to environments endpoint for each environment
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 27, 2021
1 parent 7d7e4db commit 784c353
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/pact_broker/api/decorators/environments_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 7 additions & 1 deletion spec/service_consumers/hal_relation_proxy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
36 changes: 36 additions & 0 deletions spec/service_consumers/provider_states_for_pact_broker_client_2.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 784c353

Please sign in to comment.