chat_test.rb 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'test_helper'
  3. class ChatTest < ActiveSupport::TestCase
  4. setup do
  5. groups = Group.all
  6. roles = Role.where(name: %w[Agent])
  7. @agent1 = User.create!(
  8. login: 'ticket-chat-agent1@example.com',
  9. firstname: 'Notification',
  10. lastname: 'Agent1',
  11. email: 'ticket-chat-agent1@example.com',
  12. password: 'agentpw',
  13. active: true,
  14. roles: roles,
  15. groups: groups,
  16. updated_at: '2015-02-05 16:37:00',
  17. updated_by_id: 1,
  18. created_by_id: 1,
  19. )
  20. @agent2 = User.create!(
  21. login: 'ticket-chat-agent2@example.com',
  22. firstname: 'Notification',
  23. lastname: 'Agent2',
  24. email: 'ticket-chat-agent2@example.com',
  25. password: 'agentpw',
  26. active: true,
  27. roles: roles,
  28. groups: groups,
  29. updated_at: '2015-02-05 16:38:00',
  30. updated_by_id: 1,
  31. created_by_id: 1,
  32. )
  33. Chat.delete_all
  34. Chat::Session.delete_all
  35. Chat::Message.delete_all
  36. Chat::Agent.delete_all
  37. Setting.set('chat', false)
  38. end
  39. test 'instance_variable test' do
  40. assert_nil(Sessions::Event::Base.instance_variable_get(:@database_connection))
  41. assert_equal(Sessions::Event::ChatBase.instance_variable_get(:@database_connection), true)
  42. assert_equal(Sessions::Event::ChatStatusAgent.instance_variable_get(:@database_connection), true)
  43. end
  44. # check if db connection is available for chat events
  45. # see: https://github.com/zammad/zammad/issues/2353
  46. test 'chat event db connection test' do
  47. class DummyWs # rubocop:disable Lint/ConstantDefinitionInBlock
  48. def send(msg) # rubocop:disable Zammad/ForbidDefSend
  49. Rails.logger.info "WS send: #{msg}"
  50. end
  51. end
  52. # with websockets
  53. assert(User.first)
  54. # make sure to emulate unconnected WS env
  55. ActiveRecord::Base.remove_connection
  56. message = Sessions::Event.run(
  57. event: 'login',
  58. payload: {},
  59. session: {},
  60. remote_ip: '127.0.0.1',
  61. client_id: '123',
  62. clients: {
  63. '123' => {
  64. websocket: DummyWs.new # to simulate a ws connection
  65. }
  66. },
  67. options: {},
  68. )
  69. assert_equal(message, false)
  70. assert_raises(ActiveRecord::ConnectionNotEstablished) do
  71. User.first
  72. end
  73. message = Sessions::Event.run(
  74. event: 'chat_status_customer',
  75. payload: {},
  76. session: {},
  77. remote_ip: '127.0.0.1',
  78. client_id: '123',
  79. clients: {
  80. '123' => DummyWs.new # to simulate a ws connection
  81. },
  82. options: {},
  83. )
  84. assert_equal(message[:event], 'chat_error')
  85. assert_raises(ActiveRecord::ConnectionNotEstablished) do
  86. User.first
  87. end
  88. # re-establish connection
  89. ActiveRecord::Base.establish_connection
  90. # with ajax long polling
  91. assert(User.first)
  92. message = Sessions::Event.run(
  93. event: 'login',
  94. payload: {},
  95. session: {},
  96. remote_ip: '127.0.0.1',
  97. client_id: '123',
  98. clients: {},
  99. options: {},
  100. )
  101. assert_equal(message, false)
  102. assert(User.first)
  103. message = Sessions::Event.run(
  104. event: 'chat_status_customer',
  105. payload: {},
  106. session: {},
  107. remote_ip: '127.0.0.1',
  108. client_id: '123',
  109. clients: {},
  110. options: {},
  111. )
  112. assert_equal(message[:event], 'chat_error')
  113. assert(User.first)
  114. end
  115. test 'default test' do
  116. chat = Chat.create!(
  117. name: 'default',
  118. max_queue: 5,
  119. note: '',
  120. active: true,
  121. updated_by_id: 1,
  122. created_by_id: 1,
  123. )
  124. @agent1.preferences[:chat] = {
  125. active: {
  126. chat.id => 'on',
  127. },
  128. }
  129. @agent1.save!
  130. @agent2.preferences[:chat] = {
  131. active: {
  132. chat.id => 'on',
  133. },
  134. }
  135. @agent2.save!
  136. # check if feature is disabled
  137. assert_equal('chat_disabled', chat.customer_state[:state])
  138. assert_equal('chat_disabled', Chat.agent_state(@agent1.id)[:state])
  139. Setting.set('chat', true)
  140. # check customer state
  141. assert_equal('offline', chat.customer_state[:state])
  142. # check agent state
  143. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  144. assert_equal(0, agent_state[:waiting_chat_count])
  145. assert_equal(0, agent_state[:running_chat_count])
  146. assert_equal([], agent_state[:active_sessions])
  147. assert_equal(0, agent_state[:seads_available])
  148. assert_equal(0, agent_state[:seads_total])
  149. assert_equal(false, agent_state[:active])
  150. # set agent 1 to active
  151. Chat::Agent.create_or_update(
  152. active: true,
  153. concurrent: 4,
  154. updated_by_id: @agent1.id,
  155. created_by_id: @agent1.id,
  156. )
  157. # check customer state
  158. assert_equal('online', chat.customer_state[:state])
  159. # check agent state
  160. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  161. assert_equal(0, agent_state[:waiting_chat_count])
  162. assert_equal(0, agent_state[:running_chat_count])
  163. assert_equal([], agent_state[:active_sessions])
  164. assert_equal(4, agent_state[:seads_available])
  165. assert_equal(4, agent_state[:seads_total])
  166. assert_equal(true, agent_state[:active])
  167. # start session
  168. chat_session1 = Chat::Session.create!(
  169. chat_id: chat.id,
  170. user_id: @agent1.id,
  171. )
  172. assert(chat_session1.session_id)
  173. # check customer state
  174. assert_equal('online', chat.customer_state[:state])
  175. # check agent state
  176. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  177. assert_equal(1, agent_state[:waiting_chat_count])
  178. assert_equal(0, agent_state[:running_chat_count])
  179. assert_equal([], agent_state[:active_sessions])
  180. assert_equal(3, agent_state[:seads_available])
  181. assert_equal(4, agent_state[:seads_total])
  182. assert_equal(true, agent_state[:active])
  183. # activate second agent
  184. chat_agent2 = Chat::Agent.create!(
  185. active: true,
  186. concurrent: 2,
  187. updated_by_id: @agent2.id,
  188. created_by_id: @agent2.id,
  189. )
  190. # check customer state
  191. assert_equal('online', chat.customer_state[:state])
  192. # check agent1 state
  193. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  194. assert_equal(1, agent_state[:waiting_chat_count])
  195. assert_equal(0, agent_state[:running_chat_count])
  196. assert_equal([], agent_state[:active_sessions])
  197. assert_equal(5, agent_state[:seads_available])
  198. assert_equal(6, agent_state[:seads_total])
  199. assert_equal(true, agent_state[:active])
  200. # check agent2 state
  201. agent_state = Chat.agent_state_with_sessions(@agent2.id)
  202. assert_equal(1, agent_state[:waiting_chat_count])
  203. assert_equal(0, agent_state[:running_chat_count])
  204. assert_equal([], agent_state[:active_sessions])
  205. assert_equal(5, agent_state[:seads_available])
  206. assert_equal(6, agent_state[:seads_total])
  207. assert_equal(true, agent_state[:active])
  208. # start next chat
  209. Chat::Session.create(
  210. chat_id: chat.id,
  211. )
  212. # check customer state
  213. assert_equal('online', chat.customer_state[:state])
  214. # check agent1 state
  215. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  216. assert_equal(2, agent_state[:waiting_chat_count])
  217. assert_equal(0, agent_state[:running_chat_count])
  218. assert_equal([], agent_state[:active_sessions])
  219. assert_equal(4, agent_state[:seads_available])
  220. assert_equal(6, agent_state[:seads_total])
  221. assert_equal(true, agent_state[:active])
  222. # check agent2 state
  223. agent_state = Chat.agent_state_with_sessions(@agent2.id)
  224. assert_equal(2, agent_state[:waiting_chat_count])
  225. assert_equal(0, agent_state[:running_chat_count])
  226. assert_equal([], agent_state[:active_sessions])
  227. assert_equal(4, agent_state[:seads_available])
  228. assert_equal(6, agent_state[:seads_total])
  229. assert_equal(true, agent_state[:active])
  230. # start new chats
  231. Chat::Session.create(
  232. chat_id: chat.id,
  233. )
  234. chat_session4 = Chat::Session.create!(
  235. chat_id: chat.id,
  236. )
  237. chat_session5 = Chat::Session.create!(
  238. chat_id: chat.id,
  239. )
  240. chat_session6 = Chat::Session.create!(
  241. chat_id: chat.id,
  242. )
  243. # check customer state
  244. assert_equal('no_seats_available', chat.customer_state[:state])
  245. # check agent1 state
  246. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  247. assert_equal(6, agent_state[:waiting_chat_count])
  248. assert_equal(0, agent_state[:running_chat_count])
  249. assert_equal([], agent_state[:active_sessions])
  250. assert_equal(0, agent_state[:seads_available])
  251. assert_equal(6, agent_state[:seads_total])
  252. assert_equal(true, agent_state[:active])
  253. # check agent2 state
  254. agent_state = Chat.agent_state_with_sessions(@agent2.id)
  255. assert_equal(6, agent_state[:waiting_chat_count])
  256. assert_equal(0, agent_state[:running_chat_count])
  257. assert_equal([], agent_state[:active_sessions])
  258. assert_equal(0, agent_state[:seads_available])
  259. assert_equal(6, agent_state[:seads_total])
  260. assert_equal(true, agent_state[:active])
  261. chat_session6.user_id = @agent1.id
  262. chat_session6.state = 'running'
  263. chat_session6.save
  264. Chat::Message.create!(
  265. chat_session_id: chat_session6.id,
  266. content: 'message 1',
  267. created_by_id: @agent1.id,
  268. )
  269. travel 1.second
  270. Chat::Message.create!(
  271. chat_session_id: chat_session6.id,
  272. content: 'message 2',
  273. created_by_id: @agent1.id,
  274. )
  275. travel 1.second
  276. Chat::Message.create!(
  277. chat_session_id: chat_session6.id,
  278. content: 'message 3',
  279. created_by_id: @agent1.id,
  280. )
  281. travel 1.second
  282. Chat::Message.create!(
  283. chat_session_id: chat_session6.id,
  284. content: 'message 4',
  285. created_by_id: nil,
  286. )
  287. # check customer state
  288. customer_state = chat.customer_state
  289. assert_equal('no_seats_available', customer_state[:state])
  290. assert_equal(5, customer_state[:queue])
  291. # customer chat state
  292. customer_state = chat.customer_state(chat_session6.session_id)
  293. assert_equal('reconnect', customer_state[:state])
  294. assert(customer_state[:session])
  295. assert_equal(Array, customer_state[:session].class)
  296. assert_equal('message 1', customer_state[:session][0]['content'])
  297. assert_equal('message 2', customer_state[:session][1]['content'])
  298. assert_equal('message 3', customer_state[:session][2]['content'])
  299. assert_equal('message 4', customer_state[:session][3]['content'])
  300. assert_equal('Notification Agent1', customer_state[:agent][:name])
  301. assert_nil(customer_state[:agent][:avatar])
  302. # check agent1 state
  303. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  304. assert_equal(5, agent_state[:waiting_chat_count])
  305. assert_equal(1, agent_state[:running_chat_count])
  306. assert_equal(Array, agent_state[:active_sessions].class)
  307. assert_equal(chat.id, agent_state[:active_sessions][0]['chat_id'])
  308. assert_equal(@agent1.id, agent_state[:active_sessions][0]['user_id'])
  309. assert(agent_state[:active_sessions][0]['messages'])
  310. assert_equal(Array, agent_state[:active_sessions][0]['messages'].class)
  311. assert_equal('message 1', agent_state[:active_sessions][0]['messages'][0]['content'])
  312. assert_equal('message 2', agent_state[:active_sessions][0]['messages'][1]['content'])
  313. assert_equal('message 3', agent_state[:active_sessions][0]['messages'][2]['content'])
  314. assert_equal('message 4', agent_state[:active_sessions][0]['messages'][3]['content'])
  315. assert_equal(0, agent_state[:seads_available])
  316. assert_equal(6, agent_state[:seads_total])
  317. assert_equal(true, agent_state[:active])
  318. # check agent2 state
  319. agent_state = Chat.agent_state_with_sessions(@agent2.id)
  320. assert_equal(5, agent_state[:waiting_chat_count])
  321. assert_equal(1, agent_state[:running_chat_count])
  322. assert_equal([], agent_state[:active_sessions])
  323. assert_equal(0, agent_state[:seads_available])
  324. assert_equal(6, agent_state[:seads_total])
  325. assert_equal(true, agent_state[:active])
  326. chat_agent2.active = false
  327. chat_agent2.save
  328. # check customer state
  329. assert_equal('no_seats_available', chat.customer_state[:state])
  330. assert_equal(5, chat.customer_state[:queue])
  331. # check agent1 state
  332. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  333. assert_equal(5, agent_state[:waiting_chat_count])
  334. assert_equal(1, agent_state[:running_chat_count])
  335. assert_equal(Array, agent_state[:active_sessions].class)
  336. assert_equal(chat.id, agent_state[:active_sessions][0]['chat_id'])
  337. assert_equal(@agent1.id, agent_state[:active_sessions][0]['user_id'])
  338. assert(agent_state[:active_sessions][0]['messages'])
  339. assert_equal(Array, agent_state[:active_sessions][0]['messages'].class)
  340. assert_equal('message 1', agent_state[:active_sessions][0]['messages'][0]['content'])
  341. assert_equal('message 2', agent_state[:active_sessions][0]['messages'][1]['content'])
  342. assert_equal('message 3', agent_state[:active_sessions][0]['messages'][2]['content'])
  343. assert_equal('message 4', agent_state[:active_sessions][0]['messages'][3]['content'])
  344. assert_equal(-2, agent_state[:seads_available])
  345. assert_equal(4, agent_state[:seads_total])
  346. assert_equal(true, agent_state[:active])
  347. # check agent2 state
  348. agent_state = Chat.agent_state_with_sessions(@agent2.id)
  349. assert_equal(5, agent_state[:waiting_chat_count])
  350. assert_equal(1, agent_state[:running_chat_count])
  351. assert_equal([], agent_state[:active_sessions])
  352. assert_equal(-2, agent_state[:seads_available])
  353. assert_equal(4, agent_state[:seads_total])
  354. assert_equal(false, agent_state[:active])
  355. chat_session6.state = 'closed'
  356. chat_session6.save
  357. # check customer state
  358. assert_equal('no_seats_available', chat.customer_state[:state])
  359. assert_equal(5, chat.customer_state[:queue])
  360. # check agent1 state
  361. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  362. assert_equal(5, agent_state[:waiting_chat_count])
  363. assert_equal(0, agent_state[:running_chat_count])
  364. assert_equal([], agent_state[:active_sessions])
  365. assert_equal(-1, agent_state[:seads_available])
  366. assert_equal(4, agent_state[:seads_total])
  367. assert_equal(true, agent_state[:active])
  368. # check agent2 state
  369. agent_state = Chat.agent_state_with_sessions(@agent2.id)
  370. assert_equal(5, agent_state[:waiting_chat_count])
  371. assert_equal(0, agent_state[:running_chat_count])
  372. assert_equal([], agent_state[:active_sessions])
  373. assert_equal(-1, agent_state[:seads_available])
  374. assert_equal(4, agent_state[:seads_total])
  375. assert_equal(false, agent_state[:active])
  376. chat_session5.destroy
  377. chat_session4.destroy
  378. # check customer state
  379. assert_equal('online', chat.customer_state[:state])
  380. # check agent1 state
  381. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  382. assert_equal(3, agent_state[:waiting_chat_count])
  383. assert_equal(0, agent_state[:running_chat_count])
  384. assert_equal([], agent_state[:active_sessions])
  385. assert_equal(1, agent_state[:seads_available])
  386. assert_equal(4, agent_state[:seads_total])
  387. assert_equal(true, agent_state[:active])
  388. # check agent2 state
  389. agent_state = Chat.agent_state_with_sessions(@agent2.id)
  390. assert_equal(3, agent_state[:waiting_chat_count])
  391. assert_equal(0, agent_state[:running_chat_count])
  392. assert_equal([], agent_state[:active_sessions])
  393. assert_equal(1, agent_state[:seads_available])
  394. assert_equal(4, agent_state[:seads_total])
  395. assert_equal(false, agent_state[:active])
  396. travel_back
  397. end
  398. test 'check if agent_state_with_sessions works correctly with 2 chats' do
  399. chat1 = Chat.create!(
  400. name: 'topic 1',
  401. max_queue: 5,
  402. note: '',
  403. active: true,
  404. updated_by_id: 1,
  405. created_by_id: 1,
  406. )
  407. chat2 = Chat.create!(
  408. name: 'topic 2',
  409. max_queue: 5,
  410. note: '',
  411. active: true,
  412. updated_by_id: 1,
  413. created_by_id: 1,
  414. )
  415. @agent1.preferences[:chat] = {
  416. active: {
  417. chat1.id.to_s => 'on',
  418. },
  419. }
  420. @agent1.save!
  421. @agent2.preferences[:chat] = {
  422. active: {
  423. chat2.id.to_s => 'on',
  424. },
  425. }
  426. @agent2.save!
  427. Setting.set('chat', true)
  428. # check customer state
  429. assert_equal('offline', chat1.customer_state[:state])
  430. assert_equal('offline', chat2.customer_state[:state])
  431. # check agent state
  432. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  433. assert_equal(0, agent_state[:waiting_chat_count])
  434. assert_equal(0, agent_state[:running_chat_count])
  435. assert_equal([], agent_state[:active_sessions])
  436. assert_equal(0, agent_state[:seads_available])
  437. assert_equal(0, agent_state[:seads_total])
  438. assert_equal(false, agent_state[:active])
  439. # set agent 1 to active
  440. Chat::Agent.create!(
  441. active: true,
  442. concurrent: 4,
  443. updated_by_id: @agent1.id,
  444. created_by_id: @agent1.id,
  445. )
  446. # check customer state
  447. assert_equal('online', chat1.customer_state[:state])
  448. assert_equal('offline', chat2.customer_state[:state])
  449. # check agent state
  450. agent_state = Chat.agent_state_with_sessions(@agent2.id)
  451. assert_equal(0, agent_state[:waiting_chat_count])
  452. assert_equal(0, agent_state[:running_chat_count])
  453. assert_equal([], agent_state[:active_sessions])
  454. assert_equal(0, agent_state[:seads_available])
  455. assert_equal(0, agent_state[:seads_total])
  456. assert_equal(false, agent_state[:active])
  457. # set agent 2 to active
  458. Chat::Agent.create!(
  459. active: true,
  460. concurrent: 2,
  461. updated_by_id: @agent2.id,
  462. created_by_id: @agent2.id,
  463. )
  464. # check customer state
  465. assert_equal('online', chat1.customer_state[:state])
  466. assert_equal('online', chat2.customer_state[:state])
  467. # start session
  468. chat_session1 = Chat::Session.create!(
  469. chat_id: chat1.id,
  470. user_id: @agent1.id,
  471. )
  472. assert(chat_session1.session_id)
  473. # check agent1 state
  474. agent_state = Chat.agent_state_with_sessions(@agent1.id)
  475. assert_equal(1, agent_state[:waiting_chat_count])
  476. assert_equal(0, agent_state[:running_chat_count])
  477. assert_equal([], agent_state[:active_sessions])
  478. assert_equal(3, agent_state[:seads_available])
  479. assert_equal(4, agent_state[:seads_total])
  480. assert_equal(true, agent_state[:active])
  481. # check agent2 state
  482. agent_state = Chat.agent_state_with_sessions(@agent2.id)
  483. assert_equal(0, agent_state[:waiting_chat_count])
  484. assert_equal(0, agent_state[:running_chat_count])
  485. assert_equal([], agent_state[:active_sessions])
  486. assert_equal(2, agent_state[:seads_available])
  487. assert_equal(2, agent_state[:seads_total])
  488. assert_equal(true, agent_state[:active])
  489. end
  490. test 'if agent_active_chat_ids works correctly' do
  491. chat1 = Chat.create!(
  492. name: 'topic 1',
  493. max_queue: 5,
  494. note: '',
  495. active: true,
  496. updated_by_id: 1,
  497. created_by_id: 1,
  498. )
  499. chat2 = Chat.create!(
  500. name: 'topic 2',
  501. max_queue: 5,
  502. note: '',
  503. active: true,
  504. updated_by_id: 1,
  505. created_by_id: 1,
  506. )
  507. assert_equal([], Chat.agent_active_chat_ids(@agent1))
  508. assert_equal([], Chat.agent_active_chat_ids(@agent2))
  509. @agent1.preferences[:chat] = {
  510. active: {
  511. chat1.id.to_s => 'on',
  512. },
  513. }
  514. @agent1.save!
  515. @agent2.preferences[:chat] = {
  516. active: {
  517. chat2.id => 'on',
  518. },
  519. }
  520. @agent2.save!
  521. assert_equal([chat1.id], Chat.agent_active_chat_ids(@agent1))
  522. assert_equal([chat2.id], Chat.agent_active_chat_ids(@agent2))
  523. @agent2.preferences[:chat] = {
  524. active: {
  525. chat2.id => 'off',
  526. },
  527. }
  528. @agent2.save!
  529. assert_equal([chat1.id], Chat.agent_active_chat_ids(@agent1))
  530. assert_equal([], Chat.agent_active_chat_ids(@agent2))
  531. end
  532. test 'blocked ip test' do
  533. chat = Chat.create!(
  534. name: 'ip test',
  535. max_queue: 5,
  536. note: '',
  537. block_ip: '127.0.0.1;127.0.0.2;127.1.0.*',
  538. active: true,
  539. updated_by_id: 1,
  540. created_by_id: 1,
  541. )
  542. assert_not(chat.blocked_ip?('128.0.0.1'))
  543. assert_not(chat.blocked_ip?('127.0.0.30'))
  544. assert(chat.blocked_ip?('127.0.0.1'))
  545. assert(chat.blocked_ip?('127.0.0.2'))
  546. assert(chat.blocked_ip?('127.1.0.1'))
  547. assert(chat.blocked_ip?('127.1.0.100'))
  548. end
  549. test 'blocked country test' do
  550. chat = Chat.create!(
  551. name: 'country test',
  552. max_queue: 5,
  553. note: '',
  554. block_country: 'AU;CH;DE',
  555. active: true,
  556. updated_by_id: 1,
  557. created_by_id: 1,
  558. )
  559. assert_not(chat.blocked_country?('127.0.0.1'))
  560. assert(chat.blocked_country?('116.203.82.166'))
  561. end
  562. end