Skip to content

Commit

Permalink
feat: rename 'wip pacts' to 'pending pacts'
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 13, 2018
1 parent 8e2dffd commit 6a46ebb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
4 changes: 3 additions & 1 deletion lib/pact/hal/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ def follow(key, http_method, *args)
Link.new(@links[key].merge(method: http_method), @client).run(*args)
end

def _link(key)
def _link(key, fallback_key = nil)
if @links[key]
Link.new(@links[key], @client)
elsif fallback_key && @links[fallback_key]
Link.new(@links[fallback_key], @client)
else
nil
end
Expand Down
6 changes: 3 additions & 3 deletions lib/pact/pact_broker.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'pact/pact_broker/fetch_pacts'
require 'pact/pact_broker/fetch_wip_pacts'
require 'pact/pact_broker/fetch_pending_pacts'

#
# @public Use by Pact Provider Verifier
Expand All @@ -12,8 +12,8 @@ def fetch_pact_uris *args
Pact::PactBroker::FetchPacts.call(*args).collect(&:uri)
end

def fetch_wip_pact_uris *args
Pact::PactBroker::FetchWipPacts.call(*args).collect(&:uri)
def fetch_pending_pact_uris *args
Pact::PactBroker::FetchPendingPacts.call(*args).collect(&:uri)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

module Pact
module PactBroker
class FetchWipPacts
class FetchPendingPacts
attr_reader :provider, :tags, :broker_base_url, :http_client_options, :http_client, :index_entity

WIP_PROVIDER_RELATION = 'beta:wip-provider-pacts'.freeze
PENDING_PROVIDER_RELATION = 'beta:pending-provider-pacts'.freeze
WIP_PROVIDER_RELATION = 'beta:wip-provider-pacts'.freeze # deprecated
PACTS = 'pacts'.freeze
PB_PACTS = 'pb:pacts'.freeze
HREF = 'href'.freeze
Expand All @@ -25,7 +26,7 @@ def self.call(provider, broker_base_url, http_client_options)

def call
if index.success?
wip_pacts_for_provider
pending_pacts_for_provider
else
raise Pact::Error.new("Error retrieving #{broker_base_url} status=#{index_entity.response.code} #{index_entity.response.raw_body}")
end
Expand All @@ -37,8 +38,8 @@ def index
@index_entity ||= Pact::Hal::Link.new({ "href" => broker_base_url }, http_client).get
end

def wip_pacts_for_provider
link = index_entity._link(WIP_PROVIDER_RELATION)
def pending_pacts_for_provider
link = index_entity._link(WIP_PROVIDER_RELATION, PENDING_PROVIDER_RELATION)
if link
get_pact_urls(link.expand(provider: provider).get)
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'pact/pact_broker/fetch_wip_pacts'
require 'pact/pact_broker/fetch_pending_pacts'

module Pact
module PactBroker
describe FetchWipPacts do
describe FetchPendingPacts do
describe "call" do
before do
allow(Pact.configuration).to receive(:output_stream).and_return(double('output stream').as_null_object)
Expand All @@ -11,7 +11,7 @@ module PactBroker
let(:provider) { "Foo"}
let(:broker_base_url) { "http://broker.org" }
let(:http_client_options) { {} }
subject { FetchWipPacts.call(provider, broker_base_url, http_client_options)}
subject { FetchPendingPacts.call(provider, broker_base_url, http_client_options)}

context "when there is an error retrieving the index resource" do
before do
Expand All @@ -32,7 +32,7 @@ module PactBroker
end
end

context "when the pb:wip-provider-pacts relation does not exist" do
context "when the pb:pending-provider-pacts relation does not exist" do
before do
stub_request(:get, "http://broker.org/").to_return(status: 200, body: response_body, headers: response_headers)
end
Expand Down
10 changes: 5 additions & 5 deletions spec/lib/pact/pact_broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ module PactBroker
end
end

describe ".fetch_wip_pact_uris" do
describe ".fetch_pending_pact_uris" do
before do
allow(Pact::PactBroker::FetchWipPacts).to receive(:call).and_return([pact_uri])
allow(Pact::PactBroker::FetchPendingPacts).to receive(:call).and_return([pact_uri])
end

let(:pact_uri) { Pact::Provider::PactURI.new("http://pact") }

subject { Pact::PactBroker.fetch_wip_pact_uris("foo") }
subject { Pact::PactBroker.fetch_pending_pact_uris("foo") }

it "calls Pact::PactBroker::FetchWipPacts" do
expect(Pact::PactBroker::FetchWipPacts).to receive(:call).with("foo")
it "calls Pact::PactBroker::FetchPendingPacts" do
expect(Pact::PactBroker::FetchPendingPacts).to receive(:call).with("foo")
subject
end

Expand Down
22 changes: 11 additions & 11 deletions spec/service_providers/pact_ruby_fetch_wip_pacts_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative 'helper'
require 'pact/pact_broker/fetch_wip_pacts'
require 'pact/pact_broker/fetch_pending_pacts'

describe Pact::PactBroker::FetchWipPacts, pact: true do
describe Pact::PactBroker::FetchPendingPacts, pact: true do
before do
allow($stdout).to receive(:puts)
end
Expand All @@ -15,7 +15,7 @@

before do
pact_broker
.given('the relation for retrieving WIP pacts exists in the index resource')
.given('the relation for retrieving pending pacts exists in the index resource')
.upon_receiving('a request for the index resource')
.with(
method: :get,
Expand All @@ -26,25 +26,25 @@
status: 200,
body: {
_links: {
'beta:wip-provider-pacts' => {
'beta:pending-provider-pacts' => {
href: Pact.term(
generate: broker_base_url + 'pacts/provider/{provider}/wip',
matcher: %r{/pacts/provider/{provider}/wip$}
generate: broker_base_url + 'pacts/provider/{provider}/pending',
matcher: %r{/pacts/provider/{provider}/pending$}
)
}
}
}
)
end

context 'retrieving WIP pacts by provider' do
context 'retrieving pending pacts by provider' do
before do
pact_broker
.given('consumer-1 has a WIP pact with provider provider-1')
.upon_receiving('a request to retrieve the WIP pacts for provider')
.given('consumer-1 has a pending pact with provider provider-1')
.upon_receiving('a request to retrieve the pending pacts for provider')
.with(
method: :get,
path: '/pacts/provider/provider-1/wip',
path: '/pacts/provider/provider-1/pending',
headers: get_headers
)
.will_respond_with(
Expand All @@ -62,7 +62,7 @@
end

it 'returns the array of pact urls' do
pacts = Pact::PactBroker::FetchWipPacts.call(provider, broker_base_url, basic_auth_options)
pacts = Pact::PactBroker::FetchPendingPacts.call(provider, broker_base_url, basic_auth_options)
expect(pacts).to eq(
[
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1', basic_auth_options)
Expand Down

0 comments on commit 6a46ebb

Please sign in to comment.