From 2f43590c50c82a26f1d180ab733c9834745d0865 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 2 Nov 2023 09:49:55 +1100 Subject: [PATCH] feat: do not include pb:record-deployment or pb:record-release relations for versions embedded in resources --- .../api/decorators/version_decorator.rb | 5 +++-- .../api/decorators/version_decorator_spec.rb | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/pact_broker/api/decorators/version_decorator.rb b/lib/pact_broker/api/decorators/version_decorator.rb index b033a606b..2c7585739 100644 --- a/lib/pact_broker/api/decorators/version_decorator.rb +++ b/lib/pact_broker/api/decorators/version_decorator.rb @@ -1,5 +1,6 @@ require_relative "base_decorator" require_relative "embedded_tag_decorator" +require_relative "embedded_branch_version_decorator" module PactBroker module Api @@ -58,7 +59,7 @@ class VersionDecorator < BaseDecorator end links :'pb:record-deployment' do | context | - context.fetch(:environments, []).collect do | environment | + context[:environments]&.collect do | environment | { title: "Record deployment to #{environment.display_name}", name: environment.name, @@ -68,7 +69,7 @@ class VersionDecorator < BaseDecorator end links :'pb:record-release' do | context | - context.fetch(:environments, []).collect do | environment | + context[:environments]&.collect do | environment | { title: "Record release to #{environment.display_name}", name: environment.name, diff --git a/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb index 045a6ee01..22c00e4d3 100644 --- a/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/version_decorator_spec.rb @@ -23,6 +23,7 @@ module Decorators describe "to_json" do before do allow(decorator).to receive(:deployed_versions_for_version_and_environment_url).and_return("http://deployed-versions") + allow(decorator).to receive(:released_versions_for_version_and_environment_url).and_return("http://released-versions") end let(:version) do @@ -112,6 +113,25 @@ module Decorators href: "http://deployed-versions" ) end + + it "includes a list of environments that this version can be released to" do + expect(decorator).to receive(:released_versions_for_version_and_environment_url).with(version, environments.first, base_url) + expect(subject[:_links][:'pb:record-release']).to be_instance_of(Array) + expect(subject[:_links][:'pb:record-release'].first).to eq( + name: "test", + title: "Record release to Test", + href: "http://released-versions" + ) + end + + context "when the environments option is not present" do + let(:options) { { user_options: { base_url: base_url } } } + + it "does not include the pb:record-deployment or pb:record-release" do + expect(subject[:_links]).to_not have_key(:'pb:record-deployment') + expect(subject[:_links]).to_not have_key(:'pb:record-release') + end + end end end end