dry_running_spec.rb 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/cantino/huginn'}).
  19. to_return(:status => 200, :body => File.read(Rails.root.join("spec/data_fixtures/xkcd.html")), :headers => {})
  20. end
  21. it 'shows the dry run pop up without previous events and selects the events tab when a event was created' do
  22. open_dry_run_modal(agent)
  23. click_on("Dry Run")
  24. expect(page).to have_text('Biologists play reverse')
  25. expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
  26. end
  27. it 'shows the dry run pop up with previous events and allows use previously received event' do
  28. emitter.events << Event.new(payload: {url: "http://xkcd.com/"})
  29. agent.sources << emitter
  30. agent.options.merge!('url' => '', 'url_from_event' => '{{url}}')
  31. agent.save!
  32. open_dry_run_modal(agent)
  33. find('.dry-run-event-sample').click
  34. within(:css, '.modal .builder') do
  35. expect(page).to have_text('http://xkcd.com/')
  36. end
  37. click_on("Dry Run")
  38. expect(page).to have_text('Biologists play reverse')
  39. expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
  40. end
  41. it 'sends escape characters correctly to the backend' do
  42. emitter.events << Event.new(payload: {data: "Line 1\nLine 2\nLine 3"})
  43. formatting_agent.sources << emitter
  44. formatting_agent.options.merge!('instructions' => {'data' => "{{data | newline_to_br | strip_newlines | split: '<br />' | join: ','}}"})
  45. formatting_agent.save!
  46. open_dry_run_modal(formatting_agent)
  47. find('.dry-run-event-sample').click
  48. within(:css, '.modal .builder') do
  49. expect(page).to have_text('Line 1\nLine 2\nLine 3')
  50. end
  51. click_on("Dry Run")
  52. expect(page).to have_text('Line 1,Line 2,Line 3')
  53. expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabEvents"]')
  54. end
  55. end
  56. it 'shows the dry run pop up without previous events and selects the log tab when no event was created' do
  57. stub_request(:get, "http://xkcd.com/").
  58. with(:headers => {'Accept-Encoding'=>'gzip,deflate', 'User-Agent'=>'Huginn - https://github.com/cantino/huginn'}).
  59. to_return(:status => 200, :body => "", :headers => {})
  60. open_dry_run_modal(agent)
  61. click_on("Dry Run")
  62. expect(page).to have_text('Dry Run started')
  63. expect(page).to have_selector(:css, 'li[role="presentation"].active a[href="#tabLog"]')
  64. end
  65. end