123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- require 'test_helper'
- class TicketLastOwnerUpdateTest < ActiveSupport::TestCase
- setup do
- Group.create_or_update(
- name: 'LastOwnerUpdate',
- email_address: EmailAddress.first,
- assignment_timeout: 60,
- updated_by_id: 1,
- created_by_id: 1,
- )
- roles = Role.where(name: 'Agent')
- @agent1 = User.create_or_update(
- login: 'ticket-assignment_timeout-agent1@example.com',
- firstname: 'Overview',
- lastname: 'Agent1',
- email: 'ticket-assignment_timeout-agent1@example.com',
- password: 'agentpw',
- active: true,
- roles: roles,
- groups: Group.all,
- updated_by_id: 1,
- created_by_id: 1,
- )
- end
- test 'last_owner_update_at check by state' do
- ticket = Ticket.create!(
- title: 'assignment_timeout test by state 1',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
- ticket.state = Ticket::State.lookup(name: 'closed')
- ticket.save!
- assert_nil(ticket.last_owner_update_at)
- ticket = Ticket.create!(
- title: 'assignment_timeout test by state 1',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'pending reminder'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_nil(ticket.last_owner_update_at)
- ticket.state = Ticket::State.lookup(name: 'open')
- ticket.save!
- assert_in_delta(ticket.updated_at.to_i, ticket.last_owner_update_at.to_i, 1)
- end
- test 'last_owner_update_at check with agent reply' do
- ticket = Ticket.create!(
- title: 'assignment_timeout test by state 1',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'open'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_in_delta(ticket.updated_at.to_i, ticket.last_owner_update_at.to_i, 1)
- travel 1.hour
- Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message reply by customer email',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Customer'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: 2,
- created_by_id: 2,
- )
- ticket_last_owner_update_at = ticket.last_owner_update_at
- ticket.reload
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket_last_owner_update_at.to_i, 1)
- travel 1.hour
- Ticket::Article.create(
- ticket_id: ticket.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message reply by agent email',
- internal: false,
- sender: Ticket::Article::Sender.find_by(name: 'Agent'),
- type: Ticket::Article::Type.find_by(name: 'email'),
- updated_by_id: @agent1.id,
- created_by_id: @agent1.id,
- )
- ticket_last_owner_update_at = Time.zone.now
- ticket.reload
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket_last_owner_update_at.to_i, 1)
- end
- test 'last_owner_update_at check' do
- ticket = Ticket.create!(
- title: 'assignment_timeout test 1',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_nil(ticket.last_owner_update_at)
- travel 1.hour
- ticket.owner = @agent1
- ticket.save!
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
- ticket = Ticket.create!(
- title: 'assignment_timeout test 1',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_nil(ticket.last_owner_update_at)
- travel 1.hour
- ticket.owner = @agent1
- ticket.save!
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
- ticket = Ticket.create!(
- title: 'assignment_timeout test 1',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
- ticket.owner_id = 1
- ticket.save!
- assert_nil(ticket.last_owner_update_at)
- ticket = Ticket.create!(
- title: 'assignment_timeout test 1',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'open'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
- ticket.owner_id = 1
- ticket.save!
- assert_nil(ticket.last_owner_update_at)
- ticket = Ticket.create!(
- title: 'assignment_timeout test 2',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_nil(ticket.last_owner_update_at)
- travel 1.hour
- ticket.owner = @agent1
- ticket.save!
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
- ticket = Ticket.create!(
- title: 'assignment_timeout test 2',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_nil(ticket.last_owner_update_at)
- travel 1.hour
- ticket.owner = @agent1
- ticket.save!
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
- ticket = Ticket.create!(
- title: 'assignment_timeout test 2',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
- ticket.owner_id = 1
- ticket.save!
- assert_nil(ticket.last_owner_update_at)
- ticket = Ticket.create!(
- title: 'assignment_timeout test 2',
- group: Group.lookup(name: 'Users'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_nil(ticket.last_owner_update_at)
- ticket.owner_id = 1
- ticket.save!
- assert_nil(ticket.last_owner_update_at)
- end
- test 'last_owner_update_at assignment_timeout check' do
- ticket1 = Ticket.create!(
- title: 'assignment_timeout test 1',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_nil(ticket1.last_owner_update_at)
- ticket2 = Ticket.create!(
- title: 'assignment_timeout test 2',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_in_delta(ticket2.last_owner_update_at.to_i, ticket2.updated_at.to_i, 1)
- ticket3 = Ticket.create!(
- title: 'assignment_timeout test 3',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'open'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_in_delta(ticket3.last_owner_update_at.to_i, ticket3.updated_at.to_i, 1)
- ticket4 = Ticket.create!(
- title: 'assignment_timeout test 4',
- group: Group.lookup(name: 'Users'),
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_nil(ticket4.last_owner_update_at)
- ticket5 = Ticket.create!(
- title: 'assignment_timeout test 5',
- group: Group.lookup(name: 'LastOwnerUpdate'),
- owner: @agent1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- updated_by_id: 1,
- created_by_id: 1,
- )
- assert_in_delta(ticket5.last_owner_update_at.to_i, ticket5.updated_at.to_i, 1)
- travel 55.minutes
- Ticket.process_auto_unassign
- ticket1after = Ticket.find(ticket1.id)
- assert_nil(ticket1.last_owner_update_at)
- assert_equal(ticket1.updated_at.to_s, ticket1after.updated_at.to_s)
- ticket2after = Ticket.find(ticket2.id)
- assert_in_delta(ticket2.last_owner_update_at.to_i, ticket2after.last_owner_update_at.to_i, 1)
- assert_equal(ticket2.updated_at.to_s, ticket2after.updated_at.to_s)
- ticket3after = Ticket.find(ticket3.id)
- assert_in_delta(ticket3.last_owner_update_at.to_i, ticket3after.last_owner_update_at.to_i, 1)
- assert_equal(ticket3.updated_at.to_s, ticket3after.updated_at.to_s)
- ticket4after = Ticket.find(ticket4.id)
- assert_nil(ticket4.last_owner_update_at)
- assert_equal(ticket4.updated_at.to_s, ticket4after.updated_at.to_s)
- ticket5after = Ticket.find(ticket5.id)
- assert_equal(ticket5after.owner_id, @agent1.id)
- assert_equal(ticket5.updated_at.to_s, ticket5after.updated_at.to_s)
- travel 15.minutes
- Ticket.process_auto_unassign
- ticket_updated_at = Time.current
- ticket1after = Ticket.find(ticket1.id)
- assert_nil(ticket1.last_owner_update_at)
- assert_equal(ticket1.updated_at.to_s, ticket1after.updated_at.to_s)
- ticket2after = Ticket.find(ticket2.id)
- assert_nil(ticket2after.last_owner_update_at)
- assert_equal(ticket2after.owner_id, 1)
- assert_equal(ticket_updated_at.to_s, ticket2after.updated_at.to_s)
- ticket3after = Ticket.find(ticket3.id)
- assert_nil(ticket3after.last_owner_update_at)
- assert_equal(ticket3after.owner_id, 1)
- assert_equal(ticket_updated_at.to_s, ticket3after.updated_at.to_s)
- ticket4after = Ticket.find(ticket4.id)
- assert_nil(ticket4.last_owner_update_at)
- assert_equal(ticket4.updated_at.to_s, ticket4after.updated_at.to_s)
- ticket5after = Ticket.find(ticket5.id)
- assert_equal(ticket5after.owner_id, 1)
- assert_equal(ticket_updated_at.to_s, ticket5after.updated_at.to_s)
- end
- end
|