Skip to content

Commit

Permalink
feat(webhook status): consider http status < 300 to be a webhook failure
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 11, 2017
1 parent 056c77d commit 7ef595a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/domain/webhook_execution_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions spec/lib/pact_broker/domain/webhook_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 7ef595a

Please sign in to comment.