cti_spec.rb 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Caller log', authenticated_as: :authenticate, type: :system do
  4. let(:agent_phone) { '0190111' }
  5. let(:customer_phone) { '0190333' }
  6. let(:cti_token) { 'token1234' }
  7. let(:agent) { create(:agent, phone: agent_phone) }
  8. let(:customer) { create(:customer, phone: customer_phone) }
  9. let(:cti_on) { true }
  10. let(:params) do
  11. {
  12. direction: 'in',
  13. from: customer.phone,
  14. to: agent_phone,
  15. callId: '111',
  16. cause: 'busy',
  17. }
  18. end
  19. let(:first_params) { params.merge(event: 'newCall') }
  20. let(:second_params) { params.merge(event: 'hangup') }
  21. let(:place_call) do
  22. post "#{Capybara.app_host}/api/v1/cti/#{cti_token}", params: first_params
  23. post "#{Capybara.app_host}/api/v1/cti/#{cti_token}", params: second_params
  24. end
  25. # Do the preperation before the authentication.
  26. def authenticate
  27. Setting.set('cti_integration', cti_on)
  28. Setting.set('cti_token', cti_token)
  29. agent
  30. end
  31. context 'when cti integration is on' do
  32. it 'shows the phone menu in nav bar' do
  33. visit '/'
  34. within '#navigation .menu' do
  35. expect(page).to have_link('Phone', href: '#cti')
  36. end
  37. end
  38. end
  39. context 'when cti integration is not on' do
  40. let(:cti_on) { false }
  41. it 'does not show the phone menu in nav bar' do
  42. visit '/'
  43. within '#navigation .menu' do
  44. expect(page).to have_no_link('Phone', href: '#cti')
  45. end
  46. end
  47. end
  48. context 'when a customer call is answered' do
  49. let(:second_params) { params.merge(event: 'answer', answeringNumber: agent_phone) }
  50. context 'without active tickets' do
  51. before do
  52. travel(-2.months)
  53. create(:ticket, customer: customer)
  54. travel_back
  55. visit 'cti'
  56. place_call
  57. end
  58. it 'opens a new ticket after phone call inbound' do
  59. within(:active_content) do
  60. expect(page).to have_text('New Ticket')
  61. end
  62. end
  63. end
  64. context 'with active tickets' do
  65. before do
  66. create(:ticket, customer: customer)
  67. visit 'cti'
  68. place_call
  69. end
  70. it 'opens the customer profile screen after phone call inbound with tickets in the last month' do
  71. within(:active_content) do
  72. expect(page).to have_text(customer.fullname)
  73. end
  74. end
  75. end
  76. end
  77. context 'with incoming call' do
  78. before do
  79. visit 'cti'
  80. place_call
  81. end
  82. it 'increments the call counter notification badge' do
  83. within '[href="#cti"].js-phoneMenuItem' do
  84. counter = find('.counter')
  85. expect(counter).to have_content 1
  86. end
  87. end
  88. end
  89. context 'when incoming call is checked' do
  90. before do
  91. visit 'cti'
  92. place_call
  93. end
  94. it 'clears the call counter notification badge' do
  95. within :active_content do
  96. find('.table-checkbox input.js-check', visible: :all).check allow_label_click: true
  97. end
  98. within '[href="#cti"].js-phoneMenuItem' do
  99. expect(page).to have_no_selector('.counter')
  100. end
  101. end
  102. end
  103. # Regression test for #2018
  104. context 'phone numbers format' do
  105. before do
  106. visit 'cti'
  107. place_call
  108. end
  109. context 'with private number' do
  110. let(:customer_phone) { '007' }
  111. let(:agent_phone) { '008' }
  112. it 'appears verbatim' do
  113. within :active_content do
  114. expect(page).to have_selector('.js-callerLog', text: customer_phone)
  115. .and have_selector('.js-callerLog', text: agent_phone)
  116. end
  117. end
  118. end
  119. context 'with e164 number' do
  120. let(:customer_phone) { '4930609854180' }
  121. let(:agent_phone) { '4930609811111' }
  122. let(:prettified_customer_phone) { '+49 30 609854180' }
  123. let(:prettified_current_user_phone) { '+49 30 609811111' }
  124. it 'appears prettified' do
  125. within :active_content do
  126. expect(page).to have_selector('.js-callerLog', text: prettified_customer_phone)
  127. .and have_selector('.js-callerLog', text: prettified_current_user_phone)
  128. end
  129. end
  130. it 'done not appear verbatim' do
  131. within :active_content do
  132. expect(page).to have_no_selector('.js-callerLog', text: customer_phone)
  133. end
  134. end
  135. end
  136. end
  137. # Regression test for #2096
  138. context 'with inactive user' do
  139. before do
  140. visit 'cti'
  141. place_call
  142. end
  143. let(:customer) do
  144. create(:customer,
  145. phone: customer_phone,
  146. active: false,
  147. firstname: 'John',
  148. lastname: 'Doe')
  149. end
  150. it 'appears inactive' do
  151. within :active_content do
  152. expect(page).to have_selector('span.avatar--inactive', text: 'JD')
  153. end
  154. end
  155. end
  156. # Regression test for #2075
  157. context 'when user is with organization name' do
  158. before do
  159. visit 'cti'
  160. place_call
  161. end
  162. let(:firstname) { 'John' }
  163. let(:lastname) { 'Doe' }
  164. let(:organization_name) { 'Test Organization' }
  165. let(:organization) { create(:organization, name: organization_name) }
  166. let(:full_name) { "#{firstname} #{lastname}" }
  167. let(:customer) do
  168. create(:customer,
  169. phone: customer_phone,
  170. firstname: firstname,
  171. lastname: lastname,
  172. organization: organization)
  173. end
  174. shared_examples 'showing user with thier organization name' do
  175. it 'shows user with thier organization name' do
  176. within :active_content do
  177. expect(page).to have_selector(
  178. '.js-callerLog tr div.user-popover',
  179. text: "#{full_name} (#{organization_name})"
  180. )
  181. end
  182. end
  183. end
  184. context 'with call direction out' do
  185. let(:first_params) { params.merge(event: 'newCall', direction: 'out', from: agent_phone, to: customer.phone) }
  186. let(:second_params) { params.merge(event: 'hangup', direction: 'out', from: agent_phone, to: customer.phone) }
  187. it_behaves_like 'showing user with thier organization name'
  188. end
  189. context 'with call direction in' do
  190. let(:first_params) { params.merge(event: 'newCall', direction: 'in') }
  191. let(:second_params) { params.merge(event: 'hangup', direction: 'in') }
  192. it_behaves_like 'showing user with thier organization name'
  193. end
  194. end
  195. end