diff --git a/lib/pact_broker/api/contracts/webhook_contract.rb b/lib/pact_broker/api/contracts/webhook_contract.rb index e8357ea53..5b0903b7b 100644 --- a/lib/pact_broker/api/contracts/webhook_contract.rb +++ b/lib/pact_broker/api/contracts/webhook_contract.rb @@ -2,6 +2,7 @@ require 'pact_broker/webhooks/check_host_whitelist' require 'pact_broker/webhooks/render' require 'pact_broker/pacticipants/service' +require 'pact_broker/webhooks/webhook_event' module PactBroker module Api @@ -46,7 +47,6 @@ def pacticipant_exists?(name) required(:name).filled(:pacticipant_exists?) end - end property :provider do @@ -155,7 +155,7 @@ def parse_uri(uri_string, placeholder = 'placeholder') property :name validation do - required(:name).filled + required(:name).filled(included_in?: PactBroker::Webhooks::WebhookEvent::EVENT_NAMES) end end end diff --git a/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb b/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb index 6be4dc993..fdc60eb9f 100644 --- a/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb +++ b/spec/lib/pact_broker/api/contracts/webhook_contract_spec.rb @@ -159,6 +159,18 @@ def valid_webhook_with end end + context "with an event with an invalid name" do + let(:json) do + valid_webhook_with do |hash| + hash['events'].first['name'] = 'foo' + end + end + + it "contains an error" do + expect(subject.errors[:'events.name'].first).to include "must be one of" + end + end + context "with no method" do let(:json) do valid_webhook_with do |hash|