diff --git a/lib/pact_broker/api/decorators/pact_decorator.rb b/lib/pact_broker/api/decorators/pact_decorator.rb index 0959f7df0..db09766c7 100644 --- a/lib/pact_broker/api/decorators/pact_decorator.rb +++ b/lib/pact_broker/api/decorators/pact_decorator.rb @@ -99,6 +99,15 @@ def to_hash(options = {}) } end + link :'pb:diff' do | options | + { + title: "Diff with another specified version of this pact", + href: templated_diff_url(represented, options.fetch(:base_url)), + templated: true + + } + end + link :'pb:pact-webhooks' do | options | { title: "Webhooks for the pact between #{represented.consumer.name} and #{represented.provider.name}", diff --git a/lib/pact_broker/api/pact_broker_urls.rb b/lib/pact_broker/api/pact_broker_urls.rb index 65d365507..7da399dfb 100644 --- a/lib/pact_broker/api/pact_broker_urls.rb +++ b/lib/pact_broker/api/pact_broker_urls.rb @@ -51,7 +51,7 @@ def pact_url base_url, pact end def pact_version_url pact, base_url - "#{pactigration_base_url(base_url, path)}/pact-version/#{pact.sha}" + "#{pactigration_base_url(base_url, pact)}/pact-version/#{pact.pact_version_sha}" end def pact_url_from_params base_url, params @@ -81,6 +81,10 @@ def previous_distinct_diff_url pact, base_url pact_url(base_url, pact) + "/diff/previous-distinct" end + def templated_diff_url pact, base_url = '' + pact_version_url(pact, base_url) + "/diff/pact-version/{pactVersion}" + end + def previous_distinct_pact_version_url pact, base_url pact_url(base_url, pact) + "/previous-distinct" end diff --git a/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb b/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb index 57534f514..c49dedd3f 100644 --- a/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb +++ b/spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb @@ -2,13 +2,13 @@ require 'pact_broker/api/decorators/pact_decorator' module PactBroker - module Api - module Decorators - describe PactDecorator do + before do + allow_any_instance_of(PactDecorator).to receive(:templated_diff_url).and_return('templated-diff-url') + end let(:content_hash) { { 'consumer' => {'name' => 'Consumer'}, @@ -105,6 +105,11 @@ module Decorators expect(subject[:_links][:'pb:publish-verification-results'][:href]).to match %r{http://example.org/.*/verification-results} end + it "includes a link to diff this pact version with another pact version" do + expect(subject[:_links][:'pb:diff'][:href]).to eq 'templated-diff-url' + expect(subject[:_links][:'pb:diff'][:templated]).to eq true + end + it "includes a curie" do expect(subject[:_links][:curies]).to eq [{ name: "pb", href: "http://example.org/doc/{rel}", templated: true }] end @@ -116,7 +121,6 @@ module Decorators end end end - end end end diff --git a/spec/lib/pact_broker/api/pact_broker_urls_spec.rb b/spec/lib/pact_broker/api/pact_broker_urls_spec.rb index aaef0d6dd..d061af21e 100644 --- a/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +++ b/spec/lib/pact_broker/api/pact_broker_urls_spec.rb @@ -4,8 +4,11 @@ module PactBroker module Api describe PactBrokerUrls do + # Regex find all the URL parameter names + # \/\{[^\}\s\[\(\.]+\} + let(:base_url) { "http://example.org" } - let(:pact) { double('pact', consumer: consumer, provider: provider, consumer_version_number: "123") } + let(:pact) { double('pact', consumer: consumer, provider: provider, consumer_version_number: "123", pact_version_sha: "5hbfu") } let(:consumer) { double('pacticipant', name: "Foo") } let(:provider) { double('pacticipant', name: "Bar") } let(:verification) do @@ -33,6 +36,12 @@ module Api it { is_expected.to eq "http://example.org/pacts/provider/Bar/consumer/Foo/pact-version/1234/verification-results/1/triggered-webhooks" } end + + describe "templated_diff_url" do + subject { PactBrokerUrls.templated_diff_url(pact, base_url) } + + it { is_expected.to eq "http://example.org/pacts/provider/Bar/consumer/Foo/pact-version/5hbfu/diff/pact-version/{pactVersion}" } + end end end end