external_data_source_attribute_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket > Update > External Data Source Attribute', db_adapter: :postgresql, db_strategy: :reset, searchindex: true, type: :system do
  4. let(:search_url) { "#{Setting.get('es_url')}/#{Setting.get('es_index')}_test_user/_search?q=\#{search.term}" }
  5. let(:external_data_source_attribute) do
  6. create(:object_manager_attribute_autocompletion_ajax_external_data_source, :shown_screen, :elastic_search, search_url: search_url, name: 'external_data_source_attribute')
  7. end
  8. let(:group) { Group.find_by(name: 'Users') }
  9. let(:ticket) { create(:ticket, group: group, customer: customer1) }
  10. let(:customer1) { create(:customer, firstname: SecureRandom.uuid) }
  11. let(:customer2) { create(:customer, firstname: searchterm) }
  12. let(:searchterm) { SecureRandom.uuid }
  13. before do
  14. customer1
  15. customer2
  16. searchindex_model_reload([User])
  17. external_data_source_attribute
  18. ObjectManager::Attribute.migration_execute
  19. visit "ticket/zoom/#{ticket.id}"
  20. end
  21. context 'when external data source attribute is used' do
  22. it 'search and select value' do
  23. set_external_data_source_value('external_data_source_attribute', searchterm, customer2.email)
  24. click('.js-attributeBar .js-submit')
  25. expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]')
  26. expect(ticket.reload.external_data_source_attribute).to eq({ 'value' => customer2.id.to_s, 'label' => customer2.email })
  27. end
  28. context 'when search template variables are used' do
  29. let(:search_url) { "#{Setting.get('es_url')}/#{Setting.get('es_index')}_test_user/_search?q=\"\#{ticket.customer.email}\"" }
  30. it 'search only with wildcard' do
  31. set_external_data_source_value('external_data_source_attribute', '*', customer1.firstname)
  32. click('.js-attributeBar .js-submit')
  33. expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]')
  34. expect(ticket.reload.external_data_source_attribute).to eq({ 'value' => customer1.id.to_s, 'label' => customer1.email })
  35. end
  36. end
  37. end
  38. end