scenario_import_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. require 'rails_helper'
  2. describe ScenarioImportsController do
  3. let(:user) { users(:bob) }
  4. before do
  5. login_as(user)
  6. end
  7. it 'renders the import form' do
  8. visit new_scenario_imports_path
  9. expect(page).to have_text('Import a Public Scenario')
  10. end
  11. it 'requires a URL or file uplaod' do
  12. visit new_scenario_imports_path
  13. click_on 'Start Import'
  14. expect(page).to have_text('Please provide either a Scenario JSON File or a Public Scenario URL.')
  15. end
  16. it 'imports a scenario that does not exist yet' do
  17. visit new_scenario_imports_path
  18. attach_file('Option 2: Upload a Scenario JSON File', File.join(Rails.root, 'data/default_scenario.json'))
  19. click_on 'Start Import'
  20. expect(page).to have_text('This scenario has a few agents to get you started. Feel free to change them or delete them as you see fit!')
  21. expect(page).not_to have_text('This Scenario already exists in your system.')
  22. check('I confirm that I want to import these Agents.')
  23. click_on 'Finish Import'
  24. expect(page).to have_text('Import successful!')
  25. end
  26. it 'asks to accept conflicts when the scenario was modified' do
  27. DefaultScenarioImporter.seed(user)
  28. agent = user.agents.where(name: 'Rain Notifier').first
  29. agent.options['expected_receive_period_in_days'] = 9001
  30. agent.save!
  31. visit new_scenario_imports_path
  32. attach_file('Option 2: Upload a Scenario JSON File', File.join(Rails.root, 'data/default_scenario.json'))
  33. click_on 'Start Import'
  34. expect(page).to have_text('This Scenario already exists in your system.')
  35. expect(page).to have_text('9001')
  36. check('I confirm that I want to import these Agents.')
  37. click_on 'Finish Import'
  38. expect(page).to have_text('Import successful!')
  39. end
  40. it 'imports a scenario which requires a service' do
  41. visit new_scenario_imports_path
  42. attach_file('Option 2: Upload a Scenario JSON File', File.join(Rails.root, 'spec/data_fixtures/twitter_scenario.json'))
  43. click_on 'Start Import'
  44. check('I confirm that I want to import these Agents.')
  45. expect { click_on 'Finish Import' }.to change(Scenario, :count).by(1)
  46. expect(page).to have_text('Import successful!')
  47. end
  48. end