Skip to content

Commit

Permalink
feat: add pb:version relation to the pacticipant resource
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Mar 9, 2021
1 parent 984320b commit 83ce38a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions lib/pact_broker/api/decorators/pacticipant_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand Down

0 comments on commit 83ce38a

Please sign in to comment.