kayako_spec.rb 4.7 KB

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