From 9d3170ef7f76a65d071fd2beb9ee87ee6f909153 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 25 Jun 2019 19:05:45 +1000 Subject: [PATCH] fix(create webhook): pass in token from command line --- lib/pact_broker/client/webhooks/create.rb | 4 +--- spec/lib/pact_broker/client/webhooks/create_spec.rb | 12 +++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/pact_broker/client/webhooks/create.rb b/lib/pact_broker/client/webhooks/create.rb index c0b631a2..654a6206 100644 --- a/lib/pact_broker/client/webhooks/create.rb +++ b/lib/pact_broker/client/webhooks/create.rb @@ -20,9 +20,7 @@ def self.call(params, pact_broker_base_url, pact_broker_client_options) def initialize(params, pact_broker_base_url, pact_broker_client_options) @params = OpenStruct.new(params) @pact_broker_base_url = pact_broker_base_url - @basic_auth_options = pact_broker_client_options[:basic_auth] || {} - @verbose = pact_broker_client_options[:verbose] - @http_client = PactBroker::Client::Hal::HttpClient.new(basic_auth_options.merge(verbose: verbose)) + @http_client = PactBroker::Client::Hal::HttpClient.new(pact_broker_client_options.merge(pact_broker_client_options[:basic_auth] || {})) end def call diff --git a/spec/lib/pact_broker/client/webhooks/create_spec.rb b/spec/lib/pact_broker/client/webhooks/create_spec.rb index a7e49819..a9008fbe 100644 --- a/spec/lib/pact_broker/client/webhooks/create_spec.rb +++ b/spec/lib/pact_broker/client/webhooks/create_spec.rb @@ -15,7 +15,7 @@ module Webhooks }.to_json end let!(:index_request) do - stub_request(:get, "http://broker").to_return(status: 200, body: index_body, headers: { "Content-Type" => "application/hal+json" } ) + stub_request(:get, "http://broker").with(headers: { "Authorization" => /.*/}).to_return(status: 200, body: index_body, headers: { "Content-Type" => "application/hal+json" } ) end let!(:webhook_request) do @@ -34,10 +34,16 @@ module Webhooks }.tap { |it| Pact::Fixture.add_fixture(:create_webhook_params, it) } end - subject { Create.call(params, "http://broker", {}) } + let(:pact_broker_client_options) do + { + token: 'token', + verbose: 'verbose' + } + end - context "when a 405 is returned from the webhook creation request" do + subject { Create.call(params, "http://broker", pact_broker_client_options) } + context "when a 405 is returned from the webhook creation request" do it "raises an error with a message to upgrade the Pact Broker" do expect { subject }.to raise_error PactBroker::Client::Error, /This version of the Pact Broker/ end