auto_assignment_spec.rb 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket: #auto_assign' do # rubocop:disable RSpec/DescribeClass
  4. before do
  5. Setting.set('ticket_auto_assignment', ticket_auto_assignment)
  6. Setting.set('ticket_auto_assignment_selector', { condition: ticket_auto_assignment_condition })
  7. end
  8. context 'when auto assignment is enabled' do
  9. let(:ticket_auto_assignment) { true }
  10. context 'when conditions with states are used' do
  11. let(:ticket) { create(:ticket, group: Group.first, state: Ticket::State.find_by(name: 'closed')) }
  12. let(:agent) { create(:agent, groups: [Group.first]) }
  13. context 'when the condition does match' do
  14. let(:ticket_auto_assignment_condition) { { 'ticket.state_id' => { operator: 'is', value: Ticket::State.pluck(:id) } } }
  15. it 'does auto assign' do
  16. ticket.auto_assign(agent)
  17. expect(ticket.reload.owner_id).to eq(agent.id)
  18. end
  19. end
  20. context 'when the condition does not match' do
  21. let(:ticket_auto_assignment_condition) { { 'ticket.state_id' => { operator: 'is', value: Ticket::State.by_category_ids(:work_on) } } }
  22. it 'does not auto assign' do
  23. ticket.auto_assign(agent)
  24. expect(ticket.reload.owner_id).to eq(1)
  25. end
  26. end
  27. end
  28. context 'when conditions with title are used' do
  29. let(:ticket) { create(:ticket, group: Group.first, title: 'Welcome to Zammad') }
  30. let(:agent) { create(:agent, groups: [Group.first]) }
  31. context 'when the condition does match' do
  32. let(:ticket_auto_assignment_condition) { { 'ticket.title' => { operator: 'matches regex', value: '^welcome' } } }
  33. it 'does auto assign' do
  34. ticket.auto_assign(agent)
  35. expect(ticket.reload.owner_id).to eq(agent.id)
  36. end
  37. end
  38. context 'when the condition does not match' do
  39. let(:ticket_auto_assignment_condition) { { 'ticket.title' => { operator: 'does not match regex', value: '^welcome' } } }
  40. it 'does not auto assign' do
  41. ticket.auto_assign(agent)
  42. expect(ticket.reload.owner_id).to eq(1)
  43. end
  44. end
  45. end
  46. end
  47. end