-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webhook status): add endpoint for triggered webhook execution logs
- Loading branch information
Showing
4 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'pact_broker/api/resources/base_resource' | ||
require 'pact_broker/webhooks/triggered_webhook' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
|
||
class TriggeredWebhookLogs < BaseResource | ||
|
||
def content_types_provided | ||
[["text/plain", :to_text]] | ||
end | ||
|
||
def allowed_methods | ||
["GET"] | ||
end | ||
|
||
def resource_exists? | ||
triggered_webhook | ||
end | ||
|
||
def to_text | ||
# Too simple to bother putting into a service | ||
triggered_webhook.webhook_executions.collect(&:logs).join("\n") | ||
end | ||
|
||
def triggered_webhook | ||
@triggered_webhook ||= begin | ||
criteria = {webhook_uuid: identifier_from_path[:uuid], trigger_uuid: identifier_from_path[:trigger_uuid]} | ||
PactBroker::Webhooks::TriggeredWebhook.where(criteria).single_record | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
spec/lib/pact_broker/api/resources/triggered_webhook_logs_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,28 @@ | ||
require 'pact_broker/api/resources/triggered_webhook_logs' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
describe TriggeredWebhookLogs do | ||
|
||
let(:td) { TestDataBuilder.new } | ||
|
||
before do | ||
td.create_pact_with_hierarchy | ||
.create_webhook(uuid: "5432") | ||
.create_triggered_webhook(trigger_uuid: "1234") | ||
.create_webhook_execution(logs: "foo") | ||
.create_webhook_execution(logs: "bar") | ||
end | ||
|
||
let(:path) { "/webhooks/5432/trigger/1234/logs" } | ||
|
||
subject { get path; last_response } | ||
|
||
it "returns the concatenated webhook execution logs" do | ||
expect(subject.body).to eq "foo\nbar" | ||
end | ||
end | ||
end | ||
end | ||
end |