placetel_spec.rb 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. require 'rails_helper'
  2. RSpec.describe 'Integration Placetel', type: :request do
  3. let(:agent_user) do
  4. create(:agent_user)
  5. end
  6. let!(:customer_user1) do
  7. create(
  8. :customer_user,
  9. login: 'ticket-caller_id_cti-customer1@example.com',
  10. firstname: 'CallerId',
  11. lastname: 'Customer1',
  12. phone: '+49 99999 222222',
  13. fax: '+49 99999 222223',
  14. mobile: '+01114100300',
  15. note: 'Phone at home: +49 99999 222224',
  16. )
  17. end
  18. let!(:customer_user2) do
  19. create(
  20. :customer_user,
  21. login: 'ticket-caller_id_cti-customer2@example.com',
  22. firstname: 'CallerId',
  23. lastname: 'Customer2',
  24. phone: '+49 99999 222222 2',
  25. )
  26. end
  27. let!(:customer_user3) do
  28. create(
  29. :customer_user,
  30. login: 'ticket-caller_id_cti-customer3@example.com',
  31. firstname: 'CallerId',
  32. lastname: 'Customer3',
  33. phone: '+49 99999 222222 2',
  34. )
  35. end
  36. before(:each) do
  37. Cti::Log.destroy_all
  38. Setting.set('placetel_integration', true)
  39. Setting.set('placetel_config', {
  40. outbound: {
  41. routing_table: [
  42. {
  43. dest: '41*',
  44. caller_id: '41715880339000',
  45. },
  46. {
  47. dest: '491714000000',
  48. caller_id: '41715880339000',
  49. },
  50. ],
  51. default_caller_id: '4930777000000',
  52. },
  53. inbound: {
  54. block_caller_ids: [
  55. {
  56. caller_id: '491715000000',
  57. note: 'some note',
  58. }
  59. ],
  60. notify_user_ids: {
  61. 2 => true,
  62. 4 => false,
  63. },
  64. }
  65. })
  66. Cti::CallerId.rebuild
  67. end
  68. describe 'request handling' do
  69. it 'does token check' do
  70. params = 'event=IncomingCall&from=01114100300&to=030600000000&call_id=4991155921769858278-1'
  71. post '/api/v1/placetel/not_existing_token', params: params
  72. expect(response).to have_http_status(401)
  73. error = nil
  74. local_response = REXML::Document.new(response.body)
  75. local_response.elements.each('Response/Error') do |element|
  76. error = element.text
  77. end
  78. expect(error).to eq('Invalid token, please contact your admin!')
  79. end
  80. it 'does basic call' do
  81. token = Setting.get('placetel_token')
  82. # inbound - I
  83. params = 'event=IncomingCall&from=01114100300&to=030600000000&call_id=4991155921769858278-1'
  84. post "/api/v1/placetel/#{token}", params: params
  85. expect(response).to have_http_status(200)
  86. local_response = REXML::Document.new(response.body)
  87. expect(local_response.elements.count).to eq(1)
  88. expect(local_response.elements.first.to_s).to eq('<Response/>')
  89. # inbound - II - block caller
  90. params = 'event=IncomingCall&from=491715000000&to=030600000000&call_id=4991155921769858278-2'
  91. post "/api/v1/placetel/#{token}", params: params
  92. expect(response).to have_http_status(200)
  93. local_response = REXML::Document.new(response.body)
  94. reason = nil
  95. local_response.elements.each('Response/Reject') do |element|
  96. reason = element.attributes['reason']
  97. end
  98. expect(reason).to eq('busy')
  99. # outbound - I - set default_caller_id
  100. params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=8621106404543334274-3'
  101. post "/api/v1/placetel/#{token}", params: params
  102. expect(response).to have_http_status(200)
  103. caller_id = nil
  104. number_to_dail = nil
  105. lcoal_response = REXML::Document.new(response.body)
  106. lcoal_response.elements.each('Response/Dial') do |element|
  107. caller_id = element.attributes['callerId']
  108. end
  109. lcoal_response.elements.each('Response/Dial/Number') do |element|
  110. number_to_dail = element.text
  111. end
  112. expect(caller_id).to eq('4930777000000')
  113. expect(number_to_dail).to eq('01114100300')
  114. # outbound - II - set caller_id based on routing_table by explicite number
  115. params = 'event=newCall&direction=out&from=030600000000&to=491714000000&call_id=8621106404543334274-4'
  116. post "/api/v1/placetel/#{token}", params: params
  117. expect(response).to have_http_status(200)
  118. caller_id = nil
  119. number_to_dail = nil
  120. lcoal_response = REXML::Document.new(response.body)
  121. lcoal_response.elements.each('Response/Dial') do |element|
  122. caller_id = element.attributes['callerId']
  123. end
  124. lcoal_response.elements.each('Response/Dial/Number') do |element|
  125. number_to_dail = element.text
  126. end
  127. expect(caller_id).to eq('41715880339000')
  128. expect(number_to_dail).to eq('491714000000')
  129. # outbound - III - set caller_id based on routing_table by 41*
  130. params = 'event=newCall&direction=out&from=030600000000&to=4147110000000&call_id=8621106404543334274-5'
  131. post "/api/v1/placetel/#{token}", params: params
  132. expect(response).to have_http_status(200)
  133. caller_id = nil
  134. number_to_dail = nil
  135. lcoal_response = REXML::Document.new(response.body)
  136. lcoal_response.elements.each('Response/Dial') do |element|
  137. caller_id = element.attributes['callerId']
  138. end
  139. lcoal_response.elements.each('Response/Dial/Number') do |element|
  140. number_to_dail = element.text
  141. end
  142. expect(caller_id).to eq('41715880339000')
  143. expect(number_to_dail).to eq('4147110000000')
  144. # no config
  145. Setting.set('placetel_config', {})
  146. params = 'event=IncomingCall&from=01114100300&to=030600000000&call_id=4991155921769858278-6'
  147. post "/api/v1/placetel/#{token}", params: params
  148. expect(response).to have_http_status(422)
  149. error = nil
  150. local_response = REXML::Document.new(response.body)
  151. local_response.elements.each('Response/Error') do |element|
  152. error = element.text
  153. end
  154. expect(error).to eq('Feature not configured, please contact your admin!')
  155. end
  156. it 'does log call' do
  157. token = Setting.get('placetel_token')
  158. # outbound - I - new call
  159. params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=1234567890-1'
  160. post "/api/v1/placetel/#{token}", params: params
  161. expect(response).to have_http_status(200)
  162. log = Cti::Log.find_by(call_id: '1234567890-1')
  163. expect(log).to be_truthy
  164. expect(log.from).to eq('4930777000000')
  165. expect(log.to).to eq('01114100300')
  166. expect(log.direction).to eq('out')
  167. expect(log.from_comment).to eq(nil)
  168. expect(log.to_comment).to eq('CallerId Customer1')
  169. expect(log.comment).to be_nil
  170. expect(log.state).to eq('newCall')
  171. expect(log.done).to eq(true)
  172. expect(log.initialized_at).to be_truthy
  173. expect(log.start_at).to be_nil
  174. expect(log.end_at).to be_nil
  175. expect(log.duration_waiting_time).to be_nil
  176. expect(log.duration_talking_time).to be_nil
  177. # outbound - I - hangup by agent
  178. params = 'event=HungUp&call_id=1234567890-1&type=missed'
  179. post "/api/v1/placetel/#{token}", params: params
  180. expect(response).to have_http_status(200)
  181. log = Cti::Log.find_by(call_id: '1234567890-1')
  182. expect(log).to be_truthy
  183. expect(log.from).to eq('4930777000000')
  184. expect(log.to).to eq('01114100300')
  185. expect(log.direction).to eq('out')
  186. expect(log.from_comment).to eq(nil)
  187. expect(log.to_comment).to eq('CallerId Customer1')
  188. expect(log.comment).to eq('cancel')
  189. expect(log.state).to eq('hangup')
  190. expect(log.done).to eq(true)
  191. expect(log.initialized_at).to be_truthy
  192. expect(log.start_at).to be_nil
  193. expect(log.end_at).to be_truthy
  194. expect(log.duration_waiting_time).to be_truthy
  195. expect(log.duration_talking_time).to be_nil
  196. # outbound - II - new call
  197. params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=1234567890-2'
  198. post "/api/v1/placetel/#{token}", params: params
  199. expect(response).to have_http_status(200)
  200. log = Cti::Log.find_by(call_id: '1234567890-2')
  201. expect(log).to be_truthy
  202. expect(log.from).to eq('4930777000000')
  203. expect(log.to).to eq('01114100300')
  204. expect(log.direction).to eq('out')
  205. expect(log.from_comment).to eq(nil)
  206. expect(log.to_comment).to eq('CallerId Customer1')
  207. expect(log.comment).to be_nil
  208. expect(log.state).to eq('newCall')
  209. expect(log.done).to eq(true)
  210. expect(log.initialized_at).to be_truthy
  211. expect(log.start_at).to be_nil
  212. expect(log.end_at).to be_nil
  213. expect(log.duration_waiting_time).to be_nil
  214. expect(log.duration_talking_time).to be_nil
  215. # outbound - II - answer by customer
  216. params = 'event=CallAccepted&call_id=1234567890-2&from=030600000000&to=01114100300'
  217. post "/api/v1/placetel/#{token}", params: params
  218. expect(response).to have_http_status(200)
  219. log = Cti::Log.find_by(call_id: '1234567890-2')
  220. expect(log).to be_truthy
  221. expect(log.from).to eq('4930777000000')
  222. expect(log.to).to eq('01114100300')
  223. expect(log.direction).to eq('out')
  224. expect(log.from_comment).to eq(nil)
  225. expect(log.to_comment).to eq('CallerId Customer1')
  226. expect(log.comment).to be_nil
  227. expect(log.state).to eq('answer')
  228. expect(log.done).to eq(true)
  229. expect(log.initialized_at).to be_truthy
  230. expect(log.start_at).to be_truthy
  231. expect(log.end_at).to be_nil
  232. expect(log.duration_waiting_time).to be_truthy
  233. expect(log.duration_talking_time).to be_nil
  234. # outbound - II - hangup by customer
  235. params = 'event=HungUp&call_id=1234567890-2&type=accepted&from=030600000000&to=01114100300'
  236. post "/api/v1/placetel/#{token}", params: params
  237. expect(response).to have_http_status(200)
  238. log = Cti::Log.find_by(call_id: '1234567890-2')
  239. expect(log).to be_truthy
  240. expect(log.from).to eq('4930777000000')
  241. expect(log.to).to eq('01114100300')
  242. expect(log.direction).to eq('out')
  243. expect(log.from_comment).to eq(nil)
  244. expect(log.to_comment).to eq('CallerId Customer1')
  245. expect(log.comment).to eq('normalClearing')
  246. expect(log.state).to eq('hangup')
  247. expect(log.done).to eq(true)
  248. expect(log.initialized_at).to be_truthy
  249. expect(log.start_at).to be_truthy
  250. expect(log.end_at).to be_truthy
  251. expect(log.duration_waiting_time).to be_truthy
  252. expect(log.duration_talking_time).to be_truthy
  253. # inbound - I - new call
  254. params = 'event=IncomingCall&to=030600000000&from=01114100300&call_id=1234567890-3'
  255. post "/api/v1/placetel/#{token}", params: params
  256. expect(response).to have_http_status(200)
  257. log = Cti::Log.find_by(call_id: '1234567890-3')
  258. expect(log).to be_truthy
  259. expect(log.to).to eq('030600000000')
  260. expect(log.from).to eq('01114100300')
  261. expect(log.direction).to eq('in')
  262. expect(log.to_comment).to eq(nil)
  263. expect(log.from_comment).to eq('CallerId Customer1')
  264. expect(log.comment).to be_nil
  265. expect(log.state).to eq('newCall')
  266. expect(log.done).to eq(false)
  267. expect(log.initialized_at).to be_truthy
  268. expect(log.start_at).to be_nil
  269. expect(log.end_at).to be_nil
  270. expect(log.duration_waiting_time).to be_nil
  271. expect(log.duration_talking_time).to be_nil
  272. # inbound - I - answer by customer
  273. params = 'event=CallAccepted&call_id=1234567890-3&to=030600000000&from=01114100300'
  274. post "/api/v1/placetel/#{token}", params: params
  275. expect(response).to have_http_status(200)
  276. log = Cti::Log.find_by(call_id: '1234567890-3')
  277. expect(log).to be_truthy
  278. expect(log.to).to eq('030600000000')
  279. expect(log.from).to eq('01114100300')
  280. expect(log.direction).to eq('in')
  281. expect(log.to_comment).to eq(nil)
  282. expect(log.from_comment).to eq('CallerId Customer1')
  283. expect(log.comment).to be_nil
  284. expect(log.state).to eq('answer')
  285. expect(log.done).to eq(true)
  286. expect(log.initialized_at).to be_truthy
  287. expect(log.start_at).to be_truthy
  288. expect(log.end_at).to be_nil
  289. expect(log.duration_waiting_time).to be_truthy
  290. expect(log.duration_talking_time).to be_nil
  291. # inbound - I - hangup by customer
  292. params = 'event=HungUp&call_id=1234567890-3&type=accepted&to=030600000000&from=01114100300'
  293. post "/api/v1/placetel/#{token}", params: params
  294. expect(response).to have_http_status(200)
  295. log = Cti::Log.find_by(call_id: '1234567890-3')
  296. expect(log).to be_truthy
  297. expect(log.to).to eq('030600000000')
  298. expect(log.from).to eq('01114100300')
  299. expect(log.direction).to eq('in')
  300. expect(log.to_comment).to eq(nil)
  301. expect(log.from_comment).to eq('CallerId Customer1')
  302. expect(log.comment).to eq('normalClearing')
  303. expect(log.state).to eq('hangup')
  304. expect(log.done).to eq(true)
  305. expect(log.initialized_at).to be_truthy
  306. expect(log.start_at).to be_truthy
  307. expect(log.end_at).to be_truthy
  308. expect(log.duration_waiting_time).to be_truthy
  309. expect(log.duration_talking_time).to be_truthy
  310. # inbound - II - new call
  311. params = 'event=IncomingCall&to=030600000000&from=01114100300&call_id=1234567890-4'
  312. post "/api/v1/placetel/#{token}", params: params
  313. expect(response).to have_http_status(200)
  314. log = Cti::Log.find_by(call_id: '1234567890-4')
  315. expect(log).to be_truthy
  316. expect(log.to).to eq('030600000000')
  317. expect(log.from).to eq('01114100300')
  318. expect(log.direction).to eq('in')
  319. expect(log.to_comment).to eq(nil)
  320. expect(log.from_comment).to eq('CallerId Customer1')
  321. expect(log.comment).to be_nil
  322. expect(log.state).to eq('newCall')
  323. expect(log.done).to eq(false)
  324. expect(log.initialized_at).to be_truthy
  325. expect(log.start_at).to be_nil
  326. expect(log.end_at).to be_nil
  327. expect(log.duration_waiting_time).to be_nil
  328. expect(log.duration_talking_time).to be_nil
  329. # inbound - II - answer by voicemail
  330. params = 'event=CallAccepted&call_id=1234567890-4&to=030600000000&from=01114100300&user=voicemail'
  331. post "/api/v1/placetel/#{token}", params: params
  332. expect(response).to have_http_status(200)
  333. log = Cti::Log.find_by(call_id: '1234567890-4')
  334. expect(log).to be_truthy
  335. expect(log.to).to eq('030600000000')
  336. expect(log.from).to eq('01114100300')
  337. expect(log.direction).to eq('in')
  338. expect(log.to_comment).to eq('voicemail')
  339. expect(log.from_comment).to eq('CallerId Customer1')
  340. expect(log.comment).to be_nil
  341. expect(log.state).to eq('answer')
  342. expect(log.done).to eq(true)
  343. expect(log.initialized_at).to be_truthy
  344. expect(log.start_at).to be_truthy
  345. expect(log.end_at).to be_nil
  346. expect(log.duration_waiting_time).to be_truthy
  347. expect(log.duration_talking_time).to be_nil
  348. # inbound - II - hangup by customer
  349. params = 'event=HungUp&call_id=1234567890-4&type=accepted&to=030600000000&from=01114100300'
  350. post "/api/v1/placetel/#{token}", params: params
  351. expect(response).to have_http_status(200)
  352. log = Cti::Log.find_by(call_id: '1234567890-4')
  353. expect(log).to be_truthy
  354. expect(log.to).to eq('030600000000')
  355. expect(log.from).to eq('01114100300')
  356. expect(log.direction).to eq('in')
  357. expect(log.to_comment).to eq('voicemail')
  358. expect(log.from_comment).to eq('CallerId Customer1')
  359. expect(log.comment).to eq('normalClearing')
  360. expect(log.state).to eq('hangup')
  361. expect(log.done).to eq(false)
  362. expect(log.initialized_at).to be_truthy
  363. expect(log.start_at).to be_truthy
  364. expect(log.end_at).to be_truthy
  365. expect(log.duration_waiting_time).to be_truthy
  366. expect(log.duration_talking_time).to be_truthy
  367. # inbound - III - new call
  368. params = 'event=IncomingCall&to=030600000000&from=01114100300&call_id=1234567890-5'
  369. post "/api/v1/placetel/#{token}", params: params
  370. expect(response).to have_http_status(200)
  371. log = Cti::Log.find_by(call_id: '1234567890-5')
  372. expect(log).to be_truthy
  373. expect(log.to).to eq('030600000000')
  374. expect(log.from).to eq('01114100300')
  375. expect(log.direction).to eq('in')
  376. expect(log.to_comment).to eq(nil)
  377. expect(log.from_comment).to eq('CallerId Customer1')
  378. expect(log.comment).to be_nil
  379. expect(log.state).to eq('newCall')
  380. expect(log.done).to eq(false)
  381. expect(log.initialized_at).to be_truthy
  382. expect(log.start_at).to be_nil
  383. expect(log.end_at).to be_nil
  384. expect(log.duration_waiting_time).to be_nil
  385. expect(log.duration_talking_time).to be_nil
  386. # inbound - III - hangup by customer
  387. params = 'event=HungUp&call_id=1234567890-5&type=accepted&to=030600000000&from=01114100300'
  388. post "/api/v1/placetel/#{token}", params: params
  389. expect(response).to have_http_status(200)
  390. log = Cti::Log.find_by(call_id: '1234567890-5')
  391. expect(log).to be_truthy
  392. expect(log.to).to eq('030600000000')
  393. expect(log.from).to eq('01114100300')
  394. expect(log.direction).to eq('in')
  395. expect(log.to_comment).to eq(nil)
  396. expect(log.from_comment).to eq('CallerId Customer1')
  397. expect(log.comment).to eq('normalClearing')
  398. expect(log.state).to eq('hangup')
  399. expect(log.done).to eq(false)
  400. expect(log.initialized_at).to be_truthy
  401. expect(log.start_at).to be_nil
  402. expect(log.end_at).to be_truthy
  403. expect(log.duration_waiting_time).to be_truthy
  404. expect(log.duration_talking_time).to be_nil
  405. # inbound - IV - new call
  406. params = 'event=IncomingCall&to=030600000000&from=49999992222222&call_id=1234567890-6'
  407. post "/api/v1/placetel/#{token}", params: params
  408. expect(response).to have_http_status(200)
  409. log = Cti::Log.find_by(call_id: '1234567890-6')
  410. expect(log).to be_truthy
  411. expect(log.to).to eq('030600000000')
  412. expect(log.from).to eq('49999992222222')
  413. expect(log.direction).to eq('in')
  414. expect(log.to_comment).to eq(nil)
  415. expect(log.from_comment).to eq('CallerId Customer3,CallerId Customer2')
  416. expect(log.preferences['to']).to be_falsey
  417. expect(log.preferences['from']).to be_truthy
  418. expect(log.comment).to be_nil
  419. expect(log.state).to eq('newCall')
  420. expect(log.done).to eq(false)
  421. expect(log.initialized_at).to be_truthy
  422. expect(log.start_at).to be_nil
  423. expect(log.end_at).to be_nil
  424. expect(log.duration_waiting_time).to be_nil
  425. expect(log.duration_talking_time).to be_nil
  426. # inbound - IV - new call
  427. params = 'event=IncomingCall&to=030600000000&from=anonymous&call_id=1234567890-7'
  428. post "/api/v1/placetel/#{token}", params: params
  429. expect(response).to have_http_status(200)
  430. log = Cti::Log.find_by(call_id: '1234567890-7')
  431. expect(log).to be_truthy
  432. expect(log.to).to eq('030600000000')
  433. expect(log.from).to eq('anonymous')
  434. expect(log.direction).to eq('in')
  435. expect(log.to_comment).to eq(nil)
  436. expect(log.from_comment).to be_nil
  437. expect(log.preferences['to']).to be_falsey
  438. expect(log.preferences['from']).to be_falsey
  439. expect(log.comment).to be_nil
  440. expect(log.state).to eq('newCall')
  441. expect(log.done).to eq(false)
  442. expect(log.initialized_at).to be_truthy
  443. expect(log.start_at).to be_nil
  444. expect(log.end_at).to be_nil
  445. expect(log.duration_waiting_time).to be_nil
  446. expect(log.duration_talking_time).to be_nil
  447. # get caller list
  448. get '/api/v1/cti/log'
  449. expect(response).to have_http_status(401)
  450. authenticated_as(agent_user)
  451. get '/api/v1/cti/log', as: :json
  452. expect(response).to have_http_status(200)
  453. expect(json_response['list']).to be_a_kind_of(Array)
  454. expect(json_response['list'].count).to eq(7)
  455. expect(json_response['assets']).to be_truthy
  456. expect(json_response['assets']['User']).to be_truthy
  457. expect(json_response['assets']['User'][customer_user2.id.to_s]).to be_truthy
  458. expect(json_response['assets']['User'][customer_user3.id.to_s]).to be_truthy
  459. expect(json_response['list'][0]['call_id']).to eq('1234567890-7')
  460. expect(json_response['list'][1]['call_id']).to eq('1234567890-6')
  461. expect(json_response['list'][2]['call_id']).to eq('1234567890-5')
  462. expect(json_response['list'][3]['call_id']).to eq('1234567890-4')
  463. expect(json_response['list'][4]['call_id']).to eq('1234567890-3')
  464. expect(json_response['list'][5]['call_id']).to eq('1234567890-2')
  465. expect(json_response['list'][5]['state']).to eq('hangup')
  466. expect(json_response['list'][5]['from']).to eq('4930777000000')
  467. expect(json_response['list'][5]['from_comment']).to eq(nil)
  468. expect(json_response['list'][5]['to']).to eq('01114100300')
  469. expect(json_response['list'][5]['to_comment']).to eq('CallerId Customer1')
  470. expect(json_response['list'][5]['comment']).to eq('normalClearing')
  471. expect(json_response['list'][5]['state']).to eq('hangup')
  472. expect(json_response['list'][6]['call_id']).to eq('1234567890-1')
  473. end
  474. it 'does log call with peer' do
  475. token = Setting.get('placetel_token')
  476. # outbound - I - new call
  477. params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=1234567890-1&peer=something@example.com'
  478. post "/api/v1/placetel/#{token}", params: params
  479. expect(response).to have_http_status(200)
  480. log = Cti::Log.find_by(call_id: '1234567890-1')
  481. expect(log).to be_truthy
  482. expect(log.from).to eq('4930777000000')
  483. expect(log.to).to eq('01114100300')
  484. expect(log.direction).to eq('out')
  485. expect(log.from_comment).to eq(nil)
  486. expect(log.to_comment).to eq('CallerId Customer1')
  487. expect(log.comment).to be_nil
  488. expect(log.state).to eq('newCall')
  489. expect(log.done).to eq(true)
  490. expect(log.initialized_at).to be_truthy
  491. expect(log.start_at).to be_nil
  492. expect(log.end_at).to be_nil
  493. expect(log.duration_waiting_time).to be_nil
  494. expect(log.duration_talking_time).to be_nil
  495. config = Setting.get('placetel_config')
  496. config[:api_token] = '123'
  497. Setting.set('placetel_config', config)
  498. stub_request(:post, 'https://api.placetel.de/api/getVoIPUsers.json')
  499. .to_return(status: 200, body: [{ 'callerid' => '03055571600', 'did' => 10, 'name' => 'Bob Smith', 'stype' => 3, 'uid' => '777008478072@example.com', 'uid2' => nil }, { 'callerid' => '03055571600', 'did' => 12, 'name' => 'Josef Müller', 'stype' => 3, 'uid' => '777042617425@example.com', 'uid2' => nil }].to_json)
  500. params = 'event=newCall&direction=out&from=030600000000&to=01114100300&call_id=1234567890-2&peer=777008478072@example.com'
  501. post "/api/v1/placetel/#{token}", params: params
  502. expect(response).to have_http_status(200)
  503. log = Cti::Log.find_by(call_id: '1234567890-2')
  504. expect(log).to be_truthy
  505. expect(log.from).to eq('4930777000000')
  506. expect(log.to).to eq('01114100300')
  507. expect(log.direction).to eq('out')
  508. expect(log.from_comment).to eq('Bob Smith')
  509. expect(log.to_comment).to eq('CallerId Customer1')
  510. expect(log.comment).to be_nil
  511. expect(log.state).to eq('newCall')
  512. expect(log.done).to eq(true)
  513. expect(log.initialized_at).to be_truthy
  514. expect(log.start_at).to be_nil
  515. expect(log.end_at).to be_nil
  516. expect(log.duration_waiting_time).to be_nil
  517. expect(log.duration_talking_time).to be_nil
  518. # check if cache is filled
  519. expect(Cache.get('placetelGetVoipUsers')['777008478072@example.com']).to eq('Bob Smith')
  520. end
  521. end
  522. end