Przeglądaj źródła

Add specs for creating agents with a source/receiver/control target

Akinori MUSHA 7 lat temu
rodzic
commit
0abc42fb40
1 zmienionych plików z 65 dodań i 0 usunięć
  1. 65 0
      spec/features/create_an_agent_spec.rb

+ 65 - 0
spec/features/create_an_agent_spec.rb

@@ -17,6 +17,71 @@ describe "Creating a new agent", js: true do
     expect(page).to have_text("Test Trigger Agent")
   end
 
+  context "with associated agents" do
+    let!(:bob_scheduler_agent) {
+      Agents::SchedulerAgent.create!(
+        user: users(:bob),
+        name: 'Example Scheduler',
+        options: {
+          'action' => 'run',
+          'schedule' => '0 * * * *'
+        },
+      )
+    }
+
+    let!(:bob_weather_agent) {
+      agents(:bob_weather_agent)
+    }
+
+    let!(:bob_formatting_agent) {
+      agents(:bob_formatting_agent).tap { |agent|
+        # Make this valid
+        agent.options['instructions']['foo'] = 'bar'
+        agent.save!
+      }
+    }
+
+    it "creates an agent with a source and a receiver" do
+      visit "/"
+      page.find("a", text: "Agents").trigger(:mouseover)
+      click_on("New Agent")
+
+      select_agent_type("Trigger Agent")
+      fill_in(:agent_name, with: "Test Trigger Agent")
+
+      select2("SF Weather", from: 'Sources')
+      select2("Formatting Agent", from: 'Receivers')
+
+      click_on "Save"
+
+      expect(page).to have_text("Test Trigger Agent")
+
+      agent = Agent.find_by(name: "Test Trigger Agent")
+
+      expect(agent.sources).to eq([bob_weather_agent])
+      expect(agent.receivers).to eq([bob_formatting_agent])
+    end
+
+    it "creates an agent with a control target" do
+      visit "/"
+      page.find("a", text: "Agents").trigger(:mouseover)
+      click_on("New Agent")
+
+      select_agent_type("Scheduler Agent")
+      fill_in(:agent_name, with: "Test Scheduler Agent")
+
+      select2("SF Weather", from: 'Control targets')
+
+      click_on "Save"
+
+      expect(page).to have_text("Test Scheduler Agent")
+
+      agent = Agent.find_by(name: "Test Scheduler Agent")
+
+      expect(agent.control_targets).to eq([bob_weather_agent])
+    end
+  end
+
   it "creates an alert if a new agent with invalid json is submitted" do
     visit "/"
     page.find("a", text: "Agents").trigger(:mouseover)