Add validation for length of object_event_types
This commit is contained in:
parent
ff8420541e
commit
7f9e643915
2 changed files with 16 additions and 1 deletions
|
@ -12,7 +12,7 @@ class ObjectEventHookConfig < ApplicationRecord
|
||||||
|
|
||||||
validates :webhook_service, presence: true
|
validates :webhook_service, presence: true
|
||||||
validates :configuration, presence: true
|
validates :configuration, presence: true
|
||||||
validates :object_event_types, presence: true
|
validates :object_event_types, presence: true, length: {minimum: 1}
|
||||||
|
|
||||||
def webhook
|
def webhook
|
||||||
Houdini::WebhookAdapter.build(webhook_service, configuration.symbolize_keys)
|
Houdini::WebhookAdapter.build(webhook_service, configuration.symbolize_keys)
|
||||||
|
|
|
@ -8,6 +8,21 @@ RSpec.describe ObjectEventHookConfig, type: :model do
|
||||||
let(:nonprofit) { create(:nm_justice) }
|
let(:nonprofit) { create(:nm_justice) }
|
||||||
let(:open_fn_config) { create(:open_fn_config, nonprofit_id: nonprofit.id) }
|
let(:open_fn_config) { create(:open_fn_config, nonprofit_id: nonprofit.id) }
|
||||||
|
|
||||||
|
describe 'validation' do
|
||||||
|
subject{ oehc = ObjectEventHookConfig.new(object_event_types:[]); oehc.validate; oehc}
|
||||||
|
|
||||||
|
it 'has an error for webhook_service missing' do
|
||||||
|
expect(subject.errors[:webhook_service]).to_not be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has an error for configuraiton missing' do
|
||||||
|
expect(subject.errors[:configuration]).to_not be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has an error for configuraition empty' do
|
||||||
|
expect(subject.errors[:object_event_types]).to_not be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
describe '.webhook' do
|
describe '.webhook' do
|
||||||
it 'returns an instance of OpenFn webhook' do
|
it 'returns an instance of OpenFn webhook' do
|
||||||
webhook = double
|
webhook = double
|
||||||
|
|
Loading…
Reference in a new issue