freshdesk_spec.rb 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. require 'rails_helper'
  2. RSpec.describe 'Import Freshdesk', type: :system, set_up: false, authenticated_as: false, required_envs: %w[IMPORT_FRESHDESK_ENDPOINT_SUBDOMAIN IMPORT_FRESHDESK_ENDPOINT_KEY] do
  3. before(:all) do # rubocop:disable RSpec/BeforeAfterAll
  4. VCR.configure do |c|
  5. # The API key is used only inside the base64 encoded Basic Auth string, so mask that as well.
  6. c.filter_sensitive_data('<IMPORT_FRESHDESK_ENDPOINT_BASIC_AUTH>') { Base64.encode64( "#{ENV['IMPORT_FRESHDESK_ENDPOINT_KEY']}:X" ).chomp }
  7. end
  8. end
  9. describe 'fields validation', :use_vcr do
  10. before do
  11. visit '#import'
  12. find('.js-freshdesk').click
  13. end
  14. let(:subdomain_field) { find('#freshdesk-subdomain') }
  15. let(:token_field) { find('#freshdesk-api-token') }
  16. it 'invalid hostname' do
  17. subdomain_field.fill_in with: 'reallybadexample'
  18. expect(page).to have_css('.freshdesk-subdomain-error', text: 'Hostname not found!')
  19. end
  20. it 'valid hostname' do
  21. subdomain_field.fill_in with: 'reallybadexample'
  22. # wait for error to appear to validate it's hidden successfully
  23. find('.freshdesk-subdomain-error', text: 'Hostname not found!')
  24. subdomain_field.fill_in with: ENV['IMPORT_FRESHDESK_ENDPOINT_SUBDOMAIN']
  25. expect(page).to have_no_css('.freshdesk-subdomain-error', text: 'Hostname not found!')
  26. end
  27. it 'invalid credentials' do
  28. subdomain_field.fill_in with: ENV['IMPORT_FRESHDESK_ENDPOINT_SUBDOMAIN']
  29. find('.js-freshdesk-credentials').click
  30. token_field.fill_in with: '1nv4l1dT0K3N'
  31. expect(page).to have_css('.freshdesk-api-token-error', text: 'Invalid credentials!')
  32. end
  33. it 'valid credentials' do
  34. subdomain_field.fill_in with: ENV['IMPORT_FRESHDESK_ENDPOINT_SUBDOMAIN']
  35. find('.js-freshdesk-credentials').click
  36. token_field.fill_in with: '1nv4l1dT0K3N'
  37. # wait for error to appear to validate it's hidden successfully
  38. expect(page).to have_css('.freshdesk-api-token-error', text: 'Invalid credentials!')
  39. token_field.fill_in with: ENV['IMPORT_FRESHDESK_ENDPOINT_KEY']
  40. expect(page).to have_no_css('.freshdesk-api-token-error', text: 'Invalid credentials!')
  41. end
  42. it 'shows start button' do
  43. subdomain_field.fill_in with: ENV['IMPORT_FRESHDESK_ENDPOINT_SUBDOMAIN']
  44. find('.js-freshdesk-credentials').click
  45. token_field.fill_in with: ENV['IMPORT_FRESHDESK_ENDPOINT_KEY']
  46. expect(page).to have_css('.js-migration-start')
  47. end
  48. end
  49. describe 'import progress', :use_vcr do
  50. let(:subdomain_field) { find('#freshdesk-subdomain') }
  51. let(:token_field) { find('#freshdesk-api-token') }
  52. let(:job) { ImportJob.find_by(name: 'Import::Freshdesk') }
  53. before do
  54. VCR.use_cassette 'system/import/freshdesk/import_progress_setup' do
  55. visit '#import'
  56. find('.js-freshdesk').click
  57. subdomain_field.fill_in with: ENV['IMPORT_FRESHDESK_ENDPOINT_SUBDOMAIN']
  58. find('.js-freshdesk-credentials').click
  59. token_field.fill_in with: ENV['IMPORT_FRESHDESK_ENDPOINT_KEY']
  60. find('.js-migration-start').click
  61. await_empty_ajax_queue
  62. end
  63. end
  64. it 'shows groups progress' do
  65. job.update! result: { Groups: { sum: 3, total: 5 } }
  66. expect(page).to have_css('.js-groups .js-done', text: '3')
  67. .and(have_css('.js-groups .js-total', text: '5'))
  68. end
  69. it 'shows users progress' do
  70. job.update! result: { Users: { sum: 5, total: 9 } }
  71. expect(page).to have_css('.js-users .js-done', text: '5')
  72. .and(have_css('.js-users .js-total', text: '9'))
  73. end
  74. it 'shows organizations progress' do
  75. job.update! result: { Organizations: { sum: 3, total: 5 } }
  76. expect(page).to have_css('.js-organizations .js-done', text: '3')
  77. .and(have_css('.js-organizations .js-total', text: '5'))
  78. end
  79. it 'shows tickets progress' do
  80. job.update! result: { Tickets: { sum: 3, total: 5 } }
  81. expect(page).to have_css('.js-tickets .js-done', text: '3')
  82. .and(have_css('.js-tickets .js-total', text: '5'))
  83. end
  84. it 'shows login after import is finished' do
  85. job.update! finished_at: Time.zone.now
  86. Rake::Task['zammad:setup:auto_wizard'].execute
  87. expect(page).to have_text('Login')
  88. end
  89. end
  90. end