zendesk_spec.rb 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Import from Zendesk', authenticated_as: false, required_envs: %w[IMPORT_ZENDESK_ENDPOINT IMPORT_ZENDESK_ENDPOINT_KEY IMPORT_ZENDESK_ENDPOINT_USERNAME], set_up: false, type: :system do
  4. import_zendesk_url = ENV['IMPORT_ZENDESK_ENDPOINT'].remove(%r{/api/v2/?})
  5. describe 'fields validation', :use_vcr do
  6. before do
  7. visit '#import'
  8. find('.js-zendesk').click
  9. end
  10. let(:url_field) { find_by_id('zendesk-url') }
  11. let(:email_field) { find_by_id('zendesk-email') }
  12. let(:token_field) { find_by_id('zendesk-api-token') }
  13. it 'invalid hostname' do
  14. url_field.fill_in with: 'https://reallybadexample.zendesk.com/'
  15. expect(page).to have_css('.zendesk-url-error', text: 'The hostname could not be found.')
  16. end
  17. it 'valid hostname' do
  18. url_field.fill_in with: 'https://reallybadexample.zendesk.com/'
  19. # wait for error to appear to validate it's hidden successfully
  20. find('.zendesk-url-error', text: 'The hostname could not be found.')
  21. url_field.fill_in with: import_zendesk_url
  22. expect(page).to have_no_css('.zendesk-url-error', text: 'The hostname could not be found.')
  23. end
  24. it 'invalid credentials' do
  25. url_field.fill_in with: import_zendesk_url
  26. find('.js-zendesk-credentials').click
  27. email_field.fill_in with: ENV['IMPORT_ZENDESK_ENDPOINT_USERNAME']
  28. token_field.fill_in with: '1nv4l1dT0K3N'
  29. expect(page).to have_css('.zendesk-api-token-error', text: 'The provided credentials are invalid.')
  30. end
  31. it 'valid credentials' do
  32. url_field.fill_in with: import_zendesk_url
  33. find('.js-zendesk-credentials').click
  34. email_field.fill_in with: ENV['IMPORT_ZENDESK_ENDPOINT_USERNAME']
  35. token_field.fill_in with: '1nv4l1dT0K3N'
  36. # wait for error to appear to validate it's hidden successfully
  37. expect(page).to have_css('.zendesk-api-token-error', text: 'The provided credentials are invalid.')
  38. token_field.fill_in with: ENV['IMPORT_ZENDESK_ENDPOINT_KEY']
  39. expect(page).to have_no_css('.zendesk-api-token-error', text: 'The provided credentials are invalid.')
  40. end
  41. it 'shows start button' do
  42. url_field.fill_in with: import_zendesk_url
  43. find('.js-zendesk-credentials').click
  44. email_field.fill_in with: ENV['IMPORT_ZENDESK_ENDPOINT_USERNAME']
  45. token_field.fill_in with: ENV['IMPORT_ZENDESK_ENDPOINT_KEY']
  46. expect(page).to have_css('.js-migration-start')
  47. end
  48. end
  49. describe 'import progress', :use_vcr do
  50. let(:url_field) { find_by_id('zendesk-url') }
  51. let(:email_field) { find_by_id('zendesk-email') }
  52. let(:token_field) { find_by_id('zendesk-api-token') }
  53. let(:job) { ImportJob.find_by(name: 'Import::Zendesk') }
  54. before do
  55. VCR.use_cassette 'system/import/zendesk/import_progress_setup' do
  56. visit '#import'
  57. find('.js-zendesk').click
  58. url_field.fill_in with: import_zendesk_url
  59. find('.js-zendesk-credentials').click
  60. email_field.fill_in with: ENV['IMPORT_ZENDESK_ENDPOINT_USERNAME']
  61. token_field.fill_in with: ENV['IMPORT_ZENDESK_ENDPOINT_KEY']
  62. find('.js-migration-start').click
  63. await_empty_ajax_queue
  64. end
  65. end
  66. it 'shows groups progress' do
  67. job.update! result: { Groups: { sum: 3, total: 5 } }
  68. expect(page).to have_css('.js-groups .js-done', text: '3')
  69. .and(have_css('.js-groups .js-total', text: '5'))
  70. end
  71. it 'shows users progress' do
  72. job.update! result: { Users: { sum: 5, total: 9 } }
  73. expect(page).to have_css('.js-users .js-done', text: '5')
  74. .and(have_css('.js-users .js-total', text: '9'))
  75. end
  76. it 'shows organizations progress' do
  77. job.update! result: { Organizations: { sum: 3, total: 5 } }
  78. expect(page).to have_css('.js-organizations .js-done', text: '3')
  79. .and(have_css('.js-organizations .js-total', text: '5'))
  80. end
  81. it 'shows tickets progress' do
  82. job.update! result: { Tickets: { sum: 3, total: 5 } }
  83. expect(page).to have_css('.js-tickets .js-done', text: '3')
  84. .and(have_css('.js-tickets .js-total', text: '5'))
  85. end
  86. it 'shows login after import is finished' do
  87. job.update! finished_at: Time.zone.now
  88. Rake::Task['zammad:setup:auto_wizard'].execute
  89. expect(page).to have_text(Setting.get('fqdn'))
  90. # Check that the login is working and also the left navigation side bar is visible.
  91. login(
  92. username: 'admin@example.com',
  93. password: 'test',
  94. )
  95. end
  96. end
  97. end