2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2017-08-30 13:50:48 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class TicketLastOwnerUpdateTest < ActiveSupport::TestCase
|
|
|
|
|
2021-07-09 13:05:05 +00:00
|
|
|
setup do
|
2019-06-28 11:38:49 +00:00
|
|
|
Group.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'LastOwnerUpdate',
|
|
|
|
email_address: EmailAddress.first,
|
2017-08-30 13:50:48 +00:00
|
|
|
assignment_timeout: 60,
|
2018-12-19 17:31:51 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2017-08-30 13:50:48 +00:00
|
|
|
)
|
|
|
|
roles = Role.where(name: 'Agent')
|
|
|
|
@agent1 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
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,
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-11-01 14:23:44 +00:00
|
|
|
test 'last_owner_update_at check by state' do
|
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test by state 1',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
2017-11-01 14:23:44 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-11-03 07:54:13 +00:00
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
|
2017-11-01 14:23:44 +00:00
|
|
|
|
|
|
|
ticket.state = Ticket::State.lookup(name: 'closed')
|
|
|
|
ticket.save!
|
|
|
|
assert_nil(ticket.last_owner_update_at)
|
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test by state 1',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'pending reminder'),
|
2017-11-01 14:23:44 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_nil(ticket.last_owner_update_at)
|
|
|
|
|
|
|
|
ticket.state = Ticket::State.lookup(name: 'open')
|
|
|
|
ticket.save!
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket.updated_at.to_i, ticket.last_owner_update_at.to_i, 1)
|
2017-11-01 14:23:44 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'last_owner_update_at check with agent reply' do
|
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test by state 1',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'open'),
|
2017-11-01 14:23:44 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-11-03 07:51:20 +00:00
|
|
|
assert_in_delta(ticket.updated_at.to_i, ticket.last_owner_update_at.to_i, 1)
|
2017-11-01 14:23:44 +00:00
|
|
|
|
|
|
|
travel 1.hour
|
|
|
|
|
2019-06-28 11:38:49 +00:00
|
|
|
Ticket::Article.create(
|
2018-12-19 17:31:51 +00:00
|
|
|
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'),
|
2017-11-01 14:23:44 +00:00
|
|
|
updated_by_id: 2,
|
|
|
|
created_by_id: 2,
|
|
|
|
)
|
|
|
|
|
|
|
|
ticket_last_owner_update_at = ticket.last_owner_update_at
|
|
|
|
ticket.reload
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket_last_owner_update_at.to_i, 1)
|
2017-11-01 14:23:44 +00:00
|
|
|
|
|
|
|
travel 1.hour
|
|
|
|
|
2019-06-28 11:38:49 +00:00
|
|
|
Ticket::Article.create(
|
2018-12-19 17:31:51 +00:00
|
|
|
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'),
|
2017-11-01 14:23:44 +00:00
|
|
|
updated_by_id: @agent1.id,
|
|
|
|
created_by_id: @agent1.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
ticket_last_owner_update_at = Time.zone.now
|
|
|
|
ticket.reload
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket_last_owner_update_at.to_i, 1)
|
2017-11-01 14:23:44 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-08-30 13:50:48 +00:00
|
|
|
test 'last_owner_update_at check' do
|
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 1',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_nil(ticket.last_owner_update_at)
|
|
|
|
|
|
|
|
travel 1.hour
|
|
|
|
ticket.owner = @agent1
|
|
|
|
ticket.save!
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 1',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'closed'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_nil(ticket.last_owner_update_at)
|
|
|
|
|
|
|
|
travel 1.hour
|
|
|
|
ticket.owner = @agent1
|
|
|
|
ticket.save!
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 1',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket.owner_id = 1
|
|
|
|
ticket.save!
|
|
|
|
assert_nil(ticket.last_owner_update_at)
|
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 1',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'open'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-11-03 07:51:20 +00:00
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket.owner_id = 1
|
|
|
|
ticket.save!
|
|
|
|
assert_nil(ticket.last_owner_update_at)
|
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 2',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_nil(ticket.last_owner_update_at)
|
|
|
|
|
|
|
|
travel 1.hour
|
|
|
|
ticket.owner = @agent1
|
|
|
|
ticket.save!
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 2',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'closed'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_nil(ticket.last_owner_update_at)
|
|
|
|
|
|
|
|
travel 1.hour
|
|
|
|
ticket.owner = @agent1
|
|
|
|
ticket.save!
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 2',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket.last_owner_update_at.to_i, ticket.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket.owner_id = 1
|
|
|
|
ticket.save!
|
|
|
|
assert_nil(ticket.last_owner_update_at)
|
|
|
|
|
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 2',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'closed'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-11-01 14:23:44 +00:00
|
|
|
assert_nil(ticket.last_owner_update_at)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
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!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 1',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_nil(ticket1.last_owner_update_at)
|
|
|
|
|
|
|
|
ticket2 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 2',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket2.last_owner_update_at.to_i, ticket2.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket3 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 3',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'open'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket3.last_owner_update_at.to_i, ticket3.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket4 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 4',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert_nil(ticket4.last_owner_update_at)
|
|
|
|
|
|
|
|
ticket5 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'assignment_timeout test 5',
|
|
|
|
group: Group.lookup(name: 'LastOwnerUpdate'),
|
|
|
|
owner: @agent1,
|
|
|
|
customer_id: 2,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
2017-08-30 13:50:48 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-11-03 07:51:20 +00:00
|
|
|
|
|
|
|
assert_in_delta(ticket5.last_owner_update_at.to_i, ticket5.updated_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
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)
|
2017-11-03 07:51:20 +00:00
|
|
|
assert_in_delta(ticket2.last_owner_update_at.to_i, ticket2after.last_owner_update_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
assert_equal(ticket2.updated_at.to_s, ticket2after.updated_at.to_s)
|
|
|
|
|
|
|
|
ticket3after = Ticket.find(ticket3.id)
|
2017-11-03 07:51:20 +00:00
|
|
|
assert_in_delta(ticket3.last_owner_update_at.to_i, ticket3after.last_owner_update_at.to_i, 1)
|
2017-08-30 13:50:48 +00:00
|
|
|
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
|
2017-11-01 14:23:44 +00:00
|
|
|
ticket_updated_at = Time.current
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
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)
|
2017-11-01 14:23:44 +00:00
|
|
|
assert_equal(ticket_updated_at.to_s, ticket2after.updated_at.to_s)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
ticket3after = Ticket.find(ticket3.id)
|
2017-11-01 14:23:44 +00:00
|
|
|
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)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
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)
|
2017-11-01 14:23:44 +00:00
|
|
|
assert_equal(ticket5after.owner_id, 1)
|
|
|
|
assert_equal(ticket_updated_at.to_s, ticket5after.updated_at.to_s)
|
2017-08-30 13:50:48 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|