|
@@ -1,6 +1,10 @@
|
|
require 'rails_helper'
|
|
require 'rails_helper'
|
|
|
|
|
|
describe Agents::CommanderAgent do
|
|
describe Agents::CommanderAgent do
|
|
|
|
+ let(:target) {
|
|
|
|
+ agents(:bob_website_agent)
|
|
|
|
+ }
|
|
|
|
+
|
|
let(:valid_params) {
|
|
let(:valid_params) {
|
|
{
|
|
{
|
|
name: 'Example',
|
|
name: 'Example',
|
|
@@ -8,27 +12,27 @@ describe Agents::CommanderAgent do
|
|
options: {
|
|
options: {
|
|
'action' => 'run',
|
|
'action' => 'run',
|
|
},
|
|
},
|
|
|
|
+ user: users(:bob),
|
|
|
|
+ control_targets: [target]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
let(:agent) {
|
|
let(:agent) {
|
|
- described_class.create!(valid_params) { |agent|
|
|
|
|
- agent.user = users(:bob)
|
|
|
|
- }
|
|
|
|
|
|
+ described_class.create!(valid_params)
|
|
}
|
|
}
|
|
|
|
|
|
it_behaves_like AgentControllerConcern
|
|
it_behaves_like AgentControllerConcern
|
|
|
|
|
|
describe "check" do
|
|
describe "check" do
|
|
it "should command targets" do
|
|
it "should command targets" do
|
|
- stub(agent).control!.once { nil }
|
|
|
|
|
|
+ stub(Agent).async_check(target.id).once { nil }
|
|
agent.check
|
|
agent.check
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
describe "receive_events" do
|
|
describe "receive_events" do
|
|
it "should command targets" do
|
|
it "should command targets" do
|
|
- stub(agent).control!.once { nil }
|
|
|
|
|
|
+ stub(Agent).async_check(target.id).once { nil }
|
|
|
|
|
|
event = Event.new
|
|
event = Event.new
|
|
event.agent = agents(:bob_rain_notifier_agent)
|
|
event.agent = agents(:bob_rain_notifier_agent)
|
|
@@ -38,5 +42,62 @@ describe Agents::CommanderAgent do
|
|
}
|
|
}
|
|
agent.receive([event])
|
|
agent.receive([event])
|
|
end
|
|
end
|
|
|
|
+
|
|
|
|
+ context "to configure" do
|
|
|
|
+ let(:real_target) {
|
|
|
|
+ Agents::TriggerAgent.create!(
|
|
|
|
+ name: "somename",
|
|
|
|
+ options: {
|
|
|
|
+ expected_receive_period_in_days: 2,
|
|
|
|
+ rules: [
|
|
|
|
+ {
|
|
|
|
+ 'type' => 'field<value',
|
|
|
|
+ 'value' => '200.0',
|
|
|
|
+ 'path' => 'price',
|
|
|
|
+ }
|
|
|
|
+ ],
|
|
|
|
+ keep_event: 'true'
|
|
|
|
+ },
|
|
|
|
+ user: users(:bob)
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let(:valid_params) {
|
|
|
|
+ {
|
|
|
|
+ name: 'Example',
|
|
|
|
+ schedule: 'never',
|
|
|
|
+ options: {
|
|
|
|
+ 'action' => '{% if target.id == agent_id %}configure{% endif %}',
|
|
|
|
+ 'configure_options' => {
|
|
|
|
+ 'rules' => [
|
|
|
|
+ {
|
|
|
|
+ 'type' => 'field<value',
|
|
|
|
+ 'value' => "{{price}}",
|
|
|
|
+ 'path' => 'price',
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ user: users(:bob),
|
|
|
|
+ control_targets: [target, real_target]
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ it "should conditionally configure targets interpolating agent attributes" do
|
|
|
|
+ expect {
|
|
|
|
+ event = Event.new
|
|
|
|
+ event.agent = agents(:bob_website_agent)
|
|
|
|
+ event.payload = {
|
|
|
|
+ 'price' => '198.0',
|
|
|
|
+ 'agent_id' => real_target.id
|
|
|
|
+ }
|
|
|
|
+ agent.receive([event])
|
|
|
|
+ }.to change {
|
|
|
|
+ real_target.options['rules'][0]['value']
|
|
|
|
+ }.from('200.0').to('198.0') & not_change {
|
|
|
|
+ target.options
|
|
|
|
+ }
|
|
|
|
+ end
|
|
|
|
+ end
|
|
end
|
|
end
|
|
end
|
|
end
|