integration_cti_test.rb 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. require 'browser_test_helper'
  2. class IntegrationCtiTest < TestCase
  3. setup do
  4. if !ENV['CTI_TOKEN']
  5. raise "ERROR: Need CTI_TOKEN - hint CTI_TOKEN='some_token'"
  6. end
  7. end
  8. # Regression test for #2017
  9. def test_nav_menu_notification_badge_clears
  10. id = rand(99_999_999)
  11. @browser = browser_instance
  12. login(
  13. username: 'master@example.com',
  14. password: 'test',
  15. url: browser_url,
  16. )
  17. click(css: 'a[href="#manage"]')
  18. click(css: 'a[href="#system/integration"]')
  19. click(css: 'a[href="#system/integration/cti"]')
  20. switch(
  21. css: '.content.active .js-switch',
  22. type: 'on'
  23. )
  24. watch_for(
  25. css: 'a[href="#cti"]',
  26. timeout: 4,
  27. )
  28. click(css: 'a[href="#cti"]')
  29. call_counter = @browser.find_elements(css: '.js-phoneMenuItem .counter')
  30. .first&.text.to_i
  31. # simulate cti callbacks
  32. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  33. params = {
  34. direction: 'in',
  35. from: '491715000002',
  36. to: '4930600000000',
  37. callId: "4991155921769858278-#{id}",
  38. cause: 'busy'
  39. }
  40. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  41. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  42. watch_for(
  43. css: '.js-phoneMenuItem .counter',
  44. value: (call_counter + 1).to_s,
  45. timeout: 4,
  46. )
  47. check(css: '.content.active .table-checkbox input')
  48. watch_for_disappear(
  49. css: '.js-phoneMenuItem .counter',
  50. timeout: 6,
  51. )
  52. click(css: 'a[href="#manage"]')
  53. click(css: 'a[href="#system/integration"]')
  54. click(css: 'a[href="#system/integration/cti"]')
  55. switch(
  56. css: '.content.active .js-switch',
  57. type: 'off'
  58. )
  59. end
  60. # Regression test for #2018
  61. def test_e164_numbers_displayed_in_prettified_format
  62. id = rand(99_999_999)
  63. @browser = browser_instance
  64. login(
  65. username: 'master@example.com',
  66. password: 'test',
  67. url: browser_url,
  68. )
  69. click(css: 'a[href="#manage"]')
  70. click(css: 'a[href="#system/integration"]')
  71. click(css: 'a[href="#system/integration/cti"]')
  72. switch(
  73. css: '.content.active .js-switch',
  74. type: 'on'
  75. )
  76. watch_for(
  77. css: 'a[href="#cti"]'
  78. )
  79. click(css: 'a[href="#cti"]')
  80. # simulate cti callbacks...
  81. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  82. # ...for private network number
  83. params = {
  84. direction: 'in',
  85. from: '007',
  86. to: '008',
  87. callId: "4991155921769858278-#{id}",
  88. cause: 'busy'
  89. }
  90. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  91. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  92. # ...for e164 number
  93. params = {
  94. direction: 'in',
  95. from: '4930609854180',
  96. to: '4930609811111',
  97. callId: "4991155921769858278-#{id.next}",
  98. cause: 'busy'
  99. }
  100. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  101. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  102. # view caller log
  103. click(css: 'a[href="#cti"]')
  104. # assertion: private network numbers appear verbatim
  105. watch_for(
  106. css: '.content.active .js-callerLog',
  107. value: '007',
  108. timeout: 3,
  109. )
  110. match(
  111. css: '.content.active .js-callerLog',
  112. value: '008',
  113. )
  114. # assertion: E164 numbers appear prettified
  115. match(
  116. css: '.content.active .js-callerLog',
  117. value: '+49 30 609854180',
  118. )
  119. match(
  120. css: '.content.active .js-callerLog',
  121. value: '+49 30 609811111',
  122. )
  123. end
  124. # Regression test for #2075
  125. def test_caller_ids_include_organization_names
  126. id = rand(99_999_999)
  127. @browser = browser_instance
  128. login(
  129. username: 'master@example.com',
  130. password: 'test',
  131. url: browser_url,
  132. )
  133. # create user with organization (via API)
  134. user_create(
  135. data: {
  136. login: 'test_user',
  137. firstname: 'John',
  138. lastname: 'Doe',
  139. phone: '1234567890',
  140. organization: 'Zammad Foundation'
  141. },
  142. )
  143. # enable CTI
  144. click(css: 'a[href="#manage"]')
  145. click(css: 'a[href="#system/integration"]')
  146. click(css: 'a[href="#system/integration/cti"]')
  147. switch(
  148. css: '.content.active .js-switch',
  149. type: 'on'
  150. )
  151. watch_for(
  152. css: 'a[href="#cti"]'
  153. )
  154. # view caller log
  155. click(css: 'a[href="#cti"]')
  156. # simulate CTI callbacks to/from target user
  157. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  158. params = {
  159. direction: 'out',
  160. from: '1234567890',
  161. to: '1234567890',
  162. callId: "4991155921769858278-#{id}",
  163. cause: 'busy'
  164. }
  165. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  166. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  167. params = {
  168. direction: 'in',
  169. from: '1234567890',
  170. to: '1234567890',
  171. callId: "4991155921769858278-#{id.next}",
  172. cause: 'busy'
  173. }
  174. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  175. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  176. watch_for(
  177. css: '.js-callerLog tr:nth-of-type(2)'
  178. )
  179. # assertions: Caller ID includes user organization
  180. match(
  181. css: '.js-callerLog tr:first-of-type span.user-popover',
  182. value: 'John Doe (Zammad Foundation)',
  183. )
  184. match(
  185. css: '.js-callerLog tr:last-of-type span.user-popover',
  186. value: 'John Doe (Zammad Foundation)',
  187. )
  188. end
  189. end