Fixes #3551 - First response doesn't get solved after answering and state change to pending reminder.

This commit is contained in:
Mantas Masalskis 2021-05-19 15:10:36 +00:00 committed by Thorsten Eckel
parent bde3452f9b
commit 3330fe9ce7
4 changed files with 26 additions and 2 deletions

View file

@ -39,7 +39,7 @@ class Escalation
end
def calculatable?
!escalation_disabled? || preferences.close_at_changed?(ticket)
!escalation_disabled? || preferences.close_at_changed?(ticket) || preferences.last_contact_at_changed?(ticket)
end
def calculate!

View file

@ -3,7 +3,7 @@ class Escalation
KEYS = %i[escalation_disabled
first_response_at last_update_at close_at escalation_at
sla_id sla_updated_at
calendar_id calendar_updated_at].freeze
calendar_id calendar_updated_at last_contact_at].freeze
attr_reader :hash
@ -39,6 +39,10 @@ class Escalation
@hash[:close_at] != ticket.close_at
end
def last_contact_at_changed?(ticket)
@hash[:last_contact_at] != ticket.last_contact_at
end
def property_changes?(ticket)
%i[first_response_at last_update_at close_at].any? { |elem| send("#{elem}_changed?", ticket) }
end
@ -60,6 +64,7 @@ class Escalation
first_response_at: ticket.first_response_at,
last_update_at: ticket.last_original_update_at,
close_at: ticket.close_at,
last_contact_at: ticket.last_contact_at,
sla_id: sla&.id,
sla_updated_at: sla&.updated_at,
calendar_id: sla&.calendar&.id,

View file

@ -67,6 +67,14 @@ RSpec.describe ::Escalation do
expect(instance).to be_calculatable
end
it 'true when response to ticket comes while ticket has pending reminder' do
ticket.update(state: Ticket::State.find_by(name: 'pending reminder'))
without_update_escalation_information_callback { create(:'ticket/article', :outbound_email, ticket: ticket) }
expect(instance).to be_calculatable
end
end
describe '#calculate' do

View file

@ -65,6 +65,17 @@ RSpec.shared_examples 'Ticket::Escalation' do
expect(ticket.close_diff_in_min).to be_nil
end
context 'with first response time resolved by answer + state pending reminder' do
before do
ticket.update(state: Ticket::State.find_by(name: 'pending reminder'))
create(:'ticket/article', :outbound_email, ticket: ticket, created_at: '2013-03-21 09:45:00 UTC', updated_at: '2013-03-21 09:45:00 UTC')
end
it 'does set first_response_diff_in_min' do
expect(ticket.reload.first_response_diff_in_min).to eq(45)
end
end
context 'with first response in time' do
before do