auto_assignment_spec.rb 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket zoom > Auto Assignment', type: :system do
  4. describe 'Core functionality', authenticated_as: :authenticate do
  5. let!(:ticket) { create(:ticket, group: Group.find_by(name: 'Users'), state: Ticket::State.find_by(name: 'new')) }
  6. let!(:session_user) { User.find_by(login: 'admin@example.com') }
  7. context 'when agent disabled' do
  8. def authenticate
  9. Setting.set('ticket_auto_assignment', false)
  10. Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } })
  11. Setting.set('ticket_auto_assignment_user_ids_ignore', [])
  12. true
  13. end
  14. it 'do not assign ticket to current session user' do
  15. visit "#ticket/zoom/#{ticket.id}"
  16. within(:active_content) do
  17. expect(page).to have_css('select[name=owner_id]')
  18. expect(page).to have_select('owner_id',
  19. selected: '-',
  20. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  21. end
  22. end
  23. end
  24. context 'when agent enabled' do
  25. def authenticate
  26. Setting.set('ticket_auto_assignment', true)
  27. Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category(:work_on).pluck(:id) } } })
  28. Setting.set('ticket_auto_assignment_user_ids_ignore', setting_user_ids_ignore) if defined?(setting_user_ids_ignore)
  29. true
  30. end
  31. context 'with empty "ticket_auto_assignment_user_ids_ignore"' do
  32. it 'assigns ticket to current session user' do
  33. visit "#ticket/zoom/#{ticket.id}"
  34. within(:active_content) do
  35. expect(page).to have_css('.content.active select[name=owner_id]')
  36. expect(page).to have_select('owner_id',
  37. selected: session_user.fullname,
  38. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  39. end
  40. end
  41. end
  42. context 'with "ticket_auto_assignment_user_ids_ignore" (as integer)' do
  43. let(:setting_user_ids_ignore) { session_user.id }
  44. it 'assigns ticket not to current session user' do
  45. visit "#ticket/zoom/#{ticket.id}"
  46. within(:active_content) do
  47. expect(page).to have_css('select[name=owner_id]')
  48. expect(page).to have_select('owner_id',
  49. selected: '-',
  50. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  51. end
  52. end
  53. end
  54. context 'with "ticket_auto_assignment_user_ids_ignore" (as string)' do
  55. let(:setting_user_ids_ignore) { session_user.id.to_s }
  56. it 'assigns ticket not to current session user' do
  57. visit "#ticket/zoom/#{ticket.id}"
  58. within(:active_content) do
  59. expect(page).to have_css('select[name=owner_id]')
  60. expect(page).to have_select('owner_id',
  61. selected: '-',
  62. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  63. end
  64. end
  65. end
  66. context 'with "ticket_auto_assignment_user_ids_ignore" (as [integer])' do
  67. let(:setting_user_ids_ignore) { [session_user.id] }
  68. it 'assigns ticket not to current session user' do
  69. visit "#ticket/zoom/#{ticket.id}"
  70. within(:active_content) do
  71. expect(page).to have_css('select[name=owner_id]')
  72. expect(page).to have_select('owner_id',
  73. selected: '-',
  74. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  75. end
  76. end
  77. end
  78. context 'with "ticket_auto_assignment_user_ids_ignore" (as [string])' do
  79. let(:setting_user_ids_ignore) { [session_user.id.to_s] }
  80. it 'assigns ticket not to current session user' do
  81. visit "#ticket/zoom/#{ticket.id}"
  82. within(:active_content) do
  83. expect(page).to have_css('select[name=owner_id]')
  84. expect(page).to have_select('owner_id',
  85. selected: '-',
  86. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  87. end
  88. end
  89. end
  90. context 'with "ticket_auto_assignment_user_ids_ignore" and other user ids' do
  91. let(:setting_user_ids_ignore) { [99_999, 999_999] }
  92. it 'assigns ticket to current session user' do
  93. visit "#ticket/zoom/#{ticket.id}"
  94. within(:active_content) do
  95. expect(page).to have_css('select[name=owner_id]')
  96. expect(page).to have_select('owner_id',
  97. selected: session_user.fullname,
  98. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  99. end
  100. end
  101. end
  102. end
  103. end
  104. describe 'Mandatory field in combination with automatic assignment leads to a divergence in the setting of the ticket owner #4245', authenticated_as: :authenticate, db_strategy: :reset do
  105. let!(:ticket) { create(:ticket, group: Group.find_by(name: 'Users')) }
  106. let(:field_name) { SecureRandom.uuid }
  107. let(:field) do
  108. create :object_manager_attribute_text, name: field_name, display: field_name, screens: attributes_for(:required_screen)
  109. ObjectManager::Attribute.migration_execute
  110. end
  111. def authenticate
  112. Setting.set('ticket_auto_assignment', true)
  113. Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.all.pluck(:id) } } })
  114. field
  115. true
  116. end
  117. before do
  118. visit "#ticket/zoom/#{ticket.id}"
  119. end
  120. it 'does auto assign the current user even if we have an empty required field' do
  121. expect(page).to have_select('owner_id', selected: 'Test Admin Agent')
  122. end
  123. end
  124. end