mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Merge pull request #2070 from chrishein/event_formatting_agent_fix
Add validations for `mode` values in EventFormattingAgent
This commit is contained in:
commit
4cf58ebbd3
2 changed files with 31 additions and 1 deletions
|
@ -84,7 +84,7 @@ module Agents
|
|||
event_description do
|
||||
"Events will have the following fields%s:\n\n %s" % [
|
||||
case options['mode'].to_s
|
||||
when 'merged'
|
||||
when 'merge'
|
||||
', merged with the original contents'
|
||||
when /\{/
|
||||
', conditionally merged with the original contents'
|
||||
|
@ -98,6 +98,10 @@ module Agents
|
|||
def validate_options
|
||||
errors.add(:base, "instructions and mode need to be present.") unless options['instructions'].present? && options['mode'].present?
|
||||
|
||||
if options['mode'].present? && !options['mode'].to_s.include?('{{') && !%[clean merge].include?(options['mode'].to_s)
|
||||
errors.add(:base, "mode must be 'clean' or 'merge'")
|
||||
end
|
||||
|
||||
validate_matchers
|
||||
end
|
||||
|
||||
|
|
|
@ -74,6 +74,12 @@ describe Agents::EventFormattingAgent do
|
|||
expect(Event.last.payload[:content]).not_to eq(nil)
|
||||
end
|
||||
|
||||
it "should handle Liquid templating in mode" do
|
||||
@checker.options[:mode] = "{{'merge'}}"
|
||||
@checker.receive([@event])
|
||||
expect(Event.last.payload[:content]).not_to eq(nil)
|
||||
end
|
||||
|
||||
it "should handle Liquid templating in instructions" do
|
||||
@checker.receive([@event])
|
||||
expect(Event.last.payload[:message]).to eq("Received Some Lorem Ipsum from somevalue .")
|
||||
|
@ -182,5 +188,25 @@ describe Agents::EventFormattingAgent do
|
|||
@checker.options[:mode] = ""
|
||||
expect(@checker).not_to be_valid
|
||||
end
|
||||
|
||||
it "requires mode to be 'clean' or 'merge'" do
|
||||
@checker.options['mode'] = 'what?'
|
||||
expect(@checker).not_to be_valid
|
||||
|
||||
@checker.options['mode'] = 'clean'
|
||||
expect(@checker).to be_valid
|
||||
|
||||
@checker.options['mode'] = 'merge'
|
||||
expect(@checker).to be_valid
|
||||
|
||||
@checker.options['mode'] = :clean
|
||||
expect(@checker).to be_valid
|
||||
|
||||
@checker.options['mode'] = :merge
|
||||
expect(@checker).to be_valid
|
||||
|
||||
@checker.options['mode'] = '{{somekey}}'
|
||||
expect(@checker).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue