2018-09-19 13:54:49 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Ticket Escalation', type: :request do
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
let!(:agent) do
|
|
|
|
create(:agent, groups: Group.all)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
2020-06-19 09:17:18 +00:00
|
|
|
let!(:customer) do
|
|
|
|
create(:customer)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
let!(:calendar) do
|
|
|
|
create(
|
|
|
|
:calendar,
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Escalation Test',
|
|
|
|
timezone: 'Europe/Berlin',
|
2018-09-19 13:54:49 +00:00
|
|
|
business_hours: {
|
|
|
|
mon: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2018-09-19 13:54:49 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
tue: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2018-09-19 13:54:49 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
wed: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2018-09-19 13:54:49 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
thu: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2018-09-19 13:54:49 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
fri: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2018-09-19 13:54:49 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
sat: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2018-09-19 13:54:49 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
sun: {
|
2018-12-19 17:31:51 +00:00
|
|
|
active: true,
|
2018-09-19 13:54:49 +00:00
|
|
|
timeframes: [ ['00:00', '23:59'] ]
|
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
default: true,
|
|
|
|
ical_url: nil,
|
2018-09-19 13:54:49 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
let!(:sla) do
|
|
|
|
create(
|
|
|
|
:sla,
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'test sla 1',
|
|
|
|
condition: {
|
2018-09-19 13:54:49 +00:00
|
|
|
'ticket.title' => {
|
|
|
|
operator: 'contains',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'some value 123',
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
first_response_time: 60,
|
2018-12-19 17:31:51 +00:00
|
|
|
update_time: 180,
|
|
|
|
solution_time: 240,
|
|
|
|
calendar: calendar,
|
2018-09-19 13:54:49 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
let!(:mail_group) do
|
|
|
|
create(:group, email_address: create(:email_address) )
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'request handling' do
|
|
|
|
|
|
|
|
it 'does escalate by ticket created via web' do
|
|
|
|
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: {
|
|
|
|
body: 'some test 123',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(customer)
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/tickets', params: params, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:created)
|
2018-09-19 13:54:49 +00:00
|
|
|
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'new').id)
|
|
|
|
expect(json_response['title']).to eq('some value 123')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['updated_by_id']).to eq(customer.id)
|
|
|
|
expect(json_response['created_by_id']).to eq(customer.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
|
|
|
|
ticket_p = Ticket.find(json_response['id'])
|
|
|
|
|
|
|
|
expect(json_response['escalation_at'].sub(/.\d\d\dZ$/, 'Z')).to eq(ticket_p['escalation_at'].iso8601)
|
|
|
|
expect(json_response['first_response_escalation_at'].sub(/.\d\d\dZ$/, 'Z')).to eq(ticket_p['first_response_escalation_at'].iso8601)
|
|
|
|
expect(json_response['update_escalation_at'].sub(/.\d\d\dZ$/, 'Z')).to eq(ticket_p['update_escalation_at'].iso8601)
|
|
|
|
expect(json_response['close_escalation_at'].sub(/.\d\d\dZ$/, 'Z')).to eq(ticket_p['close_escalation_at'].iso8601)
|
|
|
|
|
|
|
|
expect(ticket_p.escalation_at).to be_truthy
|
|
|
|
expect(ticket_p.first_response_escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 1.hour).to_i)
|
|
|
|
expect(ticket_p.update_escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 3.hours).to_i)
|
|
|
|
expect(ticket_p.close_escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 4.hours).to_i)
|
|
|
|
expect(ticket_p.escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 1.hour).to_i)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does escalate by ticket got created via email - reply by agent via web' do
|
|
|
|
|
|
|
|
email = "From: Bob Smith <customer@example.com>
|
|
|
|
To: #{mail_group.email_address.email}
|
|
|
|
Subject: some value 123
|
|
|
|
|
|
|
|
Some Text"
|
|
|
|
|
2019-06-28 11:38:49 +00:00
|
|
|
ticket_p, _article_p, user_p, _mail = Channel::EmailParser.new.process({}, email)
|
2018-09-19 13:54:49 +00:00
|
|
|
ticket_p.reload
|
|
|
|
expect(ticket_p.escalation_at).to be_truthy
|
|
|
|
expect(ticket_p.first_response_escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 1.hour).to_i)
|
|
|
|
expect(ticket_p.update_escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 3.hours).to_i)
|
|
|
|
expect(ticket_p.close_escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 4.hours).to_i)
|
|
|
|
expect(ticket_p.escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 1.hour).to_i)
|
|
|
|
|
|
|
|
travel 3.hours
|
|
|
|
|
|
|
|
params = {
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'some value 123 - update',
|
2018-09-19 13:54:49 +00:00
|
|
|
article: {
|
|
|
|
body: 'some test 123',
|
|
|
|
type: 'email',
|
2018-12-19 17:31:51 +00:00
|
|
|
to: 'customer@example.com',
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
}
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
put "/api/v1/tickets/#{ticket_p.id}", params: params, as: :json
|
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['state_id']).to eq(Ticket::State.lookup(name: 'open').id)
|
|
|
|
expect(json_response['title']).to eq('some value 123 - update')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['updated_by_id']).to eq(agent.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['created_by_id']).to eq(user_p.id)
|
|
|
|
|
|
|
|
ticket_p.reload
|
|
|
|
expect(json_response['escalation_at'].sub(/.\d\d\dZ$/, 'Z')).to eq(ticket_p['escalation_at'].iso8601)
|
|
|
|
expect(json_response['first_response_escalation_at'].sub(/.\d\d\dZ$/, 'Z')).to eq(ticket_p['first_response_escalation_at'].iso8601)
|
|
|
|
expect(json_response['update_escalation_at'].sub(/.\d\d\dZ$/, 'Z')).to eq(ticket_p['update_escalation_at'].iso8601)
|
|
|
|
expect(json_response['close_escalation_at'].sub(/.\d\d\dZ$/, 'Z')).to eq(ticket_p['close_escalation_at'].iso8601)
|
|
|
|
|
|
|
|
expect(ticket_p.first_response_escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 1.hour).to_i)
|
|
|
|
expect(ticket_p.update_escalation_at.to_i).to be_within(90.seconds).of((ticket_p.last_contact_agent_at + 3.hours).to_i)
|
|
|
|
expect(ticket_p.close_escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 4.hours).to_i)
|
|
|
|
expect(ticket_p.escalation_at.to_i).to be_within(90.seconds).of((ticket_p.created_at + 4.hours).to_i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|