freshdesk_spec.rb 4.2 KB

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