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
|
|
|
|
|
2019-01-17 10:19:20 +00:00
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe Cti::Log do
|
2019-07-09 22:07:32 +00:00
|
|
|
|
subject(:user) { create(:user, roles: Role.where(name: 'Agent'), phone: phone) }
|
|
|
|
|
|
|
|
|
|
let(:phone) { '' }
|
|
|
|
|
let(:log) { create(:'cti/log') }
|
2019-01-17 10:19:20 +00:00
|
|
|
|
|
|
|
|
|
describe '.log' do
|
|
|
|
|
it 'returns a hash with :list and :assets keys' do
|
2019-07-09 22:07:32 +00:00
|
|
|
|
expect(described_class.log(user)).to match(hash_including(:list, :assets))
|
2019-01-17 10:19:20 +00:00
|
|
|
|
end
|
|
|
|
|
|
2021-05-12 10:31:00 +00:00
|
|
|
|
context 'when pretty is not generated' do
|
|
|
|
|
let(:log) { create(:'cti/log') }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
log.update_column(:preferences, nil)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'does fallback generate the pretty value' do
|
|
|
|
|
expect(log.reload.attributes['from_pretty']).to eq('+49 30 609854180')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-01-17 10:19:20 +00:00
|
|
|
|
context 'when over 60 Log records exist' do
|
2019-04-07 15:23:03 +00:00
|
|
|
|
subject!(:cti_logs) do
|
|
|
|
|
61.times.map do |_i| # rubocop:disable Performance/TimesMap
|
|
|
|
|
travel 1.second
|
|
|
|
|
create(:'cti/log')
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-01-17 10:19:20 +00:00
|
|
|
|
|
|
|
|
|
it 'returns the 60 latest ones in the :list key' do
|
2019-07-09 22:07:32 +00:00
|
|
|
|
expect(described_class.log(user)[:list]).to match_array(cti_logs.last(60))
|
2019-01-17 10:19:20 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when Log records have arrays of CallerId attributes in #preferences[:to] / #preferences[:from]' do
|
|
|
|
|
subject!(:cti_log) { create(:'cti/log', preferences: { from: [caller_id] }) }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-01-17 10:19:20 +00:00
|
|
|
|
let(:caller_id) { create(:caller_id) }
|
2019-07-09 22:07:32 +00:00
|
|
|
|
let(:caller_user) { User.find_by(id: caller_id.user_id) }
|
2019-01-17 10:19:20 +00:00
|
|
|
|
|
|
|
|
|
it 'returns a hash of the CallerId Users and their assets in the :assets key' do
|
2019-07-09 22:07:32 +00:00
|
|
|
|
expect(described_class.log(user)[:assets]).to eq(caller_user.assets({}))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when a notify map is defined' do
|
|
|
|
|
subject!(:cti_logs) do
|
|
|
|
|
[create(:'cti/log', queue: 'queue0'),
|
|
|
|
|
create(:'cti/log', queue: 'queue2'),
|
|
|
|
|
create(:'cti/log', queue: 'queue3'),
|
|
|
|
|
create(:'cti/log', queue: 'queue4')]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
cti_config = Setting.get('cti_config')
|
|
|
|
|
cti_config[:notify_map] = [ { queue: 'queue4', user_ids: [user.id.to_s] } ]
|
|
|
|
|
Setting.set('cti_config', cti_config)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'returns one matching log record' do
|
|
|
|
|
|
|
|
|
|
expect(described_class.log(user)[:list]).to match_array([cti_logs[3]])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.push_caller_list_update?' do
|
|
|
|
|
let!(:existing_logs) { create_list(:'cti/log', 60) }
|
|
|
|
|
let(:log) { create(:'cti/log') }
|
|
|
|
|
|
|
|
|
|
context 'when given log is older than existing logs' do
|
|
|
|
|
before { travel(-10.seconds) }
|
|
|
|
|
|
|
|
|
|
it 'return false' do
|
2022-03-01 08:00:40 +00:00
|
|
|
|
expect(described_class.push_caller_list_update?(log)).to be false
|
2019-07-09 22:07:32 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when given log is newer than existing logs' do
|
|
|
|
|
before { travel(10.seconds) }
|
|
|
|
|
|
|
|
|
|
it 'return true' do
|
2022-03-01 08:00:40 +00:00
|
|
|
|
expect(described_class.push_caller_list_update?(log)).to be true
|
2019-01-17 10:19:20 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.process' do
|
2019-01-18 02:26:15 +00:00
|
|
|
|
let(:attributes) do
|
|
|
|
|
{
|
2019-02-04 15:42:18 +00:00
|
|
|
|
'cause' => cause,
|
2019-01-18 02:26:15 +00:00
|
|
|
|
'event' => event,
|
|
|
|
|
'user' => 'user 1',
|
|
|
|
|
'from' => '49123456',
|
|
|
|
|
'to' => '49123457',
|
|
|
|
|
'call_id' => '1',
|
|
|
|
|
'direction' => 'in',
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
2019-02-04 15:42:18 +00:00
|
|
|
|
let(:cause) { '' }
|
|
|
|
|
|
2019-01-17 10:19:20 +00:00
|
|
|
|
context 'for event "newCall"' do
|
2019-01-18 02:26:15 +00:00
|
|
|
|
let(:event) { 'newCall' }
|
|
|
|
|
|
|
|
|
|
context 'with unrecognized "call_id"' do
|
2019-07-09 22:07:32 +00:00
|
|
|
|
it 'creates a new Log record' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect { described_class.process(attributes) }
|
|
|
|
|
.to change(described_class, :count).by(1)
|
2019-01-18 02:26:15 +00:00
|
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect(described_class.last.attributes)
|
2019-07-09 22:07:32 +00:00
|
|
|
|
.to include(
|
|
|
|
|
'call_id' => '1',
|
|
|
|
|
'state' => 'newCall',
|
|
|
|
|
'done' => false,
|
|
|
|
|
'queue' => '49123457',
|
|
|
|
|
'from' => '49123456',
|
|
|
|
|
'from_comment' => nil,
|
2021-07-01 11:23:52 +00:00
|
|
|
|
'from_pretty' => '+49 491 23456',
|
2019-07-09 22:07:32 +00:00
|
|
|
|
'start_at' => nil,
|
|
|
|
|
'end_at' => nil,
|
|
|
|
|
'to' => '49123457',
|
|
|
|
|
'to_comment' => 'user 1',
|
2021-07-01 11:23:52 +00:00
|
|
|
|
'to_pretty' => '+49 491 23457'
|
2019-07-09 22:07:32 +00:00
|
|
|
|
)
|
2019-01-18 02:26:15 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for direction "in", with a CallerId record matching the "from" number' do
|
|
|
|
|
let!(:caller_id) { create(:caller_id, caller_id: '49123456') }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
before { attributes.merge!('direction' => 'in') }
|
|
|
|
|
|
|
|
|
|
it 'saves that CallerId’s attributes in the new Log’s #preferences[:from] attribute' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
described_class.process(attributes)
|
2019-01-18 02:26:15 +00:00
|
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect(described_class.last.preferences[:from].first)
|
2019-01-18 02:26:15 +00:00
|
|
|
|
.to include(caller_id.attributes.except('created_at')) # Checking equality of Time objects is error-prone
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for direction "out", with a CallerId record matching the "to" number' do
|
|
|
|
|
let!(:caller_id) { create(:caller_id, caller_id: '49123457') }
|
2019-04-15 01:41:17 +00:00
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
before { attributes.merge!('direction' => 'out') }
|
|
|
|
|
|
|
|
|
|
it 'saves that CallerId’s attributes in the new Log’s #preferences[:to] attribute' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
described_class.process(attributes)
|
2019-01-18 02:26:15 +00:00
|
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect(described_class.last.preferences[:to].first)
|
2019-01-18 02:26:15 +00:00
|
|
|
|
.to include(caller_id.attributes.except('created_at')) # Checking equality of Time objects is error-prone
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-01-17 10:19:20 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
context 'with recognized "call_id"' do
|
|
|
|
|
before { create(:'cti/log', call_id: '1') }
|
|
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2021-05-12 11:37:44 +00:00
|
|
|
|
expect { described_class.process(attributes) }.to raise_error(%r{call_id \S+ already exists!})
|
2019-01-18 02:26:15 +00:00
|
|
|
|
end
|
2019-01-17 10:19:20 +00:00
|
|
|
|
end
|
2019-01-18 02:26:15 +00:00
|
|
|
|
end
|
2019-01-17 10:19:20 +00:00
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
context 'for event "answer"' do
|
|
|
|
|
let(:event) { 'answer' }
|
|
|
|
|
|
|
|
|
|
context 'with unrecognized "call_id"' do
|
|
|
|
|
it 'raises an error' do
|
2021-05-12 11:37:44 +00:00
|
|
|
|
expect { described_class.process(attributes) }.to raise_error(%r{No such call_id})
|
2019-01-18 02:26:15 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-01-17 10:19:20 +00:00
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
context 'with recognized "call_id"' do
|
2019-02-04 15:42:18 +00:00
|
|
|
|
context 'for Log with #state "newCall"' do
|
|
|
|
|
let(:log) { create(:'cti/log', call_id: 1, state: 'newCall', done: false) }
|
|
|
|
|
|
|
|
|
|
it 'returns early with no changes' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect { described_class.process(attributes) }
|
2019-02-04 15:42:18 +00:00
|
|
|
|
.to change { log.reload.state }.to('answer')
|
|
|
|
|
.and change { log.reload.done }.to(true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
context 'for Log with #state "hangup"' do
|
|
|
|
|
let(:log) { create(:'cti/log', call_id: 1, state: 'hangup', done: false) }
|
2019-01-17 10:19:20 +00:00
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
it 'returns early with no changes' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect { described_class.process(attributes) }
|
|
|
|
|
.not_to change(log, :reload)
|
2019-01-18 02:26:15 +00:00
|
|
|
|
end
|
2019-01-17 10:19:20 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-01-18 02:26:15 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for event "hangup"' do
|
|
|
|
|
let(:event) { 'hangup' }
|
2019-01-17 10:19:20 +00:00
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
context 'with unrecognized "call_id"' do
|
|
|
|
|
it 'raises an error' do
|
2021-05-12 11:37:44 +00:00
|
|
|
|
expect { described_class.process(attributes) }.to raise_error(%r{No such call_id})
|
2019-01-18 02:26:15 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2019-01-17 10:19:20 +00:00
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
context 'with recognized "call_id"' do
|
|
|
|
|
context 'for Log with #state "newCall"' do
|
2019-02-04 15:42:18 +00:00
|
|
|
|
let(:log) { create(:'cti/log', call_id: 1, state: 'newCall', done: false) }
|
2019-01-17 10:19:20 +00:00
|
|
|
|
|
2019-01-18 02:26:15 +00:00
|
|
|
|
it 'sets attributes #state: "hangup", #done: false' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect { described_class.process(attributes) }
|
2019-02-04 15:42:18 +00:00
|
|
|
|
.to change { log.reload.state }.to('hangup')
|
|
|
|
|
.and not_change { log.reload.done }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when call is forwarded' do
|
|
|
|
|
let(:cause) { 'forwarded' }
|
|
|
|
|
|
|
|
|
|
it 'sets attributes #state: "hangup", #done: true' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect { described_class.process(attributes) }
|
2019-02-04 15:42:18 +00:00
|
|
|
|
.to change { log.reload.state }.to('hangup')
|
|
|
|
|
.and change { log.reload.done }.to(true)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'for Log with #state "answer"' do
|
|
|
|
|
let(:log) { create(:'cti/log', call_id: 1, state: 'answer', done: true) }
|
|
|
|
|
|
|
|
|
|
it 'sets attributes #state: "hangup"' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect { described_class.process(attributes) }
|
2019-02-04 15:42:18 +00:00
|
|
|
|
.to change { log.reload.state }.to('hangup')
|
|
|
|
|
.and not_change { log.reload.done }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when call is sent to voicemail' do
|
|
|
|
|
before { log.update(to_comment: 'voicemail') }
|
|
|
|
|
|
|
|
|
|
it 'sets attributes #state: "hangup", #done: false' do
|
2019-04-15 01:41:17 +00:00
|
|
|
|
expect { described_class.process(attributes) }
|
2019-02-04 15:42:18 +00:00
|
|
|
|
.to change { log.reload.state }.to('hangup')
|
|
|
|
|
.and change { log.reload.done }.to(false)
|
|
|
|
|
end
|
2019-01-18 02:26:15 +00:00
|
|
|
|
end
|
2019-01-17 10:19:20 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-07-09 22:07:32 +00:00
|
|
|
|
|
|
|
|
|
context 'for preferences.from verification' do
|
|
|
|
|
subject(:log) do
|
|
|
|
|
described_class.process(attributes)
|
|
|
|
|
end
|
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let(:customer_of_ticket) { create(:customer) }
|
2019-07-09 22:07:32 +00:00
|
|
|
|
let(:ticket_sample) do
|
2020-06-19 09:17:18 +00:00
|
|
|
|
create(:ticket_article, created_by_id: customer_of_ticket.id, body: 'some text 0123457')
|
2021-05-20 06:59:02 +00:00
|
|
|
|
TransactionDispatcher.commit
|
2019-07-09 22:07:32 +00:00
|
|
|
|
Scheduler.worker(true)
|
|
|
|
|
end
|
|
|
|
|
let(:caller_id) { '0123456' }
|
|
|
|
|
let(:attributes) do
|
|
|
|
|
{
|
|
|
|
|
'cause' => '',
|
|
|
|
|
'event' => 'newCall',
|
|
|
|
|
'user' => 'user 1',
|
|
|
|
|
'from' => caller_id,
|
|
|
|
|
'to' => '49123450',
|
|
|
|
|
'call_id' => '1',
|
|
|
|
|
'direction' => 'in',
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with now related customer' do
|
|
|
|
|
it 'gives no caller information' do
|
2022-03-01 08:00:40 +00:00
|
|
|
|
expect(log.preferences[:from]).to be_nil
|
2019-07-09 22:07:32 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with related known customer' do
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let!(:customer) { create(:customer, phone: '0123456') }
|
2019-07-09 22:07:32 +00:00
|
|
|
|
|
|
|
|
|
it 'gives caller information' do
|
|
|
|
|
expect(log.preferences[:from].count).to eq(1)
|
|
|
|
|
expect(log.preferences[:from].first)
|
|
|
|
|
.to include(
|
|
|
|
|
'level' => 'known',
|
2020-06-19 09:17:18 +00:00
|
|
|
|
'user_id' => customer.id,
|
2019-07-09 22:07:32 +00:00
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with related known customers' do
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let!(:customer1) { create(:customer, phone: '0123456') }
|
|
|
|
|
let!(:customer2) { create(:customer, phone: '0123456') }
|
2019-07-09 22:07:32 +00:00
|
|
|
|
|
|
|
|
|
it 'gives caller information' do
|
|
|
|
|
expect(log.preferences[:from].count).to eq(2)
|
|
|
|
|
expect(log.preferences[:from].first)
|
|
|
|
|
.to include(
|
|
|
|
|
'level' => 'known',
|
2020-06-19 09:17:18 +00:00
|
|
|
|
'user_id' => customer2.id,
|
2019-07-09 22:07:32 +00:00
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with related maybe customer' do
|
|
|
|
|
let(:caller_id) { '0123457' }
|
|
|
|
|
let!(:ticket) { ticket_sample }
|
|
|
|
|
|
|
|
|
|
it 'gives caller information' do
|
|
|
|
|
expect(log.preferences[:from].count).to eq(1)
|
|
|
|
|
expect(log.preferences[:from].first)
|
|
|
|
|
.to include(
|
|
|
|
|
'level' => 'maybe',
|
2020-06-19 09:17:18 +00:00
|
|
|
|
'user_id' => customer_of_ticket.id,
|
2019-07-09 22:07:32 +00:00
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with related maybe and known customer' do
|
|
|
|
|
let(:caller_id) { '0123457' }
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let!(:customer) { create(:customer, phone: '0123457') }
|
2019-07-09 22:07:32 +00:00
|
|
|
|
let!(:ticket) { ticket_sample }
|
|
|
|
|
|
|
|
|
|
it 'gives caller information' do
|
|
|
|
|
expect(log.preferences[:from].count).to eq(1)
|
|
|
|
|
expect(log.preferences[:from].first)
|
|
|
|
|
.to include(
|
|
|
|
|
'level' => 'known',
|
|
|
|
|
'user_id' => customer.id,
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-01-17 10:19:20 +00:00
|
|
|
|
end
|
|
|
|
|
|
2019-01-18 00:04:39 +00:00
|
|
|
|
describe 'Callbacks -' do
|
|
|
|
|
describe 'Updating agent sessions:' do
|
|
|
|
|
before { allow(Sessions).to receive(:send_to).with(any_args) }
|
|
|
|
|
|
|
|
|
|
context 'on creation' do
|
|
|
|
|
it 'pushes "cti_list_push" event' do
|
|
|
|
|
User.with_permissions('cti.agent').each do |u|
|
|
|
|
|
expect(Sessions).to receive(:send_to).with(u.id, { event: 'cti_list_push' })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
create(:cti_log)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with over 60 existing Log records' do
|
|
|
|
|
before { create_list(:cti_log, 60) }
|
|
|
|
|
|
|
|
|
|
it '(always) pushes "cti_list_push" event' do
|
|
|
|
|
User.with_permissions('cti.agent').each do |u|
|
|
|
|
|
expect(Sessions).to receive(:send_to).with(u.id, { event: 'cti_list_push' })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
create(:cti_log)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'on update' do
|
|
|
|
|
subject!(:log) { create(:cti_log) }
|
|
|
|
|
|
|
|
|
|
it 'pushes "cti_list_push" event' do
|
|
|
|
|
User.with_permissions('cti.agent').each do |u|
|
|
|
|
|
expect(Sessions).to receive(:send_to).with(u.id, { event: 'cti_list_push' })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
log.touch
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when among the latest 60 Log records' do
|
|
|
|
|
before { create_list(:cti_log, 59) }
|
|
|
|
|
|
|
|
|
|
it 'pushes "cti_list_push" event' do
|
|
|
|
|
User.with_permissions('cti.agent').each do |u|
|
|
|
|
|
expect(Sessions).to receive(:send_to).with(u.id, { event: 'cti_list_push' })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
log.touch
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when not among the latest 60 Log records' do
|
|
|
|
|
before { create_list(:cti_log, 60) }
|
|
|
|
|
|
|
|
|
|
it 'does NOT push "cti_list_push" event' do
|
|
|
|
|
User.with_permissions('cti.agent').each do |u|
|
|
|
|
|
expect(Sessions).not_to receive(:send_to).with(u.id, { event: 'cti_list_push' })
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
log.touch
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-01-17 10:19:20 +00:00
|
|
|
|
describe '#from_pretty' do
|
|
|
|
|
context 'with complete, E164 international numbers' do
|
|
|
|
|
subject(:log) { create(:cti_log, from: '4930609854180') }
|
|
|
|
|
|
|
|
|
|
it 'gives the number in prettified format' do
|
|
|
|
|
expect(log.from_pretty).to eq('+49 30 609854180')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with private network numbers' do
|
|
|
|
|
subject(:log) { create(:cti_log, from: '007') }
|
|
|
|
|
|
|
|
|
|
it 'gives the number unaltered' do
|
|
|
|
|
expect(log.from_pretty).to eq('007')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#to_pretty' do
|
|
|
|
|
context 'with complete, E164 international numbers' do
|
|
|
|
|
subject(:log) { create(:cti_log, to: '4930609811111') }
|
|
|
|
|
|
|
|
|
|
it 'gives the number in prettified format' do
|
|
|
|
|
expect(log.to_pretty).to eq('+49 30 609811111')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with private network numbers' do
|
|
|
|
|
subject(:log) { create(:cti_log, to: '008') }
|
|
|
|
|
|
|
|
|
|
it 'gives the number unaltered' do
|
|
|
|
|
expect(log.to_pretty).to eq('008')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-07-09 22:07:32 +00:00
|
|
|
|
describe '.queues_of_user' do
|
|
|
|
|
context 'without notify_map and no own phone number' do
|
|
|
|
|
it 'gives an empty array' do
|
|
|
|
|
expect(described_class.queues_of_user(user, Setting.get('cti_config'))).to eq([])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with notify_map and no own phone number' do
|
|
|
|
|
before do
|
|
|
|
|
cti_config = Setting.get('cti_config')
|
|
|
|
|
cti_config[:notify_map] = [ { queue: 'queue4', user_ids: [user.id.to_s] } ]
|
|
|
|
|
Setting.set('cti_config', cti_config)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'gives an array with queue' do
|
|
|
|
|
expect(described_class.queues_of_user(user, Setting.get('cti_config'))).to eq(['queue4'])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with notify_map and with own phone number' do
|
|
|
|
|
let(:phone) { '012345678' }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
cti_config = Setting.get('cti_config')
|
|
|
|
|
cti_config[:notify_map] = [ { queue: 'queue4', user_ids: [user.id.to_s] } ]
|
|
|
|
|
Setting.set('cti_config', cti_config)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'gives an array with queue and phone number' do
|
|
|
|
|
expect(described_class.queues_of_user(user, Setting.get('cti_config'))).to eq(%w[queue4 4912345678])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#best_customer_id_of_log_entry' do
|
|
|
|
|
subject(:log1) do
|
|
|
|
|
described_class.process(
|
|
|
|
|
'event' => 'newCall',
|
|
|
|
|
'user' => 'user 1',
|
|
|
|
|
'from' => '01234599',
|
|
|
|
|
'to' => '49123450',
|
|
|
|
|
'call_id' => '1',
|
|
|
|
|
'direction' => 'in',
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let!(:agent1) { create(:agent, phone: '01234599') }
|
|
|
|
|
let!(:customer2) { create(:customer, phone: '') }
|
2019-07-09 22:07:32 +00:00
|
|
|
|
let!(:ticket_article1) { create(:ticket_article, created_by_id: customer2.id, body: 'some text 01234599') }
|
|
|
|
|
|
|
|
|
|
context 'with agent1 (known), customer1 (known) and customer2 (maybe)' do
|
2020-06-19 09:17:18 +00:00
|
|
|
|
let!(:customer1) { create(:customer, phone: '01234599') }
|
2019-07-09 22:07:32 +00:00
|
|
|
|
|
|
|
|
|
it 'gives customer1' do
|
|
|
|
|
expect(log1.best_customer_id_of_log_entry).to eq(customer1.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with agent1 (known) and customer2 (maybe)' do
|
|
|
|
|
it 'gives customer2' do
|
|
|
|
|
expect(log1.best_customer_id_of_log_entry).to eq(agent1.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-01-17 10:19:20 +00:00
|
|
|
|
describe '#to_json' do
|
|
|
|
|
it 'includes virtual attributes' do
|
|
|
|
|
expect(log.as_json).to include('from_pretty', 'to_pretty')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|