Skip to content

Commit

Permalink
feat: FetchPacts is not returning pactUri array instead of string arr…
Browse files Browse the repository at this point in the history
…ay. Other PR feedback.
  • Loading branch information
rashiagarwal committed Jun 23, 2018
1 parent b609289 commit fca52f2
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 55 deletions.
6 changes: 5 additions & 1 deletion lib/pact/pact_broker/fetch_pacts.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pact/hal/entity'
require 'pact/hal/http_client'
require 'pact/provider/pact_uri'

module Pact
module PactBroker
Expand All @@ -21,6 +22,7 @@ def initialize(provider, tags, broker_base_url, basic_auth_options)
tag
end
end
@basic_auth_options = basic_auth_options
@broker_base_url = broker_base_url
@http_client = Pact::Hal::HttpClient.new(basic_auth_options)
end
Expand Down Expand Up @@ -74,7 +76,9 @@ def get_latest_pacts_for_provider
end

def get_pact_urls(link_by_provider)
link_by_provider.fetch(PACTS).collect { |pact| pact[HREF] }
link_by_provider.fetch(PACTS).collect do |pact|
Pact::Provider::PactURI.new(pact[HREF], basic_auth_options)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'pact/provider/pact_verification_with_tags'
require 'pact/provider/pact_verification'
require 'pact/provider/pact_uri'
require 'pact/shared/dsl'
require 'pact/provider/world'
Expand All @@ -8,24 +8,23 @@ module Provider

module Configuration

class PactVerificationWithTags
class PactVerificationFromBroker

extend Pact::DSL

attr_accessor :name, :pact_broker_base_url, :tags, :pact_uri
attr_accessor :name, :pact_broker_base_url, :tags

def initialize(name, options = {})
puts options
@tags = options.fetch(:consumer_version_tags) || []
@pact_broker_base_url = options.fetch(:pact_broker_base_url)
@pact_broker_base_url = options.fetch(:pact_broker_base_url) || ''
@provider_name = name
@options = options
@pact_uri = nil
end

dsl do
def pact_uri pact_uri, options = {}
self.pact_uri = ::Pact::Provider::PactURI.new(pact_uri, options) if pact_uri
def pact_broker_base_url pact_broker_base_url, options
@pact_broker_base_url = URI(pact_broker_base_url)
@pact_broker_base_url.set_user(options[:username]) if options[:username] # not sure about this exactly, I'll work it out when I get there.
end
end

Expand All @@ -39,13 +38,13 @@ def finalize
def create_pact_verification
pacts = Pact::PactBroker::FetchPacts.call(@provider_name, tags, pact_broker_base_url, @options)
pacts.each do |pact_uri|
verification = Pact::Provider::PactVerificationWithTags.new(pact_uri)
verification = Pact::Provider::PactVerification.new(nil, pact_uri, nil)
Pact.provider_world.add_pact_verification verification
end
end

def validate
raise "Please provide a pact_uri for the verification" unless pact_uri
raise "Please provide a pact_broker_base_url for the verification" unless pact_broker_base_url
end

end
Expand Down
8 changes: 4 additions & 4 deletions lib/pact/provider/configuration/service_provider_dsl.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'pact/provider/configuration/pact_verification'
require 'pact/provider/configuration/pact_verification_with_tags'
require 'pact/provider/configuration/pact_verification_from_broker'
require 'pact/provider/configuration/service_provider_config'
require 'pact/errors'

Expand Down Expand Up @@ -56,16 +56,16 @@ def honours_pact_with consumer_name, options = {}, &block
end

def honours_pacts_from_pact_broker options = {}, &block
create_pact_verification_with_tags options, &block
create_pact_verification_from_broker options, &block
end
end

def create_pact_verification consumer_name, options, &block
PactVerification.build(consumer_name, options, &block)
end

def create_pact_verification_with_tags(options, &block)
PactVerificationWithTags.build(name, options, &block)
def create_pact_verification_from_broker(options, &block)
PactVerificationFromBroker.build(name, options, &block)
end

def finalize
Expand Down
28 changes: 14 additions & 14 deletions lib/pact/provider/pact_verification.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module Pact::Provider
class PactVerification
attr_reader :consumer_name, :uri, :ref
def initialize consumer_name, uri, ref
@consumer_name = consumer_name
@uri = uri
@ref = ref
end
class PactVerification
attr_reader :consumer_name, :uri, :ref
def initialize consumer_name, uri, ref
@consumer_name = consumer_name
@uri = uri
@ref = ref
end

