diff --git a/lib/pact_broker/api/decorators/pacticipant_decorator.rb b/lib/pact_broker/api/decorators/pacticipant_decorator.rb index 0ef0aff69..c4830509d 100644 --- a/lib/pact_broker/api/decorators/pacticipant_decorator.rb +++ b/lib/pact_broker/api/decorators/pacticipant_decorator.rb @@ -28,6 +28,14 @@ class PacticipantDecorator < BaseDecorator versions_url(options[:base_url], represented) end + link :'pb:version' do | options | + { + title: "Get, create or delete a pacticipant version", + href: templated_version_url_for_pacticipant(represented.name, options[:base_url]), + templated: true + } + end + link :'pb:version-tag' do | options | { title: "Get, create or delete a tag for a version of #{represented.name}", diff --git a/lib/pact_broker/api/pact_broker_urls.rb b/lib/pact_broker/api/pact_broker_urls.rb index 7f5219379..4b9cffd4a 100644 --- a/lib/pact_broker/api/pact_broker_urls.rb +++ b/lib/pact_broker/api/pact_broker_urls.rb @@ -208,6 +208,10 @@ def templated_tag_url_for_pacticipant pacticipant_name, base_url = "" pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/versions/{version}/tags/{tag}" end + def templated_version_url_for_pacticipant pacticipant_name, base_url = "" + pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/versions/{version}" + end + def templated_label_url_for_pacticipant pacticipant_name, base_url = "" pacticipant_url_from_params({ pacticipant_name: pacticipant_name }, base_url) + "/labels/{label}" end diff --git a/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb index 9ed455368..3963eece3 100644 --- a/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/pacticipant_decorator_spec.rb @@ -36,6 +36,7 @@ module Decorators pacticipant.created_at = created_at pacticipant.updated_at = updated_at allow_any_instance_of(PacticipantDecorator).to receive(:templated_tag_url_for_pacticipant).and_return('version_tag_url') + allow_any_instance_of(PacticipantDecorator).to receive(:templated_version_url_for_pacticipant).and_return('version_url') end subject { JSON.parse PacticipantDecorator.new(pacticipant).to_json(user_options: { base_url: base_url }), symbolize_names: true } @@ -50,13 +51,14 @@ module Decorators expect(subject[:_embedded][:labels].first[:_links][:self][:href]).to match %r{http://example.org/.*foo} end - it "creates the URL for a version tag" do + it "includes a relation for a version tag" do expect_any_instance_of(PacticipantDecorator).to receive(:templated_tag_url_for_pacticipant).with("Name", base_url) - subject + expect(subject[:_links][:'pb:version-tag'][:href]).to eq "version_tag_url" end - it "includes a relation for a version tag" do - expect(subject[:_links][:'pb:version-tag'][:href]).to eq "version_tag_url" + it "includes a relation for a version" do + expect_any_instance_of(PacticipantDecorator).to receive(:templated_version_url_for_pacticipant).with("Name", base_url) + expect(subject[:_links][:'pb:version'][:href]).to eq "version_url" end context "when there is a latest_version" do