2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-09-19 13:54:49 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Ticket Escalation', type: :request do
|
2021-02-15 13:55:00 +00:00
|
|
|
let(:sla_first_response) { 1.hour }
|
|
|
|
let(:sla_update) { 3.hours }
|
|
|
|
let(:sla_close) { 4.hours }
|
|
|
|
|
|
|
|
let!(:mail_group) { create(:group, email_address: create(:email_address) ) }
|
|
|
|
|
|
|
|
let(:calendar) { create(:calendar, :'24/7') }
|
|
|
|
let(:sla) do
|
|
|
|
create(:sla,
|
|
|
|
calendar: calendar,
|
|
|
|
first_response_time: sla_first_response / 1.minute,
|
|
|
|
update_time: sla_update / 1.minute,
|
|
|
|
solution_time: sla_close / 1.minute)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
2021-02-15 13:55:00 +00:00
|
|
|
|
|
|
|
define :json_equal_date do
|
|
|
|
match do
|
2021-05-12 11:37:44 +00:00
|
|
|
actual&.sub(%r{.\d\d\dZ$}, 'Z') == expected&.iso8601
|
2021-02-15 13:55:00 +00:00
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
2021-02-15 13:55:00 +00:00
|
|
|
|
|
|
|
shared_examples 'response matching object' do
|
|
|
|
%w[escalation_at first_response_escalation_at update_escalation_at close_escalation_at].each do |attribute|
|
|
|
|
it "#{attribute} is representing the same time" do
|
|
|
|
expect(json_response[attribute]).to json_equal_date ticket[attribute]
|
|
|
|
end
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
2021-02-15 13:55:00 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
freeze_time
|
|
|
|
sla
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
context 'when customer creates ticket via web', authenticated_as: :customer do
|
|
|
|
subject(:ticket) { Ticket.find(json_response['id']) }
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
let(:customer) { create(:customer) }
|
|
|
|
|
|
|
|
before do
|
2018-09-19 13:54:49 +00:00
|
|
|
params = {
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'some value 123',
|
|
|
|
group: mail_group.name,
|
2018-09-19 13:54:49 +00:00
|
|
|
article: {
|
2021-02-15 13:55:00 +00:00
|
|
|
type_id: Ticket::Article::Type.find_by(name: 'web').id,
|
|
|
|
body: 'some test 123',
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/tickets', params: params, as: :json
|
2021-02-15 13:55:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'response matching object'
|
|
|
|
|
|
|
|
it 'first response escalation in 1h' do
|
|
|
|
expect(ticket.first_response_escalation_at).to eq 1.hour.from_now
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'update_escalation in 3h' do
|
|
|
|
expect(ticket.update_escalation_at).to eq 3.hours.from_now
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'close escalation in 4h' do
|
|
|
|
expect(ticket.close_escalation_at).to eq 4.hours.from_now
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'next escalation is closest escalation' do
|
|
|
|
expect(ticket.escalation_at).to eq 1.hour.from_now
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when customer sends email' do
|
|
|
|
subject(:ticket) { ticket_mail_in }
|
|
|
|
|
|
|
|
before { ticket }
|
|
|
|
|
|
|
|
it 'first response escalation in 1h' do
|
|
|
|
expect(ticket.first_response_escalation_at).to eq 1.hour.from_now
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'update_escalation in 3h' do
|
|
|
|
expect(ticket.update_escalation_at).to eq 3.hours.from_now
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'close escalation in 4h' do
|
|
|
|
expect(ticket.close_escalation_at).to eq 4.hours.from_now
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'next escalation is closest escalation' do
|
|
|
|
expect(ticket.escalation_at).to eq 1.hour.from_now
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when agent responds via web', authenticated_as: :agent do
|
|
|
|
subject(:ticket) { ticket_mail_in }
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
let(:agent) { create(:agent, groups: Group.all) }
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
before { ticket && travel(3.hours) }
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
it_behaves_like 'response matching object' do
|
|
|
|
before { ticket_respond_web }
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
it 'clears first response escalation' do
|
|
|
|
expect { ticket_respond_web }.to change(ticket, :first_response_escalation_at).to(nil)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
it 'changes update escalation' do
|
|
|
|
expect { ticket_respond_web }.to change(ticket, :update_escalation_at)
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
it 'update escalation is nil since agent responded' do
|
|
|
|
ticket_respond_web
|
|
|
|
expect(ticket.update_escalation_at).to be_nil
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
it 'does not change close escalation' do
|
|
|
|
expect { ticket_respond_web }.not_to change(ticket, :close_escalation_at)
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
it 'change next escalation' do
|
|
|
|
expect { ticket_respond_web }.to change(ticket, :escalation_at)
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
it 'next escalation is closest escalation which is close escalation' do
|
|
|
|
ticket_respond_web
|
|
|
|
expect(ticket.escalation_at).to eq 1.hour.from_now
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2021-02-15 13:55:00 +00:00
|
|
|
def ticket_respond_web
|
2018-09-19 13:54:49 +00:00
|
|
|
params = {
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'some value 123 - update',
|
2018-09-19 13:54:49 +00:00
|
|
|
article: {
|
2021-02-15 13:55:00 +00:00
|
|
|
type_id: Ticket::Article::Type.find_by(name: 'email').id,
|
|
|
|
body: 'some test 123',
|
|
|
|
type: 'email',
|
|
|
|
to: 'customer@example.com',
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
}
|
2021-02-15 13:55:00 +00:00
|
|
|
|
|
|
|
put "/api/v1/tickets/#{ticket.id}", params: params, as: :json
|
|
|
|
|
|
|
|
ticket.reload
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
end
|
2021-02-15 13:55:00 +00:00
|
|
|
|
|
|
|
def ticket_mail_in
|
|
|
|
email = <<~EMAIL
|
|
|
|
From: Bob Smith <customer@example.com>
|
|
|
|
To: #{mail_group.email_address.email}
|
|
|
|
Subject: some value 123
|
|
|
|
|
|
|
|
Some Text
|
|
|
|
EMAIL
|
|
|
|
|
|
|
|
ticket, _article_p, _user_p, _mail = Channel::EmailParser.new.process({}, email)
|
|
|
|
|
|
|
|
ticket
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|