cti_caller_id_test.rb 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class CtiCallerIdTest < ActiveSupport::TestCase
  4. test '2 lookups' do
  5. Ticket.destroy_all
  6. Cti::CallerId.destroy_all
  7. agent1 = User.create_or_update(
  8. login: 'ticket-caller_id-agent1@example.com',
  9. firstname: 'CallerId',
  10. lastname: 'Agent1',
  11. email: 'ticket-caller_id-agent1@example.com',
  12. password: 'agentpw',
  13. active: true,
  14. phone: '+49 1111 222222',
  15. fax: '+49 1111 222223',
  16. mobile: '+49 1111 222223',
  17. note: 'Phone at home: +49 1111 222224',
  18. updated_by_id: 1,
  19. created_by_id: 1,
  20. )
  21. agent2 = User.create_or_update(
  22. login: 'ticket-caller_id-agent2@example.com',
  23. firstname: 'CallerId',
  24. lastname: 'Agent2',
  25. email: 'ticket-caller_id-agent2@example.com',
  26. password: 'agentpw',
  27. phone: '+49 2222 222222',
  28. note: 'Phone at home: <b>+49 2222 222224</b>',
  29. active: true,
  30. updated_by_id: 1,
  31. created_by_id: 1,
  32. )
  33. agent3 = User.create_or_update(
  34. login: 'ticket-caller_id-agent3@example.com',
  35. firstname: 'CallerId',
  36. lastname: 'Agent3',
  37. email: 'ticket-caller_id-agent3@example.com',
  38. password: 'agentpw',
  39. phone: '+49 2222 222222',
  40. active: true,
  41. updated_by_id: 1,
  42. created_by_id: 1,
  43. )
  44. customer1 = User.create_or_update(
  45. login: 'ticket-caller_id-customer1@example.com',
  46. firstname: 'CallerId',
  47. lastname: 'Customer1',
  48. email: 'ticket-caller_id-customer1@example.com',
  49. password: 'customerpw',
  50. active: true,
  51. updated_by_id: 1,
  52. created_by_id: 1,
  53. )
  54. Cti::CallerId.rebuild
  55. caller_ids = Cti::CallerId.lookup('491111222277')
  56. assert_equal(0, caller_ids.length)
  57. caller_ids = Cti::CallerId.lookup('491111222223')
  58. assert_equal(1, caller_ids.length)
  59. assert_equal(agent1.id, caller_ids[0].user_id)
  60. assert_equal('known', caller_ids[0].level)
  61. caller_ids = Cti::CallerId.lookup('492222222222')
  62. assert_equal(2, caller_ids.length)
  63. assert_equal(agent3.id, caller_ids[0].user_id)
  64. assert_equal('known', caller_ids[0].level)
  65. assert_equal(agent2.id, caller_ids[1].user_id)
  66. assert_equal('known', caller_ids[1].level)
  67. # create ticket in group
  68. ticket1 = Ticket.create(
  69. title: 'some caller id test 1',
  70. group: Group.lookup(name: 'Users'),
  71. customer: customer1,
  72. state: Ticket::State.lookup(name: 'new'),
  73. priority: Ticket::Priority.lookup(name: '2 normal'),
  74. updated_by_id: agent1.id,
  75. created_by_id: agent1.id,
  76. )
  77. article1 = Ticket::Article.create(
  78. ticket_id: ticket1.id,
  79. from: 'some_sender@example.com',
  80. to: 'some_recipient@example.com',
  81. subject: 'some subject',
  82. message_id: 'some@id',
  83. body: "some message\nFon (GEL): +49 111 366-1111 Mi-Fr
  84. Fon (LIN): +49 222 6112222 Mo-Di
  85. Mob: +49 333 8362222",
  86. internal: false,
  87. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  88. type: Ticket::Article::Type.where(name: 'email').first,
  89. updated_by_id: customer1.id,
  90. created_by_id: customer1.id,
  91. )
  92. assert(ticket1)
  93. # create ticket in group
  94. ticket2 = Ticket.create(
  95. title: 'some caller id test 2',
  96. group: Group.lookup(name: 'Users'),
  97. customer: customer1,
  98. state: Ticket::State.lookup(name: 'new'),
  99. priority: Ticket::Priority.lookup(name: '2 normal'),
  100. updated_by_id: agent1.id,
  101. created_by_id: agent1.id,
  102. )
  103. article2 = Ticket::Article.create(
  104. ticket_id: ticket2.id,
  105. from: 'some_sender@example.com',
  106. to: 'some_recipient@example.com',
  107. subject: 'some subject',
  108. message_id: 'some@id',
  109. body: "some message\nFon (GEL): +49 111 111-1111 Mi-Fr
  110. Fon (LIN): +49 222 1112222 Mo-Di
  111. Mob: +49 333 1112222",
  112. internal: false,
  113. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  114. type: Ticket::Article::Type.where(name: 'email').first,
  115. updated_by_id: agent1.id,
  116. created_by_id: agent1.id,
  117. )
  118. assert(ticket2)
  119. Cti::CallerId.rebuild
  120. caller_ids = Cti::CallerId.lookup('491111222277')
  121. assert_equal(0, caller_ids.length)
  122. caller_ids = Cti::CallerId.lookup('491111222223')
  123. assert_equal(1, caller_ids.length)
  124. assert_equal(agent1.id, caller_ids[0].user_id)
  125. assert_equal('known', caller_ids[0].level)
  126. caller_ids = Cti::CallerId.lookup('492222222222')
  127. assert_equal(2, caller_ids.length)
  128. assert_equal(agent3.id, caller_ids[0].user_id)
  129. assert_equal('known', caller_ids[0].level)
  130. assert_equal(agent2.id, caller_ids[1].user_id)
  131. assert_equal('known', caller_ids[1].level)
  132. caller_ids = Cti::CallerId.lookup('492226112222')
  133. assert_equal(1, caller_ids.length)
  134. assert_equal(customer1.id, caller_ids[0].user_id)
  135. assert_equal('maybe', caller_ids[0].level)
  136. caller_ids = Cti::CallerId.lookup('492221112222')
  137. assert_equal(0, caller_ids.length)
  138. end
  139. test '3 lookups' do
  140. Cti::CallerId.destroy_all
  141. Cti::CallerId.maybe_add(
  142. caller_id: '4999999999',
  143. level: 'maybe',
  144. user_id: 2,
  145. object: 'Ticket',
  146. o_id: 2,
  147. )
  148. Cti::CallerId.maybe_add(
  149. caller_id: '4912345678901',
  150. comment: 'Hairdresser Bob Smith, San Francisco',
  151. level: 'public',
  152. user_id: 2,
  153. object: 'GoYello',
  154. o_id: 1,
  155. )
  156. caller_ids = Cti::CallerId.lookup('4912345678901')
  157. assert_equal(1, caller_ids.length)
  158. assert_equal('public', caller_ids[0].level)
  159. assert_equal(2, caller_ids[0].user_id)
  160. assert_equal('Hairdresser Bob Smith, San Francisco', caller_ids[0].comment)
  161. Cti::CallerId.maybe_add(
  162. caller_id: '4912345678901',
  163. level: 'maybe',
  164. user_id: 2,
  165. object: 'Ticket',
  166. o_id: 2,
  167. )
  168. caller_ids = Cti::CallerId.lookup('4912345678901')
  169. assert_equal(1, caller_ids.length)
  170. assert_equal('maybe', caller_ids[0].level)
  171. assert_equal(2, caller_ids[0].user_id)
  172. assert_equal(nil, caller_ids[0].comment)
  173. Cti::CallerId.maybe_add(
  174. caller_id: '4912345678901',
  175. level: 'maybe',
  176. user_id: 2,
  177. object: 'Ticket',
  178. o_id: 2,
  179. )
  180. caller_ids = Cti::CallerId.lookup('4912345678901')
  181. assert_equal(1, caller_ids.length)
  182. assert_equal('maybe', caller_ids[0].level)
  183. assert_equal(2, caller_ids[0].user_id)
  184. assert_equal(nil, caller_ids[0].comment)
  185. Cti::CallerId.maybe_add(
  186. caller_id: '4912345678901',
  187. level: 'maybe',
  188. user_id: 3,
  189. object: 'Ticket',
  190. o_id: 2,
  191. )
  192. caller_ids = Cti::CallerId.lookup('4912345678901')
  193. assert_equal(2, caller_ids.length)
  194. assert_equal('maybe', caller_ids[0].level)
  195. assert_equal(3, caller_ids[0].user_id)
  196. assert_equal(nil, caller_ids[0].comment)
  197. assert_equal('maybe', caller_ids[1].level)
  198. assert_equal(2, caller_ids[1].user_id)
  199. assert_equal(nil, caller_ids[1].comment)
  200. Cti::CallerId.maybe_add(
  201. caller_id: '4912345678901',
  202. level: 'known',
  203. user_id: 3,
  204. object: 'User',
  205. o_id: 2,
  206. )
  207. caller_ids = Cti::CallerId.lookup('4912345678901')
  208. assert_equal(1, caller_ids.length)
  209. assert_equal('known', caller_ids[0].level)
  210. assert_equal(3, caller_ids[0].user_id)
  211. assert_equal(nil, caller_ids[0].comment)
  212. end
  213. end