Skip to content

Commit

Permalink
feat; populate the webhook template ${pactbroker.buildUrl} from the b…
Browse files Browse the repository at this point in the history
…uildUrl of the verification results
  • Loading branch information
bethesque committed Dec 7, 2021
1 parent 972cead commit 17463b1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/verifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create_path
end

def from_json
handle_webhook_events do
handle_webhook_events(build_url: verification_params["buildUrl"]) do
verified_pacts = pact_service.find_for_verification_publication(pact_params, event_context[:consumer_version_selectors])
verification = verification_service.create(next_verification_number, verification_params, verified_pacts, event_context)
response.body = decorator_for(verification).to_json(decorator_options)
Expand Down
44 changes: 44 additions & 0 deletions spec/integration/webhooks/verification_publication_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
RSpec.describe "triggering a webhook for verification publication" do
before do
td.create_global_webhook(event_names: ["provider_verification_published"], body: webhook_body_template)
.create_pact_with_hierarchy("Foo", "1", "Bar")
end

let(:webhook_body_template) do
{
"build_url" => "${pactbroker.buildUrl}"
}
end

let(:expected_webhook_body) do
{
build_url: "http://ci/builds/1234"
}
end

let(:path) { "/pacts/provider/Bar/consumer/Foo/pact-version/#{td.and_return(:pact).pact_version_sha}/verification-results" }
let(:verification_content) { load_json_fixture("verification.json").merge("buildUrl" => "http://ci/builds/1234") }

let(:rack_headers) do
{
"CONTENT_TYPE" => "application/json",
"HTTP_ACCEPT" => "application/hal+json",
"pactbroker.database_connector" => database_connector
}
end

let!(:request) do
stub_request(:post, /http/).to_return(:status => 200)
end

subject { post(path, verification_content.to_json, rack_headers) }

let(:database_connector) { ->(&block) { block.call } }

it { is_expected.to be_a_hal_json_created_response }

it "passes through the correct parameters to the webhook" do
subject
expect(a_request(:post, /http/).with(body: expected_webhook_body)).to have_been_made
end
end

0 comments on commit 17463b1

Please sign in to comment.