Add validation for length of object_event_types

This commit is contained in:
Eric Schultz 2021-02-18 14:32:42 -06:00 committed by Eric Schultz
parent ff8420541e
commit 7f9e643915
2 changed files with 16 additions and 1 deletions

View file

@ -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)

View file

@ -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