Refactoring: Migrate fifth test case in cti_caller_id_test.rb

This commit is contained in:
Ryan Lue 2019-01-18 08:04:39 +08:00 committed by Martin Edenhofer
parent d425b0fd19
commit a95c4e988d
2 changed files with 64 additions and 57 deletions

View file

@ -72,6 +72,70 @@ RSpec.describe Cti::Log do
end
end
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
describe '#from_pretty' do
context 'with complete, E164 international numbers' do
subject(:log) { create(:cti_log, from: '4930609854180') }

View file

@ -56,63 +56,6 @@ class CtiCallerIdTest < ActiveSupport::TestCase
Scheduler.worker(true)
end
test '5 probe if caller log need to be pushed' do
Cti::Log.process(
'cause' => '',
'event' => 'newCall',
'user' => 'user 1',
'from' => '491111222222',
'to' => '4930600000000',
'callId' => 'touch-loop-0',
'direction' => 'in',
)
assert(Cti::Log.push_caller_list_update?(Cti::Log.last))
65.times do |count|
travel 1.hour
Cti::Log.process(
'cause' => '',
'event' => 'newCall',
'user' => 'user 1',
'from' => '491111222222',
'to' => '4930600000000',
'callId' => "touch-loop-1-#{count}",
'direction' => 'in',
)
end
assert(Cti::Log.push_caller_list_update?(Cti::Log.last))
assert_not(Cti::Log.push_caller_list_update?(Cti::Log.first))
65.times do |count|
travel 1.minute
Cti::Log.process(
'cause' => '',
'event' => 'newCall',
'user' => 'user 1',
'from' => '491111222222',
'to' => '4930600000000',
'callId' => "touch-loop-2-#{count}",
'direction' => 'in',
)
end
assert(Cti::Log.push_caller_list_update?(Cti::Log.last))
assert_not(Cti::Log.push_caller_list_update?(Cti::Log.first))
travel 2.seconds
Cti::Log.process(
'cause' => '',
'event' => 'newCall',
'user' => 'user 1',
'from' => '491111222222',
'to' => '4930600000000',
'callId' => 'touch-loop-3-1',
'direction' => 'in',
)
assert(Cti::Log.push_caller_list_update?(Cti::Log.last))
end
test 'user delete with caller log rebuild' do
assert_equal(2, Cti::CallerId.where(user_id: @agent2.id).count)