-
-
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 application/hal+json content type for webhook logs (#679)
- Loading branch information
Showing
5 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
lib/pact_broker/api/decorators/triggered_webhook_logs_decorator.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,38 @@ | ||
require_relative "base_decorator" | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
class TriggeredWebhookLogsDecorator < BaseDecorator | ||
class WebhookExecutionDecorator < BaseDecorator | ||
property :success | ||
property :logs | ||
property :created_at, as: :createdAt | ||
end | ||
|
||
|
||
nested :triggeredWebhook, embedded: true do | ||
property :uuid | ||
end | ||
|
||
collection :webhook_executions, as: :executions, :class => PactBroker::Webhooks::Execution, :extend => WebhookExecutionDecorator | ||
|
||
link :self do | options | | ||
{ | ||
title: "Triggered webhook logs", | ||
href: options[:resource_url] | ||
} | ||
end | ||
|
||
link :'pb:webhook' do | context | | ||
if represented.webhook | ||
{ | ||
href: webhook_url(represented.webhook.uuid, context[:base_url]), | ||
title: "Webhook" | ||
} | ||
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
24 changes: 24 additions & 0 deletions
24
spec/fixtures/approvals/triggered_webhook_logs_decorator.approved.json
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,24 @@ | ||
{ | ||
"executions": [ | ||
{ | ||
"success": true, | ||
"logs": "foo", | ||
"createdAt": "2024-01-01T00:00:00+00:00" | ||
} | ||
], | ||
"_embedded": { | ||
"triggeredWebhook": { | ||
"uuid": "1234" | ||
} | ||
}, | ||
"_links": { | ||
"self": { | ||
"title": "Triggered webhook logs", | ||
"href": null | ||
}, | ||
"pb:webhook": { | ||
"href": "http://example.org/webhooks/1234", | ||
"title": "Webhook" | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
spec/lib/pact_broker/api/decorators/triggered_webhook_logs_decorator_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,31 @@ | ||
require "pact_broker/api/decorators/triggered_webhook_logs_decorator" | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
describe TriggeredWebhookLogsDecorator do | ||
let(:triggered_webhook) do | ||
double("PactBroker::Webhooks::TriggeredWebhook", | ||
uuid: "1234", | ||
webhook_executions: [webhook_execution], | ||
webhook: webhook | ||
) | ||
end | ||
|
||
let(:webhook) { double("webhook", uuid: "1234") } | ||
|
||
let(:webhook_execution) do | ||
instance_double(PactBroker::Webhooks::Execution, logs: "foo", success: true, created_at: td.in_utc { DateTime.new(2024, 1, 1) } ) | ||
end | ||
|
||
let(:user_options) { { base_url: "http://example.org" } } | ||
|
||
subject { TriggeredWebhookLogsDecorator.new(triggered_webhook).to_json(user_options: user_options) } | ||
|
||
it { | ||
Approvals.verify(subject, :name => "triggered_webhook_logs_decorator", format: :json) | ||
} | ||
end | ||
end | ||
end | ||
end |