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
|
|
|
|
2020-08-17 13:37:55 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2021-12-10 08:38:53 +00:00
|
|
|
RSpec.describe 'Caller log', type: :system, authenticated_as: :authenticate do
|
2021-10-12 14:16:59 +00:00
|
|
|
let(:agent_phone) { '0190111' }
|
|
|
|
let(:customer_phone) { '0190333' }
|
|
|
|
let(:cti_token) { 'token1234' }
|
|
|
|
let(:agent) { create(:agent, phone: agent_phone) }
|
|
|
|
let(:customer) { create(:customer, phone: customer_phone) }
|
|
|
|
let(:cti_on) { true }
|
2020-08-17 13:37:55 +00:00
|
|
|
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
direction: 'in',
|
2021-10-12 14:16:59 +00:00
|
|
|
from: customer.phone,
|
|
|
|
to: agent_phone,
|
2020-08-17 13:37:55 +00:00
|
|
|
callId: '111',
|
2021-10-12 14:16:59 +00:00
|
|
|
cause: 'busy',
|
2020-08-17 13:37:55 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
let(:first_params) { params.merge(event: 'newCall') }
|
|
|
|
let(:second_params) { params.merge(event: 'hangup') }
|
|
|
|
|
|
|
|
let(:place_call) do
|
|
|
|
post "#{Capybara.app_host}/api/v1/cti/#{cti_token}", params: first_params
|
|
|
|
post "#{Capybara.app_host}/api/v1/cti/#{cti_token}", params: second_params
|
|
|
|
end
|
|
|
|
|
2021-12-10 08:38:53 +00:00
|
|
|
# Do the preperation before the authentication.
|
|
|
|
def authenticate
|
2021-10-12 14:16:59 +00:00
|
|
|
Setting.set('cti_integration', cti_on)
|
|
|
|
Setting.set('cti_token', cti_token)
|
|
|
|
|
2021-12-10 08:38:53 +00:00
|
|
|
agent
|
|
|
|
end
|
2021-10-12 14:16:59 +00:00
|
|
|
|
|
|
|
context 'when cti integration is on' do
|
|
|
|
it 'shows the phone menu in nav bar' do
|
|
|
|
|
|
|
|
within '#navigation .menu' do
|
|
|
|
expect(page).to have_link('Phone', href: '#cti')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when cti integration is not on' do
|
|
|
|
let(:cti_on) { false }
|
|
|
|
|
|
|
|
it 'does not show the phone menu in nav bar' do
|
|
|
|
|
|
|
|
within '#navigation .menu' do
|
|
|
|
expect(page).to have_no_link('Phone', href: '#cti')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a customer call is answered' do
|
|
|
|
let(:second_params) { params.merge(event: 'answer', answeringNumber: agent_phone) }
|
|
|
|
|
|
|
|
context 'without active tickets' do
|
|
|
|
before do
|
|
|
|
travel(-2.months)
|
|
|
|
create(:ticket, customer: customer)
|
|
|
|
travel_back
|
|
|
|
|
|
|
|
visit 'cti'
|
|
|
|
|
|
|
|
place_call
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'opens a new ticket after phone call inbound' do
|
|
|
|
within(:active_content) do
|
|
|
|
expect(page).to have_text('New Ticket')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with active tickets' do
|
|
|
|
before do
|
|
|
|
create(:ticket, customer: customer)
|
|
|
|
|
|
|
|
visit 'cti'
|
|
|
|
|
|
|
|
place_call
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'opens the customer profile screen after phone call inbound with tickets in the last month' do
|
|
|
|
within(:active_content) do
|
|
|
|
expect(page).to have_text(customer.fullname)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with incoming call' do
|
|
|
|
before do
|
|
|
|
visit 'cti'
|
|
|
|
place_call
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'increments the call counter notification badge' do
|
|
|
|
within '[href="#cti"].js-phoneMenuItem' do
|
|
|
|
counter = find('.counter')
|
|
|
|
expect(counter).to have_content 1
|
|
|
|
end
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
end
|
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
context 'when incoming call is checked' do
|
|
|
|
before do
|
|
|
|
visit 'cti'
|
|
|
|
place_call
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'clears the call counter notification badge' do
|
|
|
|
within :active_content do
|
|
|
|
find('.table-checkbox input.js-check', visible: :all).check allow_label_click: true
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
within '[href="#cti"].js-phoneMenuItem' do
|
|
|
|
expect(page).to have_no_selector('.counter')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
# Regression test for #2018
|
|
|
|
context 'phone numbers format' do
|
|
|
|
before do
|
2020-08-17 13:37:55 +00:00
|
|
|
visit 'cti'
|
2021-10-12 14:16:59 +00:00
|
|
|
place_call
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with private number' do
|
|
|
|
let(:customer_phone) { '007' }
|
|
|
|
let(:agent_phone) { '008' }
|
2020-08-17 13:37:55 +00:00
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
it 'appears verbatim' do
|
2020-08-17 13:37:55 +00:00
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
within :active_content do
|
|
|
|
expect(page).to have_selector('.js-callerLog', text: customer_phone)
|
|
|
|
.and have_selector('.js-callerLog', text: agent_phone)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with e164 number' do
|
|
|
|
let(:customer_phone) { '4930609854180' }
|
|
|
|
let(:agent_phone) { '4930609811111' }
|
|
|
|
let(:prettified_customer_phone) { '+49 30 609854180' }
|
|
|
|
let(:prettified_current_user_phone) { '+49 30 609811111' }
|
|
|
|
|
|
|
|
it 'appears prettified' do
|
|
|
|
within :active_content do
|
|
|
|
expect(page).to have_selector('.js-callerLog', text: prettified_customer_phone)
|
|
|
|
.and have_selector('.js-callerLog', text: prettified_current_user_phone)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'done not appear verbatim' do
|
|
|
|
within :active_content do
|
|
|
|
expect(page).to have_no_selector('.js-callerLog', text: customer_phone)
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
# Regression test for #2096
|
|
|
|
context 'with inactive user' do
|
|
|
|
before do
|
|
|
|
visit 'cti'
|
|
|
|
place_call
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
let(:customer) do
|
|
|
|
create(:customer,
|
|
|
|
phone: customer_phone,
|
|
|
|
active: false,
|
|
|
|
firstname: 'John',
|
|
|
|
lastname: 'Doe')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'appears inactive' do
|
|
|
|
within :active_content do
|
|
|
|
expect(page).to have_selector('span.avatar--inactive', text: 'JD')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
# Regression test for #2075
|
|
|
|
context 'when user is with organization name' do
|
|
|
|
before do
|
2020-08-17 13:37:55 +00:00
|
|
|
visit 'cti'
|
2021-10-12 14:16:59 +00:00
|
|
|
place_call
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
let(:firstname) { 'John' }
|
|
|
|
let(:lastname) { 'Doe' }
|
|
|
|
let(:organization_name) { 'Test Organization' }
|
|
|
|
let(:organization) { create(:organization, name: organization_name) }
|
|
|
|
let(:full_name) { "#{firstname} #{lastname}" }
|
|
|
|
let(:customer) do
|
|
|
|
create(:customer,
|
|
|
|
phone: customer_phone,
|
|
|
|
firstname: firstname,
|
|
|
|
lastname: lastname,
|
|
|
|
organization: organization)
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
|
2021-10-12 14:16:59 +00:00
|
|
|
shared_examples 'showing user with thier organization name' do
|
|
|
|
it 'shows user with thier organization name' do
|
|
|
|
within :active_content do
|
|
|
|
expect(page).to have_selector(
|
|
|
|
'.js-callerLog tr div.user-popover',
|
|
|
|
text: "#{full_name} (#{organization_name})"
|
|
|
|
)
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
end
|
|
|
|
end
|
2021-10-12 14:16:59 +00:00
|
|
|
|
|
|
|
context 'with call direction out' do
|
|
|
|
let(:first_params) { params.merge(event: 'newCall', direction: 'out', from: agent_phone, to: customer.phone) }
|
|
|
|
let(:second_params) { params.merge(event: 'hangup', direction: 'out', from: agent_phone, to: customer.phone) }
|
|
|
|
|
|
|
|
it_behaves_like 'showing user with thier organization name'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with call direction in' do
|
|
|
|
let(:first_params) { params.merge(event: 'newCall', direction: 'in') }
|
|
|
|
let(:second_params) { params.merge(event: 'hangup', direction: 'in') }
|
|
|
|
|
|
|
|
it_behaves_like 'showing user with thier organization name'
|
|
|
|
end
|
2020-08-17 13:37:55 +00:00
|
|
|
end
|
|
|
|
end
|