integration_cti_test.rb 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. # flanky
  43. watch_for(
  44. css: '.js-phoneMenuItem .counter',
  45. value: (call_counter + 1).to_s,
  46. timeout: 4,
  47. )
  48. check(css: '.content.active .table-checkbox input')
  49. watch_for_disappear(
  50. css: '.js-phoneMenuItem .counter',
  51. timeout: 6,
  52. )
  53. click(css: 'a[href="#manage"]')
  54. click(css: 'a[href="#system/integration"]')
  55. click(css: 'a[href="#system/integration/cti"]')
  56. switch(
  57. css: '.content.active .js-switch',
  58. type: 'off'
  59. )
  60. end
  61. # Regression test for #2018
  62. def test_e164_numbers_displayed_in_prettified_format
  63. id = rand(99_999_999)
  64. @browser = browser_instance
  65. login(
  66. username: 'master@example.com',
  67. password: 'test',
  68. url: browser_url,
  69. )
  70. click(css: 'a[href="#manage"]')
  71. click(css: 'a[href="#system/integration"]')
  72. click(css: 'a[href="#system/integration/cti"]')
  73. switch(
  74. css: '.content.active .js-switch',
  75. type: 'on'
  76. )
  77. watch_for(
  78. css: 'a[href="#cti"]'
  79. )
  80. click(css: 'a[href="#cti"]')
  81. # simulate cti callbacks...
  82. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  83. # ...for private network number
  84. params = {
  85. direction: 'in',
  86. from: '007',
  87. to: '008',
  88. callId: "4991155921769858278-#{id}",
  89. cause: 'busy'
  90. }
  91. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  92. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  93. # ...for e164 number
  94. params = {
  95. direction: 'in',
  96. from: '4930609854180',
  97. to: '4930609811111',
  98. callId: "4991155921769858278-#{id.next}",
  99. cause: 'busy'
  100. }
  101. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  102. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  103. # view caller log
  104. click(css: 'a[href="#cti"]')
  105. # assertion: private network numbers appear verbatim
  106. watch_for(
  107. css: '.content.active .js-callerLog',
  108. value: '007',
  109. timeout: 3,
  110. )
  111. match(
  112. css: '.content.active .js-callerLog',
  113. value: '008',
  114. )
  115. # assertion: E164 numbers appear prettified
  116. match(
  117. css: '.content.active .js-callerLog',
  118. value: '+49 30 609854180',
  119. )
  120. match(
  121. css: '.content.active .js-callerLog',
  122. value: '+49 30 609811111',
  123. )
  124. end
  125. # Regression test for #2096
  126. def test_inactive_users_displayed_inactive_in_caller_log
  127. id = rand(99_999_999)
  128. @browser = browser_instance
  129. login(
  130. username: 'master@example.com',
  131. password: 'test',
  132. url: browser_url,
  133. )
  134. # create inactive user with phone number (via API)
  135. user_create(
  136. data: {
  137. login: 'test_user',
  138. firstname: 'John',
  139. lastname: 'Doe',
  140. phone: '1234567890',
  141. active: false,
  142. },
  143. )
  144. # enable CTI
  145. click(css: 'a[href="#manage"]')
  146. click(css: 'a[href="#system/integration"]')
  147. click(css: 'a[href="#system/integration/cti"]')
  148. switch(
  149. css: '.content.active .js-switch',
  150. type: 'on'
  151. )
  152. watch_for(
  153. css: 'a[href="#cti"]'
  154. )
  155. click(css: 'a[href="#cti"]')
  156. # simulate CTI callback to/from inactive user
  157. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  158. params = {
  159. direction: 'in',
  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. # view caller log
  168. click(css: 'a[href="#cti"]')
  169. # assertion: names appear in inactive
  170. match(
  171. css: 'span.avatar--inactive',
  172. value: 'JD',
  173. )
  174. end
  175. # Regression test for #2075
  176. def test_caller_ids_include_organization_names
  177. id = rand(99_999_999)
  178. @browser = browser_instance
  179. login(
  180. username: 'master@example.com',
  181. password: 'test',
  182. url: browser_url,
  183. )
  184. # create user with organization (via API)
  185. user_create(
  186. data: {
  187. login: 'test_user',
  188. firstname: 'John',
  189. lastname: 'Doe',
  190. phone: '1234567890',
  191. organization: 'Zammad Foundation'
  192. },
  193. )
  194. # enable CTI
  195. click(css: 'a[href="#manage"]')
  196. click(css: 'a[href="#system/integration"]')
  197. click(css: 'a[href="#system/integration/cti"]')
  198. switch(
  199. css: '.content.active .js-switch',
  200. type: 'on'
  201. )
  202. watch_for(
  203. css: 'a[href="#cti"]'
  204. )
  205. # view caller log
  206. click(css: 'a[href="#cti"]')
  207. # simulate CTI callbacks to/from target user
  208. url = URI.join(browser_url, "api/v1/cti/#{ENV['CTI_TOKEN']}")
  209. params = {
  210. direction: 'out',
  211. from: '1234567890',
  212. to: '1234567890',
  213. callId: "4991155921769858278-#{id}",
  214. cause: 'busy'
  215. }
  216. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  217. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  218. params = {
  219. direction: 'in',
  220. from: '1234567890',
  221. to: '1234567890',
  222. callId: "4991155921769858278-#{id.next}",
  223. cause: 'busy'
  224. }
  225. Net::HTTP.post_form(url, params.merge(event: 'newCall'))
  226. Net::HTTP.post_form(url, params.merge(event: 'hangup'))
  227. watch_for(
  228. css: '.js-callerLog tr:nth-of-type(2)'
  229. )
  230. # assertions: Caller ID includes user organization
  231. match(
  232. css: '.js-callerLog tr:first-of-type div.user-popover',
  233. value: 'John Doe (Zammad Foundation)',
  234. )
  235. match(
  236. css: '.js-callerLog tr:last-of-type div.user-popover',
  237. value: 'John Doe (Zammad Foundation)',
  238. )
  239. end
  240. end