diff --git a/lib/pact_broker/domain/webhook.rb b/lib/pact_broker/domain/webhook.rb index ad368b76b..c044a4e7a 100644 --- a/lib/pact_broker/domain/webhook.rb +++ b/lib/pact_broker/domain/webhook.rb @@ -31,9 +31,9 @@ def request_description request && request.description end - def execute options + def execute pact, options logger.info "Executing #{self}" - request.execute options + request.execute pact, options end def to_s diff --git a/lib/pact_broker/domain/webhook_request.rb b/lib/pact_broker/domain/webhook_request.rb index 883e2f0e5..c92675c08 100644 --- a/lib/pact_broker/domain/webhook_request.rb +++ b/lib/pact_broker/domain/webhook_request.rb @@ -47,7 +47,7 @@ def display_password password.nil? ? nil : "**********" end - def execute options = {} + def execute pact, options = {} logs = StringIO.new execution_logger = Logger.new(logs) begin diff --git a/lib/pact_broker/webhooks/triggered_webhook.rb b/lib/pact_broker/webhooks/triggered_webhook.rb index ac4a1a5f7..3bfab4e96 100644 --- a/lib/pact_broker/webhooks/triggered_webhook.rb +++ b/lib/pact_broker/webhooks/triggered_webhook.rb @@ -46,7 +46,7 @@ def request_description end def execute options - webhook.to_domain.execute options + webhook.to_domain.execute pact_publication.to_domain, options end def consumer_name diff --git a/spec/lib/pact_broker/domain/webhook_request_spec.rb b/spec/lib/pact_broker/domain/webhook_request_spec.rb index 9e6b69fc6..eeae59aa6 100644 --- a/spec/lib/pact_broker/domain/webhook_request_spec.rb +++ b/spec/lib/pact_broker/domain/webhook_request_spec.rb @@ -15,6 +15,7 @@ module Domain let(:logs) { StringIO.new } let(:execution_logger) { Logger.new(logs) } let(:options) { {failure_log_message: 'oops'}} + let(:pact) { instance_double('PactBroker::Domain::Pact') } subject do WebhookRequest.new( @@ -26,7 +27,7 @@ module Domain body: body) end - let(:logs) { subject.execute(options).logs } + let(:logs) { subject.execute(pact, options).logs } describe "description" do it "returns a brief description of the HTTP request" do @@ -57,14 +58,14 @@ module Domain end it "executes the configured request" do - subject.execute(options) + subject.execute(pact, options) expect(http_request).to have_been_made end it "logs the request" do allow(PactBroker.logger).to receive(:info) expect(PactBroker.logger).to receive(:info).with(/POST.*example.*text.*body/) - subject.execute(options) + subject.execute(pact, options) end it "logs the response" do @@ -72,7 +73,7 @@ module Domain allow(PactBroker.logger).to receive(:debug) expect(PactBroker.logger).to receive(:info).with(/response.*200/) expect(PactBroker.logger).to receive(:debug).with(/respbod/) - subject.execute(options) + subject.execute(pact, options) end describe "execution logs" do @@ -144,7 +145,7 @@ module Domain end it "uses the credentials" do - subject.execute(options) + subject.execute(pact, options) expect(http_request_with_basic_auth).to have_been_made end end @@ -160,7 +161,7 @@ module Domain end it "uses SSL" do - subject.execute(options) + subject.execute(pact, options) expect(https_request).to have_been_made end end @@ -175,7 +176,7 @@ module Domain end it "converts the body to JSON before submitting the request" do - subject.execute(options) + subject.execute(pact, options) expect(http_request).to have_been_made end end @@ -190,18 +191,18 @@ module Domain end it "executes the request without a body" do - subject.execute(options) + subject.execute(pact, options) expect(http_request).to have_been_made end end context "when the request is successful" do it "returns a WebhookExecutionResult with success=true" do - expect(subject.execute(options).success?).to be true + expect(subject.execute(pact, options).success?).to be true end it "sets the response on the result" do - expect(subject.execute(options).response).to be_instance_of(Net::HTTPOK) + expect(subject.execute(pact, options).response).to be_instance_of(Net::HTTPOK) end end @@ -214,11 +215,11 @@ module Domain end it "returns a WebhookExecutionResult with success=false" do - expect(subject.execute(options).success?).to be false + expect(subject.execute(pact, options).success?).to be false end it "sets the response on the result" do - expect(subject.execute(options).response).to be_instance_of(Net::HTTPInternalServerError) + expect(subject.execute(pact, options).response).to be_instance_of(Net::HTTPInternalServerError) end end @@ -233,15 +234,15 @@ class WebhookTestError < StandardError; end it "logs the error" do allow(PactBroker.logger).to receive(:error) expect(PactBroker.logger).to receive(:error).with(/Error.*WebhookTestError.*blah/) - subject.execute(options) + subject.execute(pact, options) end it "returns a WebhookExecutionResult with success=false" do - expect(subject.execute(options).success?).to be false + expect(subject.execute(pact, options).success?).to be false end it "returns a WebhookExecutionResult with an error" do - expect(subject.execute(options).error).to be_instance_of WebhookTestError + expect(subject.execute(pact, options).error).to be_instance_of WebhookTestError end it "logs the failure_log_message" do diff --git a/spec/lib/pact_broker/domain/webhook_spec.rb b/spec/lib/pact_broker/domain/webhook_spec.rb index 8cd9cbf81..82d56399b 100644 --- a/spec/lib/pact_broker/domain/webhook_spec.rb +++ b/spec/lib/pact_broker/domain/webhook_spec.rb @@ -11,6 +11,8 @@ module Domain let(:provider) { Pacticipant.new(name: 'Provider')} let(:request) { instance_double(PactBroker::Domain::WebhookRequest, execute: nil)} let(:options) { double('options') } + let(:pact) { double('pact') } + subject { Webhook.new(request: request, consumer: consumer, provider: provider,) } describe "description" do @@ -22,14 +24,14 @@ module Domain describe "execute" do it "executes the request" do - expect(request).to receive(:execute).with(options) - subject.execute options + expect(request).to receive(:execute).with(pact, options) + subject.execute pact, options end it "logs before and after" do allow(PactBroker.logger).to receive(:info) expect(PactBroker.logger).to receive(:info).with(/Executing/) - subject.execute options + subject.execute pact, options end end end