Skip to content

Commit

Permalink
feat: add pb:diff relation to pact resource to view a diff with an ar…
Browse files Browse the repository at this point in the history
…bitrary pact version

Closes: #190
  • Loading branch information
bethesque committed Jul 8, 2018
1 parent 6b04d70 commit 3eaa79c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lib/pact_broker/api/decorators/pact_decorator.rb
Expand Up @@ -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}",
Expand Down
6 changes: 5 additions & 1 deletion lib/pact_broker/api/pact_broker_urls.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions spec/lib/pact_broker/api/decorators/pact_decorator_spec.rb
Expand Up @@ -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'},
Expand Down Expand Up @@ -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
Expand All @@ -116,7 +121,6 @@ module Decorators
end
end
end

end
end
end
Expand Down
11 changes: 10 additions & 1 deletion spec/lib/pact_broker/api/pact_broker_urls_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 3eaa79c

Please sign in to comment.