Skip to content

Commit

Permalink
feat(webhooks): add enabled column to model and database schema
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 23, 2019
1 parent 9f635c3 commit ce452ec
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions db/migrations/20190523_add_enabled_column_to_webhooks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Sequel.migration do
change do
add_column(:webhooks, :enabled, TrueClass, default: true)
end
end
2 changes: 2 additions & 0 deletions lib/pact_broker/api/decorators/webhook_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class WebhookEventDecorator < BaseDecorator
property :name
end

property :enabled, default: true

property :request, :class => PactBroker::Webhooks::WebhookRequestTemplate, extend: WebhookRequestTemplateDecorator
collection :events, :class => PactBroker::Webhooks::WebhookEvent, extend: WebhookEventDecorator

Expand Down
3 changes: 2 additions & 1 deletion lib/pact_broker/domain/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Webhook
include Messages
include Logging

attr_accessor :uuid, :consumer, :provider, :request, :created_at, :updated_at, :events
attr_accessor :uuid, :consumer, :provider, :request, :created_at, :updated_at, :events, :enabled
attr_reader :attributes

def initialize attributes = {}
Expand All @@ -20,6 +20,7 @@ def initialize attributes = {}
@consumer = attributes[:consumer]
@provider = attributes[:provider]
@events = attributes[:events]
@enabled = attributes[:enabled]
@created_at = attributes[:created_at]
@updated_at = attributes[:updated_at]
end
Expand Down
2 changes: 2 additions & 0 deletions lib/pact_broker/webhooks/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def to_domain
provider: provider,
events: events,
request: Webhooks::WebhookRequestTemplate.new(request_attributes),
enabled: enabled,
created_at: created_at,
updated_at: updated_at)
end
Expand Down Expand Up @@ -85,6 +86,7 @@ def self.properties_hash_from_domain webhook
url: webhook.request.url,
username: webhook.request.username,
password: not_plain_text_password(webhook.request.password),
enabled: webhook.enabled,
body: (is_json_request_body ? webhook.request.body.to_json : webhook.request.body),
is_json_request_body: is_json_request_body
}
Expand Down
1 change: 1 addition & 0 deletions spec/features/create_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
let(:webhook_json) { webhook_hash.to_json }
let(:webhook_hash) do
{
enabled: false,
events: [{
name: 'something_happened'
}],
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ def valid_webhook_with
expect(subject.errors[:"request.url"]).to eq ["cannot have a template parameter in the host"]
end
end

context "when enabled is not a boolean", pending: "I can't work out why this doesn't work" do
let(:json) do
valid_webhook_with do |hash|
hash['enabled'] = 'foo'
end
end

it "contains an error" do
expect(subject.errors[:enabled]).to eq ["cannot have a template parameter in the host"]
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module Decorators
provider: provider,
events: [event],
created_at: created_at,
updated_at: updated_at
updated_at: updated_at,
enabled: false
)
end

Expand Down Expand Up @@ -90,6 +91,10 @@ module Decorators
expect(parsed_json[:updatedAt]).to eq FormatDateTime.call(updated_at)
end

it 'includes the enabled flag' do
expect(parsed_json[:enabled]).to eq false
end

context 'when the headers are empty' do
let(:headers) { nil }
it 'does not include the headers' do
Expand Down

0 comments on commit ce452ec

Please sign in to comment.