Skip to content

Commit

Permalink
feat: Follow up for #239 + adding list of success codes to SAVABLE_SE…
Browse files Browse the repository at this point in the history
…TTING_NAMES variable (#388)

* Fix: HTTP Code Success check added -> the real fix for 239
Added: 'webhook_http_code_success' should be printed out too for logging/diagnosis

* feat: dummy change to make Semantic Pull Request happy again
  • Loading branch information
pitschr authored Feb 13, 2021
1 parent 980ff3b commit 08c0ad0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/pact_broker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Configuration
:webhook_http_method_whitelist,
:webhook_scheme_whitelist,
:webhook_host_whitelist,
:webhook_http_code_success,
:base_equality_only_on_content_that_affects_verification_results,
:seed_example_data,
:badge_provider_mode,
Expand Down
5 changes: 4 additions & 1 deletion lib/pact_broker/webhooks/webhook_execution_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def initialize(request, response, logs, error = nil)
end

def success?
!response.nil? && response.code.to_i < 300
unless response.nil?
# Response HTTP Code must be in success list otherwise it is false
PactBroker.configuration.webhook_http_code_success.include? response.code.to_i
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module PactBroker
module Webhooks
describe WebhookExecutionResult do
subject { WebhookExecutionResult::new(request, response, nil) }
let(:request) do
Net::HTTP::Get.new("http://example.org?foo=bar")
end

context "When 'webhook_http_code_success' has [200, 201]" do
before do
allow(PactBroker.configuration).to receive(:webhook_http_code_success).and_return([200, 201])
end

context "and response is '200'" do
let(:response) { double(code: '200') }

it "then it should be success" do
expect(subject.success?).to be_truthy
end
end

context "and response is '400'" do
let(:response) { double(code: '400') }

it "then it should fail" do
expect(subject.success?).to be_falsey
end
end
end


context "When 'webhook_http_code_success' has [400, 401]" do
before do
allow(PactBroker.configuration).to receive(:webhook_http_code_success).and_return([400, 401])
end

context "and response is '200'" do
let(:response) { double(code: '200') }

it "then it should fail" do
expect(subject.success?).to be_falsey
end
end

context "and response is '400'" do
let(:response) { double(code: '400') }

it "then it should be success" do
expect(subject.success?).to be_truthy
end
end
end

end
end
end

0 comments on commit 08c0ad0

Please sign in to comment.