diff --git a/lib/pact_broker/webhooks/service.rb b/lib/pact_broker/webhooks/service.rb index 2d4f389e8..c80aa86a4 100644 --- a/lib/pact_broker/webhooks/service.rb +++ b/lib/pact_broker/webhooks/service.rb @@ -61,7 +61,7 @@ def self.find_all def self.execute_webhook_now webhook, pact, verification = nil triggered_webhook = webhook_repository.create_triggered_webhook(next_uuid, webhook, pact, verification, USER) - options = { failure_log_message: "Webhook execution failed", show_response: PactBroker.configuration.show_webhook_response?} + options = { failure_log_message: "Webhook execution failed"} webhook_execution_result = execute_triggered_webhook_now triggered_webhook, options if webhook_execution_result.success? webhook_repository.update_triggered_webhook_status triggered_webhook, TriggeredWebhook::STATUS_SUCCESS @@ -72,7 +72,7 @@ def self.execute_webhook_now webhook, pact, verification = nil end def self.execute_triggered_webhook_now triggered_webhook, options - webhook_execution_result = triggered_webhook.execute options + webhook_execution_result = triggered_webhook.execute options.merge(show_response: PactBroker.configuration.show_webhook_response?) webhook_repository.create_execution triggered_webhook, webhook_execution_result webhook_execution_result end diff --git a/spec/lib/pact_broker/webhooks/service_spec.rb b/spec/lib/pact_broker/webhooks/service_spec.rb index 8b824600c..c276dab7f 100644 --- a/spec/lib/pact_broker/webhooks/service_spec.rb +++ b/spec/lib/pact_broker/webhooks/service_spec.rb @@ -104,13 +104,6 @@ module Webhooks subject { PactBroker::Webhooks::Service.execute_webhook_now td.webhook, pact, td.verification } - it "executes the triggered webhook with the correct options" do - allow(PactBroker.configuration).to receive(:show_webhook_response?).and_return('foo') - expected_options = { :failure_log_message => "Webhook execution failed", :show_response => 'foo' } - expect_any_instance_of(PactBroker::Webhooks::TriggeredWebhook).to receive(:execute).with(expected_options).and_call_original - subject - end - it "executes the HTTP request of the webhook" do subject expect(http_request).to have_been_made @@ -165,6 +158,13 @@ module Webhooks expect(http_request).to have_been_made end + it "executes the webhook with the correct options" do + allow(PactBroker.configuration).to receive(:show_webhook_response?).and_return('foo') + expected_options = {:show_response => 'foo' } + expect_any_instance_of(PactBroker::Domain::WebhookRequest).to receive(:execute).with(anything, anything, hash_including(expected_options)).and_call_original + subject + end + it "saves the triggered webhook" do expect { subject }.to change { PactBroker::Webhooks::TriggeredWebhook.count }.by(1) end