From 7ef595aa62bac16cf0add58c0c56dc8ab43b70ea Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 11 Sep 2017 15:37:12 +1000 Subject: [PATCH] feat(webhook status): consider http status < 300 to be a webhook failure --- .../domain/webhook_execution_result.rb | 2 +- .../pact_broker/domain/webhook_request_spec.rb | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/pact_broker/domain/webhook_execution_result.rb b/lib/pact_broker/domain/webhook_execution_result.rb index 9ee4c4848..78280ddb4 100644 --- a/lib/pact_broker/domain/webhook_execution_result.rb +++ b/lib/pact_broker/domain/webhook_execution_result.rb @@ -11,7 +11,7 @@ def initialize response, logs, error = nil end def success? - !@response.nil? && @response.code.to_i < 400 + !@response.nil? && @response.code.to_i < 300 end def response diff --git a/spec/lib/pact_broker/domain/webhook_request_spec.rb b/spec/lib/pact_broker/domain/webhook_request_spec.rb index a03101dd3..9e6b69fc6 100644 --- a/spec/lib/pact_broker/domain/webhook_request_spec.rb +++ b/spec/lib/pact_broker/domain/webhook_request_spec.rb @@ -53,7 +53,7 @@ module Domain let!(:http_request) do stub_request(:post, "http://example.org/hook"). with(:headers => {'Content-Type'=>'text/plain'}, :body => 'body'). - to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) + to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) end it "executes the configured request" do @@ -70,7 +70,7 @@ module Domain it "logs the response" do allow(PactBroker.logger).to receive(:info) allow(PactBroker.logger).to receive(:debug) - expect(PactBroker.logger).to receive(:info).with(/response.*302/) + expect(PactBroker.logger).to receive(:info).with(/response.*200/) expect(PactBroker.logger).to receive(:debug).with(/respbod/) subject.execute(options) end @@ -94,7 +94,7 @@ module Domain end it "logs the response status" do - expect(logs).to include "HTTP/1.0 302" + expect(logs).to include "HTTP/1.0 200" end it "logs the response headers" do @@ -140,7 +140,7 @@ module Domain basic_auth: [username, password], :headers => {'Content-Type'=>'text/plain'}, :body => 'body'). - to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) + to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) end it "uses the credentials" do @@ -156,7 +156,7 @@ module Domain # webmock will set the request signature scheme to 'https' _only_ if the use_ssl option is set stub_request(:post, "https://example.org/hook"). with(:headers => {'Content-Type'=>'text/plain'}, :body => 'body'). - to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) + to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) end it "uses SSL" do @@ -171,7 +171,7 @@ module Domain let!(:http_request) do stub_request(:post, "http://example.org/hook"). with(:headers => {'Content-Type'=>'text/plain'}, :body => body.to_json). - to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) + to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) end it "converts the body to JSON before submitting the request" do @@ -186,7 +186,7 @@ module Domain let!(:http_request) do stub_request(:post, "http://example.org/hook"). with(:headers => {'Content-Type'=>'text/plain'}, :body => nil). - to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) + to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'}) end it "executes the request without a body" do @@ -201,7 +201,7 @@ module Domain end it "sets the response on the result" do - expect(subject.execute(options).response).to be_instance_of(Net::HTTPFound) + expect(subject.execute(options).response).to be_instance_of(Net::HTTPOK) end end