Skip to content

Commit

Permalink
feat: do not include pb:record-deployment or pb:record-release relati…
Browse files Browse the repository at this point in the history
…ons for versions embedded in resources
  • Loading branch information
bethesque committed Nov 1, 2023
1 parent 47f76f1 commit 2f43590
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/pact_broker/api/decorators/version_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require_relative "base_decorator"
require_relative "embedded_tag_decorator"
require_relative "embedded_branch_version_decorator"

module PactBroker
module Api
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/pact_broker/api/decorators/version_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f43590

Please sign in to comment.