-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add resource to view the triggered webhooks for a verification …
…result
- Loading branch information
Showing
15 changed files
with
240 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
lib/pact_broker/api/resources/verification_triggered_webhooks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'pact_broker/api/decorators/triggered_webhooks_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class VerificationTriggeredWebhooks < BaseResource | ||
def allowed_methods | ||
["GET"] | ||
end | ||
|
||
def content_types_provided | ||
[["application/hal+json", :to_json]] | ||
end | ||
|
||
def resource_exists? | ||
!!verification | ||
end | ||
|
||
def to_json | ||
Decorators::TriggeredWebhooksDecorator.new(triggered_webhooks).to_json(decorator_options) | ||
end | ||
|
||
private | ||
|
||
def triggered_webhooks | ||
webhook_service.find_triggered_webhooks_for_verification(verification) | ||
end | ||
|
||
def resource_title | ||
"Webhooks triggered by the publication of verification result #{verification.number}" | ||
end | ||
|
||
def decorator_options | ||
{ | ||
user_options: decorator_context.merge(resource_title: resource_title) | ||
} | ||
end | ||
|
||
def verification | ||
@verification ||= verification_service.find(identifier_from_path) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
spec/features/get_triggered_webhooks_for_verification_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
RSpec.describe "Get triggered webhooks for verification" do | ||
before do | ||
td.create_pact_with_hierarchy | ||
.create_verification_webhook | ||
.create_verification | ||
.create_triggered_webhook | ||
.create_webhook_execution | ||
end | ||
|
||
let(:td) { TestDataBuilder.new } | ||
let(:path) { PactBroker::Api::PactBrokerUrls.verification_triggered_webhooks_url(td.verification) } | ||
let(:json_response_body) { JSON.parse(subject.body) } | ||
|
||
subject { get(path); last_response } | ||
|
||
it { is_expected.to be_a_hal_json_success_response } | ||
|
||
it "contains a list of triggered webhooks" do | ||
expect(json_response_body['_embedded']['triggeredWebhooks'].size).to be 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
spec/lib/pact_broker/api/resources/verification_triggered_webhooks_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require 'pact_broker/api/resources/verification_triggered_webhooks' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe VerificationTriggeredWebhooks do | ||
describe "GET" do | ||
before do | ||
allow(Decorators::TriggeredWebhooksDecorator).to receive(:new).and_return(decorator) | ||
allow_any_instance_of(VerificationTriggeredWebhooks).to receive(:webhook_service).and_return(webhook_service) | ||
allow_any_instance_of(VerificationTriggeredWebhooks).to receive(:verification_service).and_return(verification_service) | ||
allow(webhook_service).to receive(:find_triggered_webhooks_for_verification).and_return(triggered_webhooks) | ||
end | ||
|
||
let(:decorator) { instance_double(Decorators::TriggeredWebhooksDecorator, to_json: 'json') } | ||
let(:webhook_service) { class_double(PactBroker::Webhooks::Service) } | ||
let(:verification_service) { class_double(PactBroker::Verifications::Service, find: verification) } | ||
let(:verification) { instance_double(PactBroker::Domain::Verification, number: "1") } | ||
let(:triggered_webhooks) { double('triggered_webhooks') } | ||
let(:path) { "/pacts/provider/bar/consumer/foo/pact-version/1234/verification-results/1/triggered-webhooks" } | ||
|
||
subject { get path; last_response } | ||
|
||
it "searchs for the verification" do | ||
expect(verification_service).to receive(:find).with( | ||
hash_including( | ||
provider_name: "bar", | ||
consumer_name: "foo", | ||
pact_version_sha: "1234", | ||
verification_number: "1" | ||
) | ||
) | ||
subject | ||
end | ||
|
||
context "when the verification exists" do | ||
|
||
it "finds the triggered webhooks for the verification" do | ||
expect(webhook_service).to receive(:find_triggered_webhooks_for_verification) | ||
subject | ||
end | ||
|
||
it { is_expected.to be_a_hal_json_success_response } | ||
|
||
it "generates the JSON response body" do | ||
expect(Decorators::TriggeredWebhooksDecorator).to receive(:new).with(triggered_webhooks) | ||
expect(decorator).to receive(:to_json) do | options | | ||
expect(options[:user_options]).to include(resource_title: "Webhooks triggered by the publication of verification result 1") | ||
expect(options[:user_options]).to include(resource_url: "http://example.org#{path}") | ||
end | ||
subject | ||
end | ||
|
||
it "returns the generated JSON response body" do | ||
expect(subject.body).to eq 'json' | ||
end | ||
end | ||
|
||
context "when the verification does not exist" do | ||
let(:verification) { nil } | ||
|
||
it { is_expected.to be_a_404_response } | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters