idoit_spec.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket Handling with i-doit', integration: true, required_envs: %w[IDOIT_API_TOKEN IDOIT_API_ENDPOINT IDOIT_API_CATEGORY], type: :system do
  4. let(:api_endpoint) { ENV['IDOIT_API_ENDPOINT'] }
  5. let(:api_category) { ENV['IDOIT_API_CATEGORY'] }
  6. before do
  7. Setting.set('idoit_integration', true)
  8. Setting.set('idoit_config', { api_token: ENV['IDOIT_API_TOKEN'], endpoint: api_endpoint, client_id: '' })
  9. end
  10. def open_idoit_sidebar
  11. find('.tabsSidebar svg.icon-printer').click
  12. end
  13. def select_entry_in_sidebar
  14. find('.sidebar[data-tab="idoit"] .js-headline').click
  15. find('.sidebar[data-tab="idoit"] .dropdown-menu').click
  16. entry_id = nil
  17. in_modal do
  18. find('form input.js-input').click
  19. find("form li.js-option[data-display-name='#{api_category}']").click
  20. entry_id = find('form.js-result tbody tr:first-child input').tap(&:click).value
  21. # submit the i-doit object selections
  22. find('form button.js-submit').click
  23. end
  24. entry_id
  25. end
  26. context 'when using the i-doit integration' do
  27. let(:agent) { create(:agent, groups: [Group.find_by(name: 'Users')]) }
  28. before do
  29. visit 'ticket/create'
  30. find('[name=customer_id_completion]').fill_in with: 'nico'
  31. page.find('li.recipientList-entry.js-object.is-active').click
  32. fill_in 'Title', with: 'subject - i-doit integration'
  33. set_editor_field_value('body', 'body - i-doit integration')
  34. end
  35. it 'does process i-doit information correctly', authenticated_as: :agent do
  36. within :active_content do
  37. # Select an item initially.
  38. open_idoit_sidebar
  39. entry_id = select_entry_in_sidebar
  40. item_link = ".sidebar[data-tab='idoit'] a[href='#{api_endpoint}/?objID=#{entry_id}']"
  41. expect(page).to have_css(item_link)
  42. # Reselect the customer and verify if object is still shown in sidebar.
  43. find('[name=customer_id_completion]').fill_in with: 'admin'
  44. page.find('li.recipientList-entry.js-object.is-active').click
  45. expect(page).to have_css(item_link)
  46. # Submit the ticket.
  47. find('.newTicket button.js-submit').click
  48. open_idoit_sidebar
  49. expect(page).to have_css(item_link)
  50. # Check it's still there after reload.
  51. page.refresh
  52. open_idoit_sidebar
  53. expect(page).to have_css(item_link)
  54. # Delete the item.
  55. find(".sidebar[data-tab='idoit'] .js-delete[data-object-id=\"#{entry_id}\"]").click
  56. expect(find(".sidebar[data-tab='idoit']")).to have_text('none')
  57. # Check if the item is still gone after reload.
  58. page.refresh
  59. open_idoit_sidebar
  60. expect(find(".sidebar[data-tab='idoit']")).to have_text('none')
  61. end
  62. end
  63. end
  64. end