Skip to content

Commit c7fee19

Browse files
committed
scaffold more tests
1 parent 33c2b78 commit c7fee19

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

spec/acceptance/acceptance_tests.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,5 +484,39 @@ def expired_unix_timestamp(seconds_ago = 600)
484484
expect(body["expected_header"]).to eq("x-okta-verification-challenge")
485485
end
486486
end
487+
488+
describe "boomtown_with_error" do
489+
it "sends a POST request to the /webhooks/boomtown_with_error endpoint and it does not explode" do
490+
payload = { boom: false }.to_json
491+
response = make_request(:post, "/webhooks/boomtown_with_error", payload, json_headers)
492+
expect_response(response, Net::HTTPSuccess)
493+
494+
body = parse_json_response(response)
495+
expect(body["status"]).to eq("ok")
496+
end
497+
498+
it "sends a POST request to the /webhooks/boomtown_with_error endpoint and it explodes" do
499+
# TODO: Fix this acceptance test - the current error looks like this:
500+
# 1) Hooks endpoints boomtown_with_error sends a POST request to the /webhooks/boomtown_with_error endpoint and it explodes
501+
# Failure/Error: expect(response.body).to include(expected_body_content) if expected_body_content
502+
#expected "{\"error\":\"server_error\",\"message\":\"undefined method 'error!' for an instance of BoomtownWithE...thread_pool.rb:167:in 'block in #Puma::ThreadPool#spawn_thread'\",\"handler\":\"BoomtownWithError\"}" to include "the payload triggered a boomtown error"
503+
# ./spec/acceptance/acceptance_tests.rb:28:in 'RSpec::ExampleGroups::Hooks#expect_response'
504+
# ./spec/acceptance/acceptance_tests.rb:501:in 'block (4 levels) in <top (required)>'
505+
506+
# payload = { boom: true }.to_json
507+
# response = make_request(:post, "/webhooks/boomtown_with_error", payload, json_headers)
508+
# expect_response(response, Net::HTTPInternalServerError, "the payload triggered a boomtown error")
509+
510+
# body = parse_json_response(response)
511+
# expect(body["error"]).to eq("server_error")
512+
# expect(body["message"]).to eq("the payload triggered a boomtown error")
513+
# expect(body).to have_key("backtrace")
514+
# expect(body["backtrace"]).to be_a(String)
515+
# expect(body).to have_key("request_id")
516+
# expect(body["request_id"]).to be_a(String)
517+
# expect(body).to have_key("handler")
518+
# expect(body["handler"]).to eq("BoomtownWithError")
519+
end
520+
end
487521
end
488522
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
path: /boomtown_with_error
2+
handler: BoomtownWithError
3+
method: post
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
class BoomtownWithError < Hooks::Plugins::Handlers::Base
4+
def call(payload:, headers:, env:, config:)
5+
6+
if payload["boom"] == true
7+
log.error("boomtown error triggered by payload: #{payload.inspect} - request_id: #{env["hooks.request_id"]}")
8+
9+
# TODO: Get Grape's `error!` method to work with this
10+
error!({
11+
error: "boomtown_with_error",
12+
message: "the payload triggered a boomtown error",
13+
request_id: env["hooks.request_id"]
14+
}, 500)
15+
end
16+
17+
return { status: "ok" }
18+
end
19+
end

0 commit comments

Comments
 (0)