Skip to content

Commit 7ef595a

Browse files
committed
feat(webhook status): consider http status < 300 to be a webhook failure
1 parent 056c77d commit 7ef595a

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lib/pact_broker/domain/webhook_execution_result.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize response, logs, error = nil
1111
end
1212

1313
def success?
14-
!@response.nil? && @response.code.to_i < 400
14+
!@response.nil? && @response.code.to_i < 300
1515
end
1616

1717
def response

spec/lib/pact_broker/domain/webhook_request_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module Domain
5353
let!(:http_request) do
5454
stub_request(:post, "http://example.org/hook").
5555
with(:headers => {'Content-Type'=>'text/plain'}, :body => 'body').
56-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
56+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
5757
end
5858

5959
it "executes the configured request" do
@@ -70,7 +70,7 @@ module Domain
7070
it "logs the response" do
7171
allow(PactBroker.logger).to receive(:info)
7272
allow(PactBroker.logger).to receive(:debug)
73-
expect(PactBroker.logger).to receive(:info).with(/response.*302/)
73+
expect(PactBroker.logger).to receive(:info).with(/response.*200/)
7474
expect(PactBroker.logger).to receive(:debug).with(/respbod/)
7575
subject.execute(options)
7676
end
@@ -94,7 +94,7 @@ module Domain
9494
end
9595

9696
it "logs the response status" do
97-
expect(logs).to include "HTTP/1.0 302"
97+
expect(logs).to include "HTTP/1.0 200"
9898
end
9999

100100
it "logs the response headers" do
@@ -140,7 +140,7 @@ module Domain
140140
basic_auth: [username, password],
141141
:headers => {'Content-Type'=>'text/plain'},
142142
:body => 'body').
143-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
143+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
144144
end
145145

146146
it "uses the credentials" do
@@ -156,7 +156,7 @@ module Domain
156156
# webmock will set the request signature scheme to 'https' _only_ if the use_ssl option is set
157157
stub_request(:post, "https://example.org/hook").
158158
with(:headers => {'Content-Type'=>'text/plain'}, :body => 'body').
159-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
159+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
160160
end
161161

162162
it "uses SSL" do
@@ -171,7 +171,7 @@ module Domain
171171
let!(:http_request) do
172172
stub_request(:post, "http://example.org/hook").
173173
with(:headers => {'Content-Type'=>'text/plain'}, :body => body.to_json).
174-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
174+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
175175
end
176176

177177
it "converts the body to JSON before submitting the request" do
@@ -186,7 +186,7 @@ module Domain
186186
let!(:http_request) do
187187
stub_request(:post, "http://example.org/hook").
188188
with(:headers => {'Content-Type'=>'text/plain'}, :body => nil).
189-
to_return(:status => 302, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
189+
to_return(:status => 200, :body => "respbod", :headers => {'Content-Type' => 'text/foo, blah'})
190190
end
191191

192192
it "executes the request without a body" do
@@ -201,7 +201,7 @@ module Domain
201201
end
202202

203203
it "sets the response on the result" do
204-
expect(subject.execute(options).response).to be_instance_of(Net::HTTPFound)
204+
expect(subject.execute(options).response).to be_instance_of(Net::HTTPOK)
205205
end
206206
end
207207

0 commit comments

Comments
 (0)