1
0

dry_running_spec.rb 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. require 'rails_helper'
  2. describe "Dry running an Agent", js: true do
  3. let(:agent) { agents(:bob_website_agent) }
  4. let(:formatting_agent) { agents(:bob_formatting_agent) }
  5. let(:user) { users(:bob) }
  6. let(:emitter) { agents(:bob_weather_agent) }
  7. before(:each) do
  8. login_as(user)
  9. end
  10. def open_dry_run_modal(agent)
  11. visit edit_agent_path(agent)
  12. click_on("Dry Run")
  13. expect(page).to have_text('Event to send')
  14. end
  15. context 'successful dry runs' do
  16. before do
  17. stub_request(:get, "http://xkcd.com/").
  18. with(:headers => {'Accept-Encoding'=>'gzip,deflate', 'User-Agent'=>'Huginn - https://github.com/huginn/huginn'}).
  19. to_return(:status => 200, :body => File.read(Rails.root.join("spec/data_fixtures/xkcd.html")), :headers => {})
  20. end
  21. it 'opens the dry run modal even when clicking on the refresh icon' do
  22. visit edit_agent_path(agent)
  23. find('.agent-dry-run-button span.glyphicon').click
  24. expect(page).to have_text('Event to send (Optional)')
  25. end
  26. it 'shows the dry run pop up without previous events and selects the events tab when a event was created' do
  27. open_dry_run_modal(agent)
  28. click_on("Dry Run")
  29. expect(page).to have_text('Biologists play reverse')
  30. expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
  31. end
  32. it 'shows the dry run pop up with previous events and allows use previously received event' do
  33. emitter.events << Event.new(payload: {url: "http://xkcd.com/"})
  34. agent.sources << emitter
  35. agent.options.merge!('url' => '', 'url_from_event' => '{{url}}')
  36. agent.save!
  37. open_dry_run_modal(agent)
  38. find('.dry-run-event-sample').click
  39. within(:css, '.modal .builder') do
  40. expect(page).to have_text('http://xkcd.com/')
  41. end
  42. click_on("Dry Run")
  43. expect(page).to have_text('Biologists play reverse')
  44. expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
  45. end
  46. it 'sends escape characters correctly to the backend' do
  47. emitter.events << Event.new(payload: {data: "Line 1\nLine 2\nLine 3"})
  48. formatting_agent.sources << emitter
  49. formatting_agent.options.merge!('instructions' => {'data' => "{{data | newline_to_br | strip_newlines | split: '<br />' | join: ','}}"})
  50. formatting_agent.save!
  51. open_dry_run_modal(formatting_agent)
  52. find('.dry-run-event-sample').click
  53. within(:css, '.modal .builder') do
  54. expect(page).to have_text('Line 1\nLine 2\nLine 3')
  55. end
  56. click_on("Dry Run")
  57. expect(page).to have_text('Line 1,Line 2,Line 3')
  58. expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
  59. end
  60. end
  61. it 'shows the dry run pop up without previous events and selects the log tab when no event was created' do
  62. stub_request(:get, "http://xkcd.com/").
  63. with(:headers => {'Accept-Encoding'=>'gzip,deflate', 'User-Agent'=>'Huginn - https://github.com/huginn/huginn'}).
  64. to_return(:status => 200, :body => "", :headers => {})
  65. open_dry_run_modal(agent)
  66. click_on("Dry Run")
  67. expect(page).to have_text('Dry Run started')
  68. expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabLog"]')
  69. end
  70. end