notification_factory_test.rb 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class NotificationFactoryTest < ActiveSupport::TestCase
  4. Translation.load('de-de')
  5. test 'notifications send' do
  6. result = NotificationFactory.send(
  7. recipient: User.find(2),
  8. subject: 'sime subject',
  9. body: 'some body',
  10. content_type: '',
  11. )
  12. assert_match('some body', result.to_s)
  13. assert_match('text/plain', result.to_s)
  14. assert_no_match('text/html', result.to_s)
  15. result = NotificationFactory.send(
  16. recipient: User.find(2),
  17. subject: 'sime subject',
  18. body: 'some body',
  19. content_type: 'text/plain',
  20. )
  21. assert_match('some body', result.to_s)
  22. assert_match('text/plain', result.to_s)
  23. assert_no_match('text/html', result.to_s)
  24. result = NotificationFactory.send(
  25. recipient: User.find(2),
  26. subject: 'sime subject',
  27. body: 'some <span>body</span>',
  28. content_type: 'text/html',
  29. )
  30. assert_match('some body', result.to_s)
  31. assert_match('text/plain', result.to_s)
  32. assert_match('<span>body</span>', result.to_s)
  33. assert_match('text/html', result.to_s)
  34. end
  35. test 'notifications base' do
  36. ticket = Ticket.create(
  37. title: 'some title äöüß',
  38. group: Group.lookup(name: 'Users'),
  39. customer_id: 2,
  40. state: Ticket::State.lookup(name: 'new'),
  41. priority: Ticket::Priority.lookup(name: '2 normal'),
  42. updated_by_id: 2,
  43. created_by_id: 2,
  44. )
  45. article_plain = Ticket::Article.create(
  46. ticket_id: ticket.id,
  47. type_id: Ticket::Article::Type.where(name: 'phone').first.id,
  48. sender_id: Ticket::Article::Sender.where(name: 'Customer').first.id,
  49. from: 'Zammad Feedback <feedback@example.org>',
  50. body: 'some text',
  51. internal: false,
  52. updated_by_id: 1,
  53. created_by_id: 1,
  54. )
  55. tests = [
  56. {
  57. locale: 'en',
  58. string: 'Hi #{recipient.firstname},',
  59. result: 'Hi Nicole,',
  60. },
  61. {
  62. locale: 'de-de',
  63. string: 'Hi #{recipient.firstname},',
  64. result: 'Hi Nicole,',
  65. },
  66. {
  67. locale: 'de-de',
  68. string: 'Hi #{recipient.firstname}, Group: #{ticket.group.name}',
  69. result: 'Hi Nicole, Group: Users',
  70. },
  71. {
  72. locale: 'de-de',
  73. string: '#{config.http_type} some text',
  74. result: 'http some text',
  75. },
  76. {
  77. locale: 'de-de',
  78. string: 'i18n(New) some text',
  79. result: 'Neu some text',
  80. },
  81. {
  82. locale: 'de-de',
  83. string: '\'i18n(#{ticket.state.name})\' ticket state',
  84. result: '\'neu\' ticket state',
  85. },
  86. {
  87. locale: 'de-de',
  88. string: 'a #{not_existing_object.test}',
  89. result: 'a #{not_existing_object / no such object}',
  90. },
  91. {
  92. locale: 'de-de',
  93. string: 'a #{ticket.level1}',
  94. result: 'a #{ticket.level1 / no such method}',
  95. },
  96. {
  97. locale: 'de-de',
  98. string: 'a #{ticket.level1.level2}',
  99. result: 'a #{ticket.level1 / no such method}',
  100. },
  101. {
  102. locale: 'de-de',
  103. string: 'a #{ticket.title.level2}',
  104. result: 'a #{ticket.title.level2 / no such method}',
  105. },
  106. {
  107. locale: 'de-de',
  108. string: 'by #{ticket.updated_by.fullname}',
  109. result: 'by Nicole Braun',
  110. },
  111. {
  112. locale: 'de-de',
  113. string: 'Subject #{article.from}, Group: #{ticket.group.name}',
  114. result: 'Subject Zammad Feedback <feedback@example.org>, Group: Users',
  115. },
  116. {
  117. locale: 'de-de',
  118. string: 'Body #{article.body}, Group: #{ticket.group.name}',
  119. result: 'Body some text, Group: Users',
  120. },
  121. {
  122. locale: 'de-de',
  123. string: '\#{puts `ls`}',
  124. result: '\#{puts `ls`} (not allowed)',
  125. },
  126. {
  127. locale: 'de-de',
  128. string: 'test i18n(new)',
  129. result: 'test neu',
  130. },
  131. {
  132. locale: 'de-de',
  133. string: 'test i18n()',
  134. result: 'test ',
  135. },
  136. {
  137. locale: 'de-de',
  138. string: 'test i18n(new) i18n(open)',
  139. result: 'test neu offen',
  140. },
  141. ]
  142. tests.each { |test|
  143. result = NotificationFactory.build(
  144. string: test[:string],
  145. objects: {
  146. ticket: ticket,
  147. article: article_plain,
  148. recipient: User.find(2),
  149. },
  150. locale: test[:locale]
  151. )
  152. assert_equal(test[:result], result, 'verify result')
  153. }
  154. ticket.destroy
  155. end
  156. test 'notifications html' do
  157. ticket = Ticket.create(
  158. title: 'some title <b>äöüß</b> 2',
  159. group: Group.lookup(name: 'Users'),
  160. customer_id: 2,
  161. state: Ticket::State.lookup(name: 'new'),
  162. priority: Ticket::Priority.lookup(name: '2 normal'),
  163. updated_by_id: 1,
  164. created_by_id: 1,
  165. )
  166. article_html = Ticket::Article.create(
  167. ticket_id: ticket.id,
  168. type_id: Ticket::Article::Type.where(name: 'phone').first.id,
  169. sender_id: Ticket::Article::Sender.where(name: 'Customer').first.id,
  170. from: 'Zammad Feedback <feedback@example.org>',
  171. body: 'some <b>text</b><br>next line',
  172. content_type: 'text/html',
  173. internal: false,
  174. updated_by_id: 1,
  175. created_by_id: 1,
  176. )
  177. tests = [
  178. {
  179. locale: 'de-de',
  180. string: 'Subject #{ticket.title}',
  181. result: 'Subject some title <b>äöüß</b> 2',
  182. },
  183. {
  184. locale: 'de-de',
  185. string: 'Subject #{article.from}, Group: #{ticket.group.name}',
  186. result: 'Subject Zammad Feedback <feedback@example.org>, Group: Users',
  187. },
  188. {
  189. locale: 'de-de',
  190. string: 'Body #{article.body}, Group: #{ticket.group.name}',
  191. result: 'Body some text
  192. next line, Group: Users',
  193. },
  194. ]
  195. tests.each { |test|
  196. result = NotificationFactory.build(
  197. string: test[:string],
  198. objects: {
  199. ticket: ticket,
  200. article: article_html,
  201. recipient: User.find(2),
  202. },
  203. locale: test[:locale]
  204. )
  205. assert_equal(test[:result], result, 'verify result')
  206. }
  207. ticket.destroy
  208. end
  209. test 'notifications attack' do
  210. ticket = Ticket.create(
  211. title: 'some title <b>äöüß</b> 3',
  212. group: Group.lookup(name: 'Users'),
  213. customer_id: 2,
  214. state: Ticket::State.lookup(name: 'new'),
  215. priority: Ticket::Priority.lookup(name: '2 normal'),
  216. updated_by_id: 1,
  217. created_by_id: 1,
  218. )
  219. article_html = Ticket::Article.create(
  220. ticket_id: ticket.id,
  221. type_id: Ticket::Article::Type.where(name: 'phone').first.id,
  222. sender_id: Ticket::Article::Sender.where(name: 'Customer').first.id,
  223. from: 'Zammad Feedback <feedback@example.org>',
  224. body: 'some <b>text</b><br>next line',
  225. content_type: 'text/html',
  226. internal: false,
  227. updated_by_id: 1,
  228. created_by_id: 1,
  229. )
  230. tests = [
  231. {
  232. locale: 'de-de',
  233. string: '\#{puts `ls`}',
  234. result: '\#{puts `ls`} (not allowed)',
  235. },
  236. {
  237. locale: 'de-de',
  238. string: 'attack#1 #{article.destroy}',
  239. result: 'attack#1 #{article.destroy} (not allowed)',
  240. },
  241. {
  242. locale: 'de-de',
  243. string: 'attack#2 #{Article.where}',
  244. result: 'attack#2 #{Article.where} (not allowed)',
  245. },
  246. {
  247. locale: 'de-de',
  248. string: 'attack#1 #{article.
  249. destroy}',
  250. result: 'attack#1 #{article.
  251. destroy} (not allowed)',
  252. },
  253. {
  254. locale: 'de-de',
  255. string: 'attack#1 #{article.find}',
  256. result: 'attack#1 #{article.find} (not allowed)',
  257. },
  258. {
  259. locale: 'de-de',
  260. string: 'attack#1 #{article.update(:name => "test")}',
  261. result: 'attack#1 #{article.update(:name => "test")} (not allowed)',
  262. },
  263. {
  264. locale: 'de-de',
  265. string: 'attack#1 #{article.all}',
  266. result: 'attack#1 #{article.all} (not allowed)',
  267. },
  268. {
  269. locale: 'de-de',
  270. string: 'attack#1 #{article.delete}',
  271. result: 'attack#1 #{article.delete} (not allowed)',
  272. },
  273. ]
  274. tests.each { |test|
  275. result = NotificationFactory.build(
  276. string: test[:string],
  277. objects: {
  278. ticket: ticket,
  279. article: article_html,
  280. recipient: User.find(2),
  281. },
  282. locale: test[:locale]
  283. )
  284. assert_equal(test[:result], result, 'verify result')
  285. }
  286. ticket.destroy
  287. end
  288. test 'notifications template' do
  289. groups = Group.where(name: 'Users')
  290. roles = Role.where(name: 'Agent')
  291. agent1 = User.create_or_update(
  292. login: 'notification-template-agent1@example.com',
  293. firstname: 'Notification<b>xxx</b>',
  294. lastname: 'Agent1<b>yyy</b>',
  295. email: 'notification-template-agent1@example.com',
  296. password: 'agentpw',
  297. active: true,
  298. roles: roles,
  299. groups: groups,
  300. preferences: {
  301. locale: 'de-de',
  302. },
  303. updated_by_id: 1,
  304. created_by_id: 1,
  305. )
  306. result = NotificationFactory.template(
  307. template: 'password_reset',
  308. locale: 'de-de',
  309. objects: {
  310. user: agent1,
  311. },
  312. )
  313. assert_match('Zurücksetzen Deines', result[:subject])
  314. assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
  315. assert_match('Dein', result[:body])
  316. assert_match('Dein', result[:body])
  317. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  318. assert_no_match('Your', result[:body])
  319. result = NotificationFactory.template(
  320. template: 'password_reset',
  321. locale: 'de',
  322. objects: {
  323. user: agent1,
  324. },
  325. )
  326. assert_match('Zurücksetzen Deines', result[:subject])
  327. assert_match('wir haben eine Anfrage zum Zurücksetzen', result[:body])
  328. assert_match('Dein', result[:body])
  329. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  330. assert_no_match('Your', result[:body])
  331. result = NotificationFactory.template(
  332. template: 'password_reset',
  333. locale: 'es-us',
  334. objects: {
  335. user: agent1,
  336. },
  337. )
  338. assert_match('Reset your', result[:subject])
  339. assert_match('We received a request to reset the password', result[:body])
  340. assert_match('Your', result[:body])
  341. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  342. assert_no_match('Dein', result[:body])
  343. ticket = Ticket.create(
  344. group_id: Group.lookup(name: 'Users').id,
  345. customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
  346. owner_id: User.lookup(login: '-').id,
  347. title: 'Welcome to Zammad!',
  348. state_id: Ticket::State.lookup(name: 'new').id,
  349. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  350. updated_by_id: 1,
  351. created_by_id: 1,
  352. )
  353. article = Ticket::Article.create(
  354. ticket_id: ticket.id,
  355. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  356. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  357. from: 'Zammad Feedback <feedback@zammad.org>',
  358. content_type: 'text/plain',
  359. body: 'Welcome!
  360. <b>test123</b>',
  361. internal: false,
  362. updated_by_id: 1,
  363. created_by_id: 1,
  364. )
  365. changes = {}
  366. result = NotificationFactory.template(
  367. template: 'ticket_create',
  368. locale: 'es-us',
  369. objects: {
  370. ticket: ticket,
  371. article: article,
  372. recipient: agent1,
  373. changes: changes,
  374. },
  375. )
  376. assert_match('New Ticket', result[:subject])
  377. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  378. assert_match('has been created by', result[:body])
  379. assert_match('&lt;b&gt;test123&lt;/b&gt;', result[:body])
  380. assert_match('Manage your notifications settings', result[:body])
  381. assert_no_match('Dein', result[:body])
  382. result = NotificationFactory.template(
  383. template: 'ticket_create',
  384. locale: 'de-de',
  385. objects: {
  386. ticket: ticket,
  387. article: article,
  388. recipient: agent1,
  389. changes: changes,
  390. },
  391. )
  392. assert_match('Neues Ticket', result[:subject])
  393. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  394. assert_match('es wurde ein neues Ticket', result[:body])
  395. assert_match('&lt;b&gt;test123&lt;/b&gt;', result[:body])
  396. assert_match('Benachrichtigungseinstellungen Verwalten', result[:body])
  397. assert_no_match('Your', result[:body])
  398. article = Ticket::Article.create(
  399. ticket_id: ticket.id,
  400. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  401. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  402. from: 'Zammad Feedback <feedback@zammad.org>',
  403. content_type: 'text/html',
  404. body: 'Welcome!
  405. <b>test123</b>',
  406. internal: false,
  407. updated_by_id: 1,
  408. created_by_id: 1,
  409. )
  410. changes = {
  411. state: %w(aaa bbb),
  412. group: %w(xxx yyy),
  413. }
  414. result = NotificationFactory.template(
  415. template: 'ticket_update',
  416. locale: 'es-us',
  417. objects: {
  418. ticket: ticket,
  419. article: article,
  420. recipient: agent1,
  421. changes: changes,
  422. },
  423. )
  424. assert_match('Updated Ticket', result[:subject])
  425. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  426. assert_match('has been updated by', result[:body])
  427. assert_match('<b>test123</b>', result[:body])
  428. assert_match('Manage your notifications settings', result[:body])
  429. assert_no_match('Dein', result[:body])
  430. result = NotificationFactory.template(
  431. template: 'ticket_update',
  432. locale: 'de-de',
  433. objects: {
  434. ticket: ticket,
  435. article: article,
  436. recipient: agent1,
  437. changes: changes,
  438. },
  439. )
  440. assert_match('Ticket aktualisiert', result[:subject])
  441. assert_match('Notification&lt;b&gt;xxx&lt;/b&gt;', result[:body])
  442. assert_match('wurde von', result[:body])
  443. assert_match('<b>test123</b>', result[:body])
  444. assert_match('Benachrichtigungseinstellungen Verwalten', result[:body])
  445. assert_no_match('Your', result[:body])
  446. end
  447. test 'notifications settings' do
  448. groups = Group.all
  449. roles = Role.where(name: 'Agent')
  450. agent1 = User.create_or_update(
  451. login: 'notification-settings-agent1@example.com',
  452. firstname: 'Notification<b>xxx</b>',
  453. lastname: 'Agent1',
  454. email: 'notification-settings-agent1@example.com',
  455. password: 'agentpw',
  456. active: true,
  457. roles: roles,
  458. groups: groups,
  459. updated_by_id: 1,
  460. created_by_id: 1,
  461. )
  462. agent2 = User.create_or_update(
  463. login: 'notification-settings-agent2@example.com',
  464. firstname: 'Notification<b>xxx</b>',
  465. lastname: 'Agent2',
  466. email: 'notification-settings-agent2@example.com',
  467. password: 'agentpw',
  468. active: true,
  469. roles: roles,
  470. groups: groups,
  471. updated_by_id: 1,
  472. created_by_id: 1,
  473. )
  474. group_notification_setting = Group.create_or_update(
  475. name: 'NotificationSetting',
  476. updated_by_id: 1,
  477. created_by_id: 1,
  478. )
  479. ticket1 = Ticket.create(
  480. group_id: Group.lookup(name: 'Users').id,
  481. customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
  482. owner_id: User.lookup(login: '-').id,
  483. title: 'Notification Settings Test 1!',
  484. state_id: Ticket::State.lookup(name: 'new').id,
  485. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  486. updated_by_id: 1,
  487. created_by_id: 1,
  488. )
  489. ticket2 = Ticket.create(
  490. group_id: Group.lookup(name: 'Users').id,
  491. customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
  492. owner_id: agent1.id,
  493. title: 'Notification Settings Test 2!',
  494. state_id: Ticket::State.lookup(name: 'new').id,
  495. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  496. updated_by_id: 1,
  497. created_by_id: 1,
  498. )
  499. ticket3 = Ticket.create(
  500. group_id: group_notification_setting.id,
  501. customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
  502. owner_id: User.lookup(login: '-').id,
  503. title: 'Notification Settings Test 1!',
  504. state_id: Ticket::State.lookup(name: 'new').id,
  505. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  506. updated_by_id: 1,
  507. created_by_id: 1,
  508. )
  509. ticket4 = Ticket.create(
  510. group_id: group_notification_setting.id,
  511. customer_id: User.lookup(email: 'nicole.braun@zammad.org').id,
  512. owner_id: agent1.id,
  513. title: 'Notification Settings Test 2!',
  514. state_id: Ticket::State.lookup(name: 'new').id,
  515. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  516. updated_by_id: 1,
  517. created_by_id: 1,
  518. )
  519. agent1.preferences[:notification_config][:group_ids] = nil
  520. agent1.save
  521. result = NotificationFactory.notification_settings(agent1, ticket1, 'create')
  522. assert_equal(true, result[:channels][:online])
  523. assert_equal(true, result[:channels][:email])
  524. result = NotificationFactory.notification_settings(agent1, ticket2, 'create')
  525. assert_equal(true, result[:channels][:online])
  526. assert_equal(true, result[:channels][:email])
  527. result = NotificationFactory.notification_settings(agent1, ticket3, 'create')
  528. assert_equal(true, result[:channels][:online])
  529. assert_equal(true, result[:channels][:email])
  530. result = NotificationFactory.notification_settings(agent1, ticket4, 'create')
  531. assert_equal(true, result[:channels][:online])
  532. assert_equal(true, result[:channels][:email])
  533. agent2.preferences[:notification_config][:group_ids] = nil
  534. agent2.save
  535. result = NotificationFactory.notification_settings(agent2, ticket1, 'create')
  536. assert_equal(true, result[:channels][:online])
  537. assert_equal(true, result[:channels][:email])
  538. result = NotificationFactory.notification_settings(agent2, ticket2, 'create')
  539. assert_equal(nil, result)
  540. result = NotificationFactory.notification_settings(agent2, ticket3, 'create')
  541. assert_equal(true, result[:channels][:online])
  542. assert_equal(true, result[:channels][:email])
  543. result = NotificationFactory.notification_settings(agent2, ticket4, 'create')
  544. assert_equal(nil, result)
  545. # no group selection
  546. agent1.preferences[:notification_config][:group_ids] = []
  547. agent1.save
  548. result = NotificationFactory.notification_settings(agent1, ticket1, 'create')
  549. assert_equal(true, result[:channels][:online])
  550. assert_equal(true, result[:channels][:email])
  551. result = NotificationFactory.notification_settings(agent1, ticket2, 'create')
  552. assert_equal(true, result[:channels][:online])
  553. assert_equal(true, result[:channels][:email])
  554. result = NotificationFactory.notification_settings(agent1, ticket3, 'create')
  555. assert_equal(true, result[:channels][:online])
  556. assert_equal(true, result[:channels][:email])
  557. result = NotificationFactory.notification_settings(agent1, ticket4, 'create')
  558. assert_equal(true, result[:channels][:online])
  559. assert_equal(true, result[:channels][:email])
  560. agent2.preferences[:notification_config][:group_ids] = []
  561. agent2.save
  562. result = NotificationFactory.notification_settings(agent2, ticket1, 'create')
  563. assert_equal(true, result[:channels][:online])
  564. assert_equal(true, result[:channels][:email])
  565. result = NotificationFactory.notification_settings(agent2, ticket2, 'create')
  566. assert_equal(nil, result)
  567. result = NotificationFactory.notification_settings(agent2, ticket3, 'create')
  568. assert_equal(true, result[:channels][:online])
  569. assert_equal(true, result[:channels][:email])
  570. result = NotificationFactory.notification_settings(agent2, ticket4, 'create')
  571. assert_equal(nil, result)
  572. agent1.preferences[:notification_config][:group_ids] = ['-']
  573. agent1.save
  574. result = NotificationFactory.notification_settings(agent1, ticket1, 'create')
  575. assert_equal(true, result[:channels][:online])
  576. assert_equal(true, result[:channels][:email])
  577. result = NotificationFactory.notification_settings(agent1, ticket2, 'create')
  578. assert_equal(true, result[:channels][:online])
  579. assert_equal(true, result[:channels][:email])
  580. result = NotificationFactory.notification_settings(agent1, ticket3, 'create')
  581. assert_equal(true, result[:channels][:online])
  582. assert_equal(true, result[:channels][:email])
  583. result = NotificationFactory.notification_settings(agent1, ticket4, 'create')
  584. assert_equal(true, result[:channels][:online])
  585. assert_equal(true, result[:channels][:email])
  586. agent2.preferences[:notification_config][:group_ids] = ['-']
  587. agent2.save
  588. result = NotificationFactory.notification_settings(agent2, ticket1, 'create')
  589. assert_equal(true, result[:channels][:online])
  590. assert_equal(true, result[:channels][:email])
  591. result = NotificationFactory.notification_settings(agent2, ticket2, 'create')
  592. assert_equal(nil, result)
  593. result = NotificationFactory.notification_settings(agent2, ticket3, 'create')
  594. assert_equal(true, result[:channels][:online])
  595. assert_equal(true, result[:channels][:email])
  596. result = NotificationFactory.notification_settings(agent2, ticket4, 'create')
  597. assert_equal(nil, result)
  598. # dedecated group selection
  599. agent1.preferences[:notification_config][:group_ids] = [Group.lookup(name: 'Users').id]
  600. agent1.save
  601. result = NotificationFactory.notification_settings(agent1, ticket1, 'create')
  602. assert_equal(true, result[:channels][:online])
  603. assert_equal(true, result[:channels][:email])
  604. result = NotificationFactory.notification_settings(agent1, ticket2, 'create')
  605. assert_equal(true, result[:channels][:online])
  606. assert_equal(true, result[:channels][:email])
  607. result = NotificationFactory.notification_settings(agent1, ticket3, 'create')
  608. assert_equal(nil, result)
  609. result = NotificationFactory.notification_settings(agent1, ticket4, 'create')
  610. assert_equal(true, result[:channels][:online])
  611. assert_equal(true, result[:channels][:email])
  612. agent2.preferences[:notification_config][:group_ids] = [Group.lookup(name: 'Users').id]
  613. agent2.save
  614. result = NotificationFactory.notification_settings(agent2, ticket1, 'create')
  615. assert_equal(true, result[:channels][:online])
  616. assert_equal(true, result[:channels][:email])
  617. result = NotificationFactory.notification_settings(agent2, ticket2, 'create')
  618. assert_equal(nil, result)
  619. result = NotificationFactory.notification_settings(agent2, ticket3, 'create')
  620. assert_equal(nil, result)
  621. assert_equal(nil, result)
  622. result = NotificationFactory.notification_settings(agent2, ticket4, 'create')
  623. assert_equal(nil, result)
  624. end
  625. end