Skip to content

Commit ce452ec

Browse files
committed
feat(webhooks): add enabled column to model and database schema
1 parent 9f635c3 commit ce452ec

File tree

7 files changed

+30
-2
lines changed

7 files changed

+30
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Sequel.migration do
2+
change do
3+
add_column(:webhooks, :enabled, TrueClass, default: true)
4+
end
5+
end

lib/pact_broker/api/decorators/webhook_decorator.rb

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class WebhookEventDecorator < BaseDecorator
2424
property :name
2525
end
2626

27+
property :enabled, default: true
28+
2729
property :request, :class => PactBroker::Webhooks::WebhookRequestTemplate, extend: WebhookRequestTemplateDecorator
2830
collection :events, :class => PactBroker::Webhooks::WebhookEvent, extend: WebhookEventDecorator
2931

lib/pact_broker/domain/webhook.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Webhook
1010
include Messages
1111
include Logging
1212

13-
attr_accessor :uuid, :consumer, :provider, :request, :created_at, :updated_at, :events
13+
attr_accessor :uuid, :consumer, :provider, :request, :created_at, :updated_at, :events, :enabled
1414
attr_reader :attributes
1515

1616
def initialize attributes = {}
@@ -20,6 +20,7 @@ def initialize attributes = {}
2020
@consumer = attributes[:consumer]
2121
@provider = attributes[:provider]
2222
@events = attributes[:events]
23+
@enabled = attributes[:enabled]
2324
@created_at = attributes[:created_at]
2425
@updated_at = attributes[:updated_at]
2526
end

lib/pact_broker/webhooks/webhook.rb

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def to_domain
4646
provider: provider,
4747
events: events,
4848
request: Webhooks::WebhookRequestTemplate.new(request_attributes),
49+
enabled: enabled,
4950
created_at: created_at,
5051
updated_at: updated_at)
5152
end
@@ -85,6 +86,7 @@ def self.properties_hash_from_domain webhook
8586
url: webhook.request.url,
8687
username: webhook.request.username,
8788
password: not_plain_text_password(webhook.request.password),
89+
enabled: webhook.enabled,
8890
body: (is_json_request_body ? webhook.request.body.to_json : webhook.request.body),
8991
is_json_request_body: is_json_request_body
9092
}

spec/features/create_webhook_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
let(:webhook_json) { webhook_hash.to_json }
1212
let(:webhook_hash) do
1313
{
14+
enabled: false,
1415
events: [{
1516
name: 'something_happened'
1617
}],

spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ def valid_webhook_with
298298
expect(subject.errors[:"request.url"]).to eq ["cannot have a template parameter in the host"]
299299
end
300300
end
301+
302+
context "when enabled is not a boolean", pending: "I can't work out why this doesn't work" do
303+
let(:json) do
304+
valid_webhook_with do |hash|
305+
hash['enabled'] = 'foo'
306+
end
307+
end
308+
309+
it "contains an error" do
310+
expect(subject.errors[:enabled]).to eq ["cannot have a template parameter in the host"]
311+
end
312+
end
301313
end
302314
end
303315
end

spec/lib/pact_broker/api/decorators/webhook_decorator_spec.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ module Decorators
3333
provider: provider,
3434
events: [event],
3535
created_at: created_at,
36-
updated_at: updated_at
36+
updated_at: updated_at,
37+
enabled: false
3738
)
3839
end
3940

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

94+
it 'includes the enabled flag' do
95+
expect(parsed_json[:enabled]).to eq false
96+
end
97+
9398
context 'when the headers are empty' do
9499
let(:headers) { nil }
95100
it 'does not include the headers' do

0 commit comments

Comments
 (0)