auto_assignment_spec.rb 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Copyright (C) 2012-2024 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_ids(:work_on) } } })
  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_select('owner_id',
  18. selected: '-',
  19. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  20. end
  21. end
  22. end
  23. context 'when agent enabled' do
  24. def authenticate
  25. Setting.set('ticket_auto_assignment', true)
  26. Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category_ids(:work_on) } } })
  27. Setting.set('ticket_auto_assignment_user_ids_ignore', setting_user_ids_ignore) if defined?(setting_user_ids_ignore)
  28. true
  29. end
  30. context 'with empty "ticket_auto_assignment_user_ids_ignore"' do
  31. it 'assigns ticket to current session user' do
  32. visit "#ticket/zoom/#{ticket.id}"
  33. within(:active_content) do
  34. expect(page).to have_css('.content.active select[name=owner_id]')
  35. expect(page).to have_select('owner_id',
  36. selected: session_user.fullname,
  37. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  38. end
  39. end
  40. end
  41. context 'with "ticket_auto_assignment_user_ids_ignore" (as integer)' do
  42. let(:setting_user_ids_ignore) { session_user.id }
  43. it 'assigns ticket not to current session user' do
  44. visit "#ticket/zoom/#{ticket.id}"
  45. within(:active_content) do
  46. expect(page).to have_select('owner_id',
  47. selected: '-',
  48. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  49. end
  50. end
  51. end
  52. context 'with "ticket_auto_assignment_user_ids_ignore" (as string)' do
  53. let(:setting_user_ids_ignore) { session_user.id.to_s }
  54. it 'assigns ticket not to current session user' do
  55. visit "#ticket/zoom/#{ticket.id}"
  56. within(:active_content) do
  57. expect(page).to have_select('owner_id',
  58. selected: '-',
  59. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  60. end
  61. end
  62. end
  63. context 'with "ticket_auto_assignment_user_ids_ignore" (as [integer])' do
  64. let(:setting_user_ids_ignore) { [session_user.id] }
  65. it 'assigns ticket not to current session user' do
  66. visit "#ticket/zoom/#{ticket.id}"
  67. within(:active_content) do
  68. expect(page).to have_select('owner_id',
  69. selected: '-',
  70. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  71. end
  72. end
  73. end
  74. context 'with "ticket_auto_assignment_user_ids_ignore" (as [string])' do
  75. let(:setting_user_ids_ignore) { [session_user.id.to_s] }
  76. it 'assigns ticket not to current session user' do
  77. visit "#ticket/zoom/#{ticket.id}"
  78. within(:active_content) do
  79. expect(page).to have_select('owner_id',
  80. selected: '-',
  81. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  82. end
  83. end
  84. end
  85. context 'with "ticket_auto_assignment_user_ids_ignore" and other user ids' do
  86. let(:setting_user_ids_ignore) { [99_999, 999_999] }
  87. it 'assigns ticket to current session user' do
  88. visit "#ticket/zoom/#{ticket.id}"
  89. within(:active_content) do
  90. expect(page).to have_select('owner_id',
  91. selected: session_user.fullname,
  92. options: ['-', 'Agent 1 Test', 'Test Admin Agent'])
  93. end
  94. end
  95. end
  96. end
  97. end
  98. 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
  99. let!(:ticket) { create(:ticket, group: Group.find_by(name: 'Users')) }
  100. let(:field_name) { SecureRandom.uuid }
  101. let(:field) do
  102. create(:object_manager_attribute_text, :required_screen, name: field_name, display: field_name)
  103. ObjectManager::Attribute.migration_execute
  104. end
  105. def authenticate
  106. Setting.set('ticket_auto_assignment', true)
  107. Setting.set('ticket_auto_assignment_selector', { condition: { 'ticket.state_id' => { operator: 'is', value: Ticket::State.pluck(:id) } } })
  108. field
  109. true
  110. end
  111. before do
  112. visit "#ticket/zoom/#{ticket.id}"
  113. end
  114. it 'does auto assign the current user even if we have an empty required field' do
  115. expect(page).to have_select('owner_id', selected: 'Test Admin Agent')
  116. end
  117. end
  118. end