def == other
other.is_a?(PactVerification) &&
consumer_name == other.consumer_name &&
uri == other.uri &&
ref == other.ref
end
end
def == other
other.is_a?(PactVerification) &&
consumer_name == other.consumer_name &&
uri == other.uri &&
ref == other.ref
end
end
end
13 changes: 0 additions & 13 deletions lib/pact/provider/pact_verification_with_tags.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'pact/provider/configuration/pact_verification_with_tags'
require 'pact/provider/configuration/pact_verification'
require 'pact/pact_broker/fetch_pacts'

module Pact
Expand Down Expand Up @@ -32,7 +32,7 @@ module Configuration
end
context "with valid values" do
subject do
PactVerificationWithTags.build(provider_name, options) do
PactVerificationFromBroker.build(provider_name, options) do
end
end

Expand All @@ -41,7 +41,7 @@ module Configuration

tags = [tag]
expect(Pact::PactBroker::FetchPacts).to receive(:call).with(provider_name, tags, url, options)
expect(Pact::Provider::PactVerificationWithTags).to receive(:new).with('pact-urls')
expect(Pact::Provider::PactVerification).to receive(:new).with(nil, 'pact-urls', nil)
subject
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ module Configuration
subject

expect(Pact.provider_world.pact_verifications.first)
.to eq(Pact::Provider::PactVerificationWithTags.new('pact-urls'))
.to eq(Pact::Provider::PactVerification.new(nil, 'pact-urls', nil))
end
end
end
Expand Down
44 changes: 35 additions & 9 deletions spec/service_providers/pact_ruby_fetch_pacts_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pact/consumer/rspec'
require 'pact/pact_broker/fetch_pacts'
require 'pact/provider/pact_uri'

Pact.service_consumer 'Pact Ruby' do
has_pact_with 'Pact Broker' do
Expand Down Expand Up @@ -85,8 +86,12 @@

it 'returns the array of pact urls' do
pacts = Pact::PactBroker::FetchPacts.call(provider, tags, broker_base_url, basic_auth_options)

expect(pacts).to eq(%w[http://pact-broker-url-for-consumer-1 http://pact-broker-url-for-consumer-2])
expect(pacts).to eq(
[
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1', basic_auth_options),
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-2', basic_auth_options)
]
)
end
end

Expand Down Expand Up @@ -145,8 +150,14 @@
it 'returns the array of pact urls' do
pacts = Pact::PactBroker::FetchPacts.call(provider, tags, broker_base_url, basic_auth_options)

expect(pacts).to eq(%w[http://pact-broker-url-for-consumer-1-tag-1 http://pact-broker-url-for-consumer-2-tag-1
http://pact-broker-url-for-consumer-1-tag-2 http://pact-broker-url-for-consumer-2-tag-2])
expect(pacts).to eq(
[
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1-tag-1', basic_auth_options),
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-2-tag-1', basic_auth_options),
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1-tag-2', basic_auth_options),
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-2-tag-2', basic_auth_options)
]
)
end
end

Expand Down Expand Up @@ -197,8 +208,12 @@

it 'returns the array of pact urls' do
pacts = Pact::PactBroker::FetchPacts.call(provider, tags, broker_base_url, basic_auth_options)

expect(pacts).to eq(%w[http://pact-broker-url-for-consumer-1-master http://pact-broker-url-for-consumer-2-master])
expect(pacts).to eq(
[
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1-master', basic_auth_options),
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-2-master', basic_auth_options)
]
)
end
end

Expand Down Expand Up @@ -287,8 +302,14 @@
it 'returns the array of pact urls' do
pacts = Pact::PactBroker::FetchPacts.call(provider, tags, broker_base_url, basic_auth_options)

expect(pacts).to eq(%w[http://pact-broker-url-for-consumer-1-tag-1 http://pact-broker-url-for-consumer-2-tag-1
http://pact-broker-url-for-consumer-1-tag-2-all http://pact-broker-url-for-consumer-2-tag-2-all])
expect(pacts).to eq(
[
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1-tag-1', basic_auth_options),
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-2-tag-1', basic_auth_options),
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1-tag-2-all', basic_auth_options),
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-2-tag-2-all', basic_auth_options)
]
)
end
end

Expand Down Expand Up @@ -324,7 +345,12 @@
it 'returns the array of pact urls' do
pacts = Pact::PactBroker::FetchPacts.call(provider, tags, broker_base_url, basic_auth_options)

expect(pacts).to eq(%w[http://pact-broker-url-for-consumer-1-all http://pact-broker-url-for-consumer-2-all])
expect(pacts).to eq(
[
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-1-all', basic_auth_options),
Pact::Provider::PactURI.new('http://pact-broker-url-for-consumer-2-all', basic_auth_options)
]
)
end
end
end
Expand Down

0 comments on commit fca52f2

Please sign in to comment.