|
@@ -8,6 +8,7 @@ describe Agents::EventFormattingAgent do
|
|
|
:instructions => {
|
|
|
:message => "Received {{content.text}} from {{content.name}} .",
|
|
|
:subject => "Weather looks like {{conditions}} according to the forecast at {{pretty_date.time}}",
|
|
|
+ :timezone => "{{timezone}}",
|
|
|
:agent => "{{agent.type}}",
|
|
|
:created_at => "{{created_at}}",
|
|
|
:created_at_iso => "{{created_at | date:'%FT%T%:z'}}",
|
|
@@ -19,6 +20,10 @@ describe Agents::EventFormattingAgent do
|
|
|
:regexp => "\\A(?<time>\\d\\d:\\d\\d [AP]M [A-Z]+)",
|
|
|
:to => "pretty_date",
|
|
|
},
|
|
|
+ {
|
|
|
+ :path => "{{pretty_date.time}}",
|
|
|
+ :regexp => "(?<timezone>[A-Z]+)\\z",
|
|
|
+ },
|
|
|
],
|
|
|
}
|
|
|
}
|
|
@@ -40,6 +45,21 @@ describe Agents::EventFormattingAgent do
|
|
|
},
|
|
|
:conditions => "someothervalue"
|
|
|
}
|
|
|
+
|
|
|
+ @event2 = Event.new
|
|
|
+ @event2.agent = agents(:jane_weather_agent)
|
|
|
+ @event2.created_at = Time.now
|
|
|
+ @event2.payload = {
|
|
|
+ :content => {
|
|
|
+ :text => "Some Lorem Ipsum 2",
|
|
|
+ :name => "somevalue2",
|
|
|
+ },
|
|
|
+ :date => {
|
|
|
+ :epoch => "1366372800",
|
|
|
+ :pretty => "08:00 AM EDT on April 19, 2013"
|
|
|
+ },
|
|
|
+ :conditions => "someothervalue2"
|
|
|
+ }
|
|
|
end
|
|
|
|
|
|
describe "#receive" do
|
|
@@ -63,8 +83,31 @@ describe Agents::EventFormattingAgent do
|
|
|
end
|
|
|
|
|
|
it "should handle matchers and Liquid templating in instructions" do
|
|
|
- @checker.receive([@event])
|
|
|
- expect(Event.last.payload[:subject]).to eq("Weather looks like someothervalue according to the forecast at 10:00 PM EST")
|
|
|
+ expect {
|
|
|
+ @checker.receive([@event, @event2])
|
|
|
+ }.to change { Event.count }.by(2)
|
|
|
+
|
|
|
+ formatted_event1, formatted_event2 = Event.last(2)
|
|
|
+
|
|
|
+ expect(formatted_event1.payload[:subject]).to eq("Weather looks like someothervalue according to the forecast at 10:00 PM EST")
|
|
|
+ expect(formatted_event1.payload[:timezone]).to eq("EST")
|
|
|
+ expect(formatted_event2.payload[:subject]).to eq("Weather looks like someothervalue2 according to the forecast at 08:00 AM EDT")
|
|
|
+ expect(formatted_event2.payload[:timezone]).to eq("EDT")
|
|
|
+ end
|
|
|
+
|
|
|
+ it "should not fail if no matchers are defined" do
|
|
|
+ @checker.options.delete(:matchers)
|
|
|
+
|
|
|
+ expect {
|
|
|
+ @checker.receive([@event, @event2])
|
|
|
+ }.to change { Event.count }.by(2)
|
|
|
+
|
|
|
+ formatted_event1, formatted_event2 = Event.last(2)
|
|
|
+
|
|
|
+ expect(formatted_event1.payload[:subject]).to eq("Weather looks like someothervalue according to the forecast at ")
|
|
|
+ expect(formatted_event1.payload[:timezone]).to eq("")
|
|
|
+ expect(formatted_event2.payload[:subject]).to eq("Weather looks like someothervalue2 according to the forecast at ")
|
|
|
+ expect(formatted_event2.payload[:timezone]).to eq("")
|
|
|
end
|
|
|
|
|
|
it "should allow escaping" do
|