ticket_notification_test.rb 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class TicketNotificationTest < ActiveSupport::TestCase
  4. # create agent1 & agent2
  5. groups = Group.where(name: 'Users')
  6. roles = Role.where(name: 'Agent')
  7. agent1 = User.create_or_update(
  8. login: 'ticket-notification-agent1@example.com',
  9. firstname: 'Notification',
  10. lastname: 'Agent1',
  11. email: 'ticket-notification-agent1@example.com',
  12. password: 'agentpw',
  13. active: true,
  14. roles: roles,
  15. groups: groups,
  16. preferences: {
  17. locale: 'de-de',
  18. },
  19. updated_by_id: 1,
  20. created_by_id: 1,
  21. )
  22. agent2 = User.create_or_update(
  23. login: 'ticket-notification-agent2@example.com',
  24. firstname: 'Notification',
  25. lastname: 'Agent2',
  26. email: 'ticket-notification-agent2@example.com',
  27. password: 'agentpw',
  28. active: true,
  29. roles: roles,
  30. groups: groups,
  31. preferences: {
  32. locale: 'en-ca',
  33. },
  34. updated_by_id: 1,
  35. created_by_id: 1,
  36. )
  37. Group.create_if_not_exists(
  38. name: 'WithoutAccess',
  39. note: 'Test for notification check.',
  40. updated_by_id: 1,
  41. created_by_id: 1
  42. )
  43. # create customer
  44. roles = Role.where(name: 'Customer')
  45. customer = User.create_or_update(
  46. login: 'ticket-notification-customer@example.com',
  47. firstname: 'Notification',
  48. lastname: 'Customer',
  49. email: 'ticket-notification-customer@example.com',
  50. password: 'agentpw',
  51. active: true,
  52. roles: roles,
  53. groups: groups,
  54. updated_by_id: 1,
  55. created_by_id: 1,
  56. )
  57. test 'ticket notification - to all agents / to explicit agents' do
  58. # create ticket in group
  59. ticket1 = Ticket.create(
  60. title: 'some notification test 1',
  61. group: Group.lookup(name: 'Users'),
  62. customer: agent1,
  63. state: Ticket::State.lookup(name: 'new'),
  64. priority: Ticket::Priority.lookup(name: '2 normal'),
  65. updated_by_id: agent1.id,
  66. created_by_id: agent1.id,
  67. )
  68. Ticket::Article.create(
  69. ticket_id: ticket1.id,
  70. from: 'some_sender@example.com',
  71. to: 'some_recipient@example.com',
  72. subject: 'some subject',
  73. message_id: 'some@id',
  74. body: 'some message',
  75. internal: false,
  76. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  77. type: Ticket::Article::Type.where(name: 'email').first,
  78. updated_by_id: agent1.id,
  79. created_by_id: agent1.id,
  80. )
  81. assert(ticket1)
  82. # execute object transaction
  83. Rails.configuration.webserver_is_active = nil
  84. Observer::Transaction.commit
  85. Scheduler.worker(true)
  86. # verify notifications to agent1 + agent2
  87. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id)
  88. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
  89. # create ticket in group
  90. ticket1 = Ticket.create(
  91. title: 'some notification test 1',
  92. group: Group.lookup(name: 'Users'),
  93. customer: agent1,
  94. state: Ticket::State.lookup(name: 'new'),
  95. priority: Ticket::Priority.lookup(name: '2 normal'),
  96. updated_by_id: agent1.id,
  97. created_by_id: agent1.id,
  98. )
  99. Ticket::Article.create(
  100. ticket_id: ticket1.id,
  101. from: 'some_sender@example.com',
  102. to: 'some_recipient@example.com',
  103. subject: 'some subject',
  104. message_id: 'some@id',
  105. body: 'some message',
  106. internal: false,
  107. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  108. type: Ticket::Article::Type.where(name: 'email').first,
  109. updated_by_id: agent1.id,
  110. created_by_id: agent1.id,
  111. )
  112. assert(ticket1)
  113. # execute object transaction
  114. Rails.configuration.webserver_is_active = true
  115. Observer::Transaction.commit
  116. Scheduler.worker(true)
  117. # verify notifications to agent1 + agent2
  118. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id)
  119. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
  120. end
  121. test 'ticket notification - simple' do
  122. # create ticket in group
  123. ticket1 = Ticket.create(
  124. title: 'some notification test 1',
  125. group: Group.lookup(name: 'Users'),
  126. customer: customer,
  127. state: Ticket::State.lookup(name: 'new'),
  128. priority: Ticket::Priority.lookup(name: '2 normal'),
  129. updated_by_id: customer.id,
  130. created_by_id: customer.id,
  131. )
  132. Ticket::Article.create(
  133. ticket_id: ticket1.id,
  134. from: 'some_sender@example.com',
  135. to: 'some_recipient@example.com',
  136. subject: 'some subject',
  137. message_id: 'some@id',
  138. body: 'some message',
  139. internal: false,
  140. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  141. type: Ticket::Article::Type.where(name: 'email').first,
  142. updated_by_id: customer.id,
  143. created_by_id: customer.id,
  144. )
  145. assert(ticket1, 'ticket created - ticket notification simple')
  146. # execute object transaction
  147. Rails.configuration.webserver_is_active = true
  148. Observer::Transaction.commit
  149. Scheduler.worker(true)
  150. # verify notifications to agent1 + agent2
  151. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id)
  152. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
  153. # update ticket attributes
  154. ticket1.title = "#{ticket1.title} - #2"
  155. ticket1.priority = Ticket::Priority.lookup(name: '3 high')
  156. ticket1.save
  157. # execute object transaction
  158. Observer::Transaction.commit
  159. Scheduler.worker(true)
  160. # verify notifications to agent1 + agent2
  161. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id)
  162. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
  163. # add article to ticket
  164. Ticket::Article.create(
  165. ticket_id: ticket1.id,
  166. from: 'some person',
  167. subject: 'some note',
  168. body: 'some message',
  169. internal: true,
  170. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  171. type: Ticket::Article::Type.where(name: 'note').first,
  172. updated_by_id: agent1.id,
  173. created_by_id: agent1.id,
  174. )
  175. # execute object transaction
  176. Observer::Transaction.commit
  177. Scheduler.worker(true)
  178. # verify notifications to not to agent1 but to agent2
  179. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id)
  180. assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
  181. # update ticket by user
  182. ticket1.owner_id = agent1.id
  183. ticket1.updated_by_id = agent1.id
  184. ticket1.save
  185. Ticket::Article.create(
  186. ticket_id: ticket1.id,
  187. from: 'some person',
  188. subject: 'some note',
  189. body: 'some message',
  190. internal: true,
  191. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  192. type: Ticket::Article::Type.where(name: 'note').first,
  193. updated_by_id: agent1.id,
  194. created_by_id: agent1.id,
  195. )
  196. # execute object transaction
  197. Observer::Transaction.commit
  198. Scheduler.worker(true)
  199. # verify notifications to not to agent1 but to agent2
  200. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id)
  201. assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
  202. # create ticket with agent1 as owner
  203. ticket2 = Ticket.create(
  204. title: 'some notification test 2',
  205. group: Group.lookup(name: 'Users'),
  206. customer_id: 2,
  207. owner_id: agent1.id,
  208. state: Ticket::State.lookup(name: 'new'),
  209. priority: Ticket::Priority.lookup(name: '2 normal'),
  210. updated_by_id: agent1.id,
  211. created_by_id: agent1.id,
  212. )
  213. Ticket::Article.create(
  214. ticket_id: ticket2.id,
  215. from: 'some_sender@example.com',
  216. to: 'some_recipient@example.com',
  217. subject: 'some subject',
  218. message_id: 'some@id',
  219. body: 'some message',
  220. internal: false,
  221. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  222. type: Ticket::Article::Type.where(name: 'phone').first,
  223. updated_by_id: agent1.id,
  224. created_by_id: agent1.id,
  225. )
  226. # execute object transaction
  227. Observer::Transaction.commit
  228. Scheduler.worker(true)
  229. assert(ticket2, 'ticket created')
  230. # verify notifications to no one
  231. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id)
  232. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id)
  233. # update ticket
  234. ticket2.title = "#{ticket2.title} - #2"
  235. ticket2.updated_by_id = agent1.id
  236. ticket2.priority = Ticket::Priority.lookup(name: '3 high')
  237. ticket2.save
  238. # execute object transaction
  239. Observer::Transaction.commit
  240. Scheduler.worker(true)
  241. # verify notifications to none
  242. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id)
  243. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id)
  244. # update ticket
  245. ticket2.title = "#{ticket2.title} - #3"
  246. ticket2.updated_by_id = agent2.id
  247. ticket2.priority = Ticket::Priority.lookup(name: '2 normal')
  248. ticket2.save
  249. # execute object transaction
  250. Observer::Transaction.commit
  251. Scheduler.worker(true)
  252. # verify notifications to agent1 and not to agent2
  253. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id)
  254. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id)
  255. # create ticket with agent2 and agent1 as owner
  256. ticket3 = Ticket.create(
  257. title: 'some notification test 3',
  258. group: Group.lookup(name: 'Users'),
  259. customer_id: 2,
  260. owner_id: agent1.id,
  261. state: Ticket::State.lookup(name: 'new'),
  262. priority: Ticket::Priority.lookup(name: '2 normal'),
  263. updated_by_id: agent2.id,
  264. created_by_id: agent2.id,
  265. )
  266. article_inbound = Ticket::Article.create(
  267. ticket_id: ticket3.id,
  268. from: 'some_sender@example.com',
  269. to: 'some_recipient@example.com',
  270. subject: 'some subject',
  271. message_id: 'some@id',
  272. body: 'some message',
  273. internal: false,
  274. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  275. type: Ticket::Article::Type.where(name: 'phone').first,
  276. updated_by_id: agent2.id,
  277. created_by_id: agent2.id,
  278. )
  279. # execute object transaction
  280. Observer::Transaction.commit
  281. Scheduler.worker(true)
  282. assert(ticket3, 'ticket created')
  283. # verify notifications to agent1 and not to agent2
  284. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id)
  285. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id)
  286. # update ticket
  287. ticket3.title = "#{ticket3.title} - #2"
  288. ticket3.updated_by_id = agent1.id
  289. ticket3.priority = Ticket::Priority.lookup(name: '3 high')
  290. ticket3.save
  291. # execute object transaction
  292. Observer::Transaction.commit
  293. Scheduler.worker(true)
  294. # verify notifications to no one
  295. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id)
  296. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id)
  297. # update ticket
  298. ticket3.title = "#{ticket3.title} - #3"
  299. ticket3.updated_by_id = agent2.id
  300. ticket3.priority = Ticket::Priority.lookup(name: '2 normal')
  301. ticket3.save
  302. # execute object transaction
  303. Observer::Transaction.commit
  304. Scheduler.worker(true)
  305. # verify notifications to agent1 and not to agent2
  306. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id)
  307. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id)
  308. # update article / not notification should be sent
  309. article_inbound.internal = true
  310. article_inbound.save
  311. # execute object transaction
  312. Observer::Transaction.commit
  313. Scheduler.worker(true)
  314. # verify notifications not to agent1 and not to agent2
  315. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id)
  316. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id)
  317. delete = ticket1.destroy
  318. assert(delete, 'ticket1 destroy')
  319. delete = ticket2.destroy
  320. assert(delete, 'ticket2 destroy')
  321. delete = ticket3.destroy
  322. assert(delete, 'ticket3 destroy')
  323. end
  324. test 'ticket notification - no notification' do
  325. # create ticket in group
  326. ticket1 = Ticket.create(
  327. title: 'some notification test 1 - no notification',
  328. group: Group.lookup(name: 'Users'),
  329. customer: customer,
  330. state: Ticket::State.lookup(name: 'new'),
  331. priority: Ticket::Priority.lookup(name: '2 normal'),
  332. updated_by_id: customer.id,
  333. created_by_id: customer.id,
  334. )
  335. Ticket::Article.create(
  336. ticket_id: ticket1.id,
  337. from: 'some_sender@example.com',
  338. to: 'some_recipient@example.com',
  339. subject: 'some subject',
  340. message_id: 'some@id',
  341. body: 'some message',
  342. internal: false,
  343. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  344. type: Ticket::Article::Type.where(name: 'email').first,
  345. updated_by_id: customer.id,
  346. created_by_id: customer.id,
  347. )
  348. assert(ticket1, 'ticket created - ticket no notification')
  349. # execute object transaction
  350. Observer::Transaction.commit(disable_notification: true)
  351. Scheduler.worker(true)
  352. # verify notifications to agent1 + agent2
  353. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id)
  354. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
  355. end
  356. test 'ticket notification - z preferences tests' do
  357. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
  358. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  359. agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = false
  360. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
  361. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  362. agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = false
  363. agent1.save
  364. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
  365. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  366. agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
  367. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
  368. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  369. agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
  370. agent2.save
  371. # create ticket in group
  372. ticket1 = Ticket.create(
  373. title: 'some notification test - z preferences tests 1',
  374. group: Group.lookup(name: 'Users'),
  375. customer: customer,
  376. state: Ticket::State.lookup(name: 'new'),
  377. priority: Ticket::Priority.lookup(name: '2 normal'),
  378. updated_by_id: customer.id,
  379. created_by_id: customer.id,
  380. )
  381. Ticket::Article.create(
  382. ticket_id: ticket1.id,
  383. from: 'some_sender@example.com',
  384. to: 'some_recipient@example.com',
  385. subject: 'some subject',
  386. message_id: 'some@id',
  387. body: 'some message',
  388. internal: false,
  389. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  390. type: Ticket::Article::Type.where(name: 'email').first,
  391. updated_by_id: customer.id,
  392. created_by_id: customer.id,
  393. )
  394. # execute object transaction
  395. Rails.configuration.webserver_is_active = false
  396. Observer::Transaction.commit
  397. Scheduler.worker(true)
  398. # verify notifications to agent1 + agent2
  399. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id)
  400. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
  401. # update ticket attributes
  402. ticket1.title = "#{ticket1.title} - #2"
  403. ticket1.priority = Ticket::Priority.lookup(name: '3 high')
  404. ticket1.save
  405. # execute object transaction
  406. Observer::Transaction.commit
  407. Scheduler.worker(true)
  408. # verify notifications to agent1 + agent2
  409. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id)
  410. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id)
  411. # create ticket in group
  412. ticket2 = Ticket.create(
  413. title: 'some notification test - z preferences tests 2',
  414. group: Group.lookup(name: 'Users'),
  415. customer: customer,
  416. owner: agent1,
  417. state: Ticket::State.lookup(name: 'new'),
  418. priority: Ticket::Priority.lookup(name: '2 normal'),
  419. updated_by_id: customer.id,
  420. created_by_id: customer.id,
  421. )
  422. Ticket::Article.create(
  423. ticket_id: ticket2.id,
  424. from: 'some_sender@example.com',
  425. to: 'some_recipient@example.com',
  426. subject: 'some subject',
  427. message_id: 'some@id',
  428. body: 'some message',
  429. internal: false,
  430. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  431. type: Ticket::Article::Type.where(name: 'email').first,
  432. updated_by_id: customer.id,
  433. created_by_id: customer.id,
  434. )
  435. # execute object transaction
  436. Observer::Transaction.commit
  437. Scheduler.worker(true)
  438. # verify notifications to agent1 + agent2
  439. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id)
  440. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id)
  441. # update ticket attributes
  442. ticket2.title = "#{ticket2.title} - #2"
  443. ticket2.priority = Ticket::Priority.lookup(name: '3 high')
  444. ticket2.save
  445. # execute object transaction
  446. Observer::Transaction.commit
  447. Scheduler.worker(true)
  448. # verify notifications to agent1 + agent2
  449. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id)
  450. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id)
  451. # create ticket in group
  452. ticket3 = Ticket.create(
  453. title: 'some notification test - z preferences tests 3',
  454. group: Group.lookup(name: 'Users'),
  455. customer: customer,
  456. owner: agent2,
  457. state: Ticket::State.lookup(name: 'new'),
  458. priority: Ticket::Priority.lookup(name: '2 normal'),
  459. updated_by_id: customer.id,
  460. created_by_id: customer.id,
  461. )
  462. Ticket::Article.create(
  463. ticket_id: ticket3.id,
  464. from: 'some_sender@example.com',
  465. to: 'some_recipient@example.com',
  466. subject: 'some subject',
  467. message_id: 'some@id',
  468. body: 'some message',
  469. internal: false,
  470. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  471. type: Ticket::Article::Type.where(name: 'email').first,
  472. updated_by_id: customer.id,
  473. created_by_id: customer.id,
  474. )
  475. # execute object transaction
  476. Observer::Transaction.commit
  477. Scheduler.worker(true)
  478. # verify notifications to agent1 + agent2
  479. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id)
  480. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id)
  481. # update ticket attributes
  482. ticket3.title = "#{ticket3.title} - #2"
  483. ticket3.priority = Ticket::Priority.lookup(name: '3 high')
  484. ticket3.save
  485. # execute object transaction
  486. Observer::Transaction.commit
  487. Scheduler.worker(true)
  488. # verify notifications to agent1 + agent2
  489. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id)
  490. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id)
  491. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
  492. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  493. agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
  494. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
  495. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  496. agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
  497. agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'Users').id.to_s]
  498. agent1.save
  499. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
  500. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  501. agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
  502. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
  503. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  504. agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
  505. agent1.preferences['notification_config']['group_ids'] = ['-']
  506. agent2.save
  507. # create ticket in group
  508. ticket4 = Ticket.create(
  509. title: 'some notification test - z preferences tests 4',
  510. group: Group.lookup(name: 'Users'),
  511. customer: customer,
  512. state: Ticket::State.lookup(name: 'new'),
  513. priority: Ticket::Priority.lookup(name: '2 normal'),
  514. updated_by_id: customer.id,
  515. created_by_id: customer.id,
  516. )
  517. Ticket::Article.create(
  518. ticket_id: ticket4.id,
  519. from: 'some_sender@example.com',
  520. to: 'some_recipient@example.com',
  521. subject: 'some subject',
  522. message_id: 'some@id',
  523. body: 'some message',
  524. internal: false,
  525. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  526. type: Ticket::Article::Type.where(name: 'email').first,
  527. updated_by_id: customer.id,
  528. created_by_id: customer.id,
  529. )
  530. # execute object transaction
  531. Rails.configuration.webserver_is_active = false
  532. Observer::Transaction.commit
  533. Scheduler.worker(true)
  534. # verify notifications to agent1 + agent2
  535. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket4, agent1, 'email'), ticket4.id)
  536. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket4, agent2, 'email'), ticket4.id)
  537. # update ticket attributes
  538. ticket4.title = "#{ticket4.title} - #2"
  539. ticket4.priority = Ticket::Priority.lookup(name: '3 high')
  540. ticket4.save
  541. # execute object transaction
  542. Observer::Transaction.commit
  543. Scheduler.worker(true)
  544. # verify notifications to agent1 + agent2
  545. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket4, agent1, 'email'), ticket4.id)
  546. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket4, agent2, 'email'), ticket4.id)
  547. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
  548. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  549. agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
  550. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
  551. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  552. agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
  553. agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'Users').id.to_s]
  554. agent1.save
  555. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false
  556. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  557. agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
  558. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false
  559. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  560. agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
  561. agent2.preferences['notification_config']['group_ids'] = [99]
  562. agent2.save
  563. # create ticket in group
  564. ticket5 = Ticket.create(
  565. title: 'some notification test - z preferences tests 5',
  566. group: Group.lookup(name: 'Users'),
  567. customer: customer,
  568. state: Ticket::State.lookup(name: 'new'),
  569. priority: Ticket::Priority.lookup(name: '2 normal'),
  570. updated_by_id: customer.id,
  571. created_by_id: customer.id,
  572. )
  573. Ticket::Article.create(
  574. ticket_id: ticket5.id,
  575. from: 'some_sender@example.com',
  576. to: 'some_recipient@example.com',
  577. subject: 'some subject',
  578. message_id: 'some@id',
  579. body: 'some message',
  580. internal: false,
  581. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  582. type: Ticket::Article::Type.where(name: 'email').first,
  583. updated_by_id: customer.id,
  584. created_by_id: customer.id,
  585. )
  586. # execute object transaction
  587. Rails.configuration.webserver_is_active = false
  588. Observer::Transaction.commit
  589. Scheduler.worker(true)
  590. # verify notifications to agent1 + agent2
  591. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket5, agent1, 'email'), ticket5.id)
  592. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket5, agent2, 'email'), ticket5.id)
  593. # update ticket attributes
  594. ticket5.title = "#{ticket5.title} - #2"
  595. ticket5.priority = Ticket::Priority.lookup(name: '3 high')
  596. ticket5.save
  597. # execute object transaction
  598. Observer::Transaction.commit
  599. Scheduler.worker(true)
  600. # verify notifications to agent1 + agent2
  601. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket5, agent1, 'email'), ticket5.id)
  602. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket5, agent2, 'email'), ticket5.id)
  603. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
  604. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  605. agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
  606. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
  607. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  608. agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
  609. agent1.preferences['notification_config']['group_ids'] = [999]
  610. agent1.save
  611. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
  612. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  613. agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
  614. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
  615. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  616. agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
  617. agent2.preferences['notification_config']['group_ids'] = [999]
  618. agent2.save
  619. # create ticket in group
  620. ticket6 = Ticket.create(
  621. title: 'some notification test - z preferences tests 6',
  622. group: Group.lookup(name: 'Users'),
  623. customer: customer,
  624. owner: agent1,
  625. state: Ticket::State.lookup(name: 'new'),
  626. priority: Ticket::Priority.lookup(name: '2 normal'),
  627. updated_by_id: customer.id,
  628. created_by_id: customer.id,
  629. )
  630. Ticket::Article.create(
  631. ticket_id: ticket6.id,
  632. from: 'some_sender@example.com',
  633. to: 'some_recipient@example.com',
  634. subject: 'some subject',
  635. message_id: 'some@id',
  636. body: 'some message',
  637. internal: false,
  638. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  639. type: Ticket::Article::Type.where(name: 'email').first,
  640. updated_by_id: customer.id,
  641. created_by_id: customer.id,
  642. )
  643. # execute object transaction
  644. Rails.configuration.webserver_is_active = false
  645. Observer::Transaction.commit
  646. Scheduler.worker(true)
  647. # verify notifications to agent1 + agent2
  648. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'email'), ticket6.id)
  649. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'online'), ticket6.id)
  650. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, agent2, 'email'), ticket6.id)
  651. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, agent2, 'online'), ticket6.id)
  652. # update ticket attributes
  653. ticket6.title = "#{ticket6.title} - #2"
  654. ticket6.priority = Ticket::Priority.lookup(name: '3 high')
  655. ticket6.save
  656. # execute object transaction
  657. Observer::Transaction.commit
  658. Scheduler.worker(true)
  659. # verify notifications to agent1 + agent2
  660. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'email'), ticket6.id)
  661. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'online'), ticket6.id)
  662. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, agent2, 'email'), ticket6.id)
  663. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, agent2, 'online'), ticket6.id)
  664. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
  665. agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  666. agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
  667. agent1.preferences['notification_config']['matrix']['create']['channel']['email'] = false
  668. agent1.preferences['notification_config']['matrix']['create']['channel']['online'] = true
  669. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
  670. agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  671. agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
  672. agent1.preferences['notification_config']['matrix']['update']['channel']['email'] = false
  673. agent1.preferences['notification_config']['matrix']['update']['channel']['online'] = true
  674. agent1.preferences['notification_config']['group_ids'] = [999]
  675. agent1.save
  676. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true
  677. agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false
  678. agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true
  679. agent2.preferences['notification_config']['matrix']['create']['channel']['email'] = false
  680. agent2.preferences['notification_config']['matrix']['create']['channel']['online'] = true
  681. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true
  682. agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false
  683. agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true
  684. agent2.preferences['notification_config']['matrix']['update']['channel']['email'] = false
  685. agent2.preferences['notification_config']['matrix']['update']['channel']['online'] = true
  686. agent2.preferences['notification_config']['group_ids'] = [999]
  687. agent2.save
  688. # create ticket in group
  689. ticket7 = Ticket.create(
  690. title: 'some notification test - z preferences tests 7',
  691. group: Group.lookup(name: 'Users'),
  692. customer: customer,
  693. owner: agent1,
  694. state: Ticket::State.lookup(name: 'new'),
  695. priority: Ticket::Priority.lookup(name: '2 normal'),
  696. updated_by_id: customer.id,
  697. created_by_id: customer.id,
  698. )
  699. Ticket::Article.create(
  700. ticket_id: ticket7.id,
  701. from: 'some_sender@example.com',
  702. to: 'some_recipient@example.com',
  703. subject: 'some subject',
  704. message_id: 'some@id',
  705. body: 'some message',
  706. internal: false,
  707. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  708. type: Ticket::Article::Type.where(name: 'email').first,
  709. updated_by_id: customer.id,
  710. created_by_id: customer.id,
  711. )
  712. # execute object transaction
  713. Rails.configuration.webserver_is_active = false
  714. Observer::Transaction.commit
  715. Scheduler.worker(true)
  716. # verify notifications to agent1 + agent2
  717. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'email'), ticket7.id)
  718. assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'online'), ticket7.id)
  719. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent2, 'email'), ticket7.id)
  720. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent2, 'online'), ticket7.id)
  721. # update ticket attributes
  722. ticket7.title = "#{ticket7.title} - #2"
  723. ticket7.priority = Ticket::Priority.lookup(name: '3 high')
  724. ticket7.save
  725. # execute object transaction
  726. Observer::Transaction.commit
  727. Scheduler.worker(true)
  728. # verify notifications to agent1 + agent2
  729. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'email'), ticket7.id)
  730. assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'online'), ticket7.id)
  731. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent2, 'email'), ticket7.id)
  732. assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent2, 'online'), ticket7.id)
  733. end
  734. test 'ticket notification events' do
  735. # create ticket in group
  736. ticket1 = Ticket.create(
  737. title: 'some notification event test 1',
  738. group: Group.lookup(name: 'Users'),
  739. customer: customer,
  740. state: Ticket::State.lookup(name: 'new'),
  741. priority: Ticket::Priority.lookup(name: '2 normal'),
  742. updated_by_id: customer.id,
  743. created_by_id: customer.id,
  744. )
  745. Ticket::Article.create(
  746. ticket_id: ticket1.id,
  747. from: 'some_sender@example.com',
  748. to: 'some_recipient@example.com',
  749. subject: 'some subject',
  750. message_id: 'some@id',
  751. body: 'some message',
  752. internal: false,
  753. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  754. type: Ticket::Article::Type.where(name: 'email').first,
  755. updated_by_id: customer.id,
  756. created_by_id: customer.id,
  757. )
  758. assert(ticket1, 'ticket created')
  759. # execute object transaction
  760. Observer::Transaction.commit
  761. # update ticket attributes
  762. ticket1.title = "#{ticket1.title} - #2"
  763. ticket1.priority = Ticket::Priority.lookup(name: '3 high')
  764. ticket1.save
  765. list = EventBuffer.list('transaction')
  766. list_objects = Observer::Transaction.get_uniq_changes(list)
  767. assert_equal('some notification event test 1', list_objects['Ticket'][ticket1.id][:changes]['title'][0])
  768. assert_equal('some notification event test 1 - #2', list_objects['Ticket'][ticket1.id][:changes]['title'][1])
  769. assert_not(list_objects['Ticket'][ticket1.id][:changes]['priority'])
  770. assert_equal(2, list_objects['Ticket'][ticket1.id][:changes]['priority_id'][0])
  771. assert_equal(3, list_objects['Ticket'][ticket1.id][:changes]['priority_id'][1])
  772. # update ticket attributes
  773. ticket1.title = "#{ticket1.title} - #3"
  774. ticket1.priority = Ticket::Priority.lookup(name: '1 low')
  775. ticket1.save
  776. list = EventBuffer.list('transaction')
  777. list_objects = Observer::Transaction.get_uniq_changes(list)
  778. assert_equal('some notification event test 1', list_objects['Ticket'][ticket1.id][:changes]['title'][0])
  779. assert_equal('some notification event test 1 - #2 - #3', list_objects['Ticket'][ticket1.id][:changes]['title'][1])
  780. assert_not(list_objects['Ticket'][ticket1.id][:changes]['priority'])
  781. assert_equal(2, list_objects['Ticket'][ticket1.id][:changes]['priority_id'][0])
  782. assert_equal(1, list_objects['Ticket'][ticket1.id][:changes]['priority_id'][1])
  783. end
  784. test 'ticket notification template' do
  785. # create ticket in group
  786. ticket1 = Ticket.create(
  787. title: 'some notification template test 1 Bobs\'s resumé',
  788. group: Group.lookup(name: 'Users'),
  789. customer: customer,
  790. state: Ticket::State.lookup(name: 'new'),
  791. priority: Ticket::Priority.lookup(name: '2 normal'),
  792. updated_by_id: customer.id,
  793. created_by_id: customer.id,
  794. )
  795. article = Ticket::Article.create(
  796. ticket_id: ticket1.id,
  797. from: 'some_sender@example.com',
  798. to: 'some_recipient@example.com',
  799. subject: 'some subject',
  800. message_id: 'some@id',
  801. body: "some message\nnewline1 abc\nnewline2",
  802. internal: false,
  803. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  804. type: Ticket::Article::Type.where(name: 'email').first,
  805. updated_by_id: customer.id,
  806. created_by_id: customer.id,
  807. )
  808. assert(ticket1, 'ticket created - ticket notification template')
  809. bg = Transaction::Notification.new(
  810. ticket_id: ticket1.id,
  811. article_id: article.id,
  812. type: 'update',
  813. changes: {
  814. 'priority_id' => [1, 2],
  815. 'pending_time' => [nil, Time.zone.parse('2015-01-11 23:33:47 UTC')],
  816. },
  817. user_id: ticket1.updated_by_id,
  818. )
  819. # check changed attributes
  820. human_changes = bg.human_changes(agent2, ticket1)
  821. assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute')
  822. assert(human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute')
  823. assert_equal('1 low', human_changes['Priority'][0])
  824. assert_equal('2 normal', human_changes['Priority'][1])
  825. assert_equal('', human_changes['Pending till'][0].to_s)
  826. assert_equal('2015-01-11 23:33:47 UTC', human_changes['Pending till'][1].to_s)
  827. assert_not(human_changes['priority_id'])
  828. assert_not(human_changes['pending_time'])
  829. assert_not(human_changes['pending_till'])
  830. # en notification
  831. result = NotificationFactory::Mailer.template(
  832. locale: agent2.preferences[:locale],
  833. template: 'ticket_update',
  834. objects: {
  835. ticket: ticket1,
  836. article: article,
  837. recipient: agent2,
  838. changes: human_changes,
  839. },
  840. )
  841. assert_match(/Bobs's resumé/, result[:subject])
  842. assert_match(/Priority/, result[:body])
  843. assert_match(/1 low/, result[:body])
  844. assert_match(/2 normal/, result[:body])
  845. assert_match(/Pending till/, result[:body])
  846. assert_match(/2015-01-11 23:33:47 UTC/, result[:body])
  847. assert_match(/update/, result[:body])
  848. assert_no_match(/pending_till/, result[:body])
  849. assert_no_match(/i18n/, result[:body])
  850. human_changes = bg.human_changes(agent1, ticket1)
  851. assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute')
  852. assert(human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute')
  853. assert_equal('1 niedrig', human_changes['Priority'][0])
  854. assert_equal('2 normal', human_changes['Priority'][1])
  855. assert_equal('', human_changes['Pending till'][0].to_s)
  856. assert_equal('2015-01-11 23:33:47 UTC', human_changes['Pending till'][1].to_s)
  857. assert_not(human_changes['priority_id'])
  858. assert_not(human_changes['pending_time'])
  859. assert_not(human_changes['pending_till'])
  860. # de notification
  861. result = NotificationFactory::Mailer.template(
  862. locale: agent1.preferences[:locale],
  863. template: 'ticket_update',
  864. objects: {
  865. ticket: ticket1,
  866. article: article,
  867. recipient: agent1,
  868. changes: human_changes,
  869. },
  870. )
  871. assert_match(/Bobs's resumé/, result[:subject])
  872. assert_match(/Priorität/, result[:body])
  873. assert_match(/1 niedrig/, result[:body])
  874. assert_match(/2 normal/, result[:body])
  875. assert_match(/Warten/, result[:body])
  876. assert_match(/2015-01-11 23:33:47 UTC/, result[:body])
  877. assert_match(/aktualis/, result[:body])
  878. assert_no_match(/pending_till/, result[:body])
  879. assert_no_match(/i18n/, result[:body])
  880. bg = Transaction::Notification.new(
  881. ticket_id: ticket1.id,
  882. article_id: article.id,
  883. type: 'update',
  884. changes: {
  885. title: ['some notification template test old 1', 'some notification template test 1 #2'],
  886. priority_id: [2, 3],
  887. },
  888. user_id: customer.id,
  889. )
  890. # check changed attributes
  891. human_changes = bg.human_changes(agent1, ticket1)
  892. assert(human_changes['Title'], 'Check if attributes translated based on ObjectManager::Attribute')
  893. assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute')
  894. assert_equal('2 normal', human_changes['Priority'][0])
  895. assert_equal('3 hoch', human_changes['Priority'][1])
  896. assert_equal('some notification template test old 1', human_changes['Title'][0])
  897. assert_equal('some notification template test 1 #2', human_changes['Title'][1])
  898. assert_not(human_changes['priority_id'])
  899. assert_not(human_changes['pending_time'])
  900. assert_not(human_changes['pending_till'])
  901. # de notification
  902. result = NotificationFactory::Mailer.template(
  903. locale: agent1.preferences[:locale],
  904. template: 'ticket_update',
  905. objects: {
  906. ticket: ticket1,
  907. article: article,
  908. recipient: agent1,
  909. changes: human_changes,
  910. }
  911. )
  912. assert_match(/Bobs's resumé/, result[:subject])
  913. assert_match(/Titel/, result[:body])
  914. assert_no_match(/Title/, result[:body])
  915. assert_match(/some notification template test old 1/, result[:body])
  916. assert_match(/some notification template test 1 #2/, result[:body])
  917. assert_match(/Priorität/, result[:body])
  918. assert_no_match(/Priority/, result[:body])
  919. assert_match(/3 hoch/, result[:body])
  920. assert_match(/2 normal/, result[:body])
  921. assert_match(/aktualisier/, result[:body])
  922. human_changes = bg.human_changes(agent2, ticket1)
  923. # en notification
  924. result = NotificationFactory::Mailer.template(
  925. locale: agent2.preferences[:locale],
  926. template: 'ticket_update',
  927. objects: {
  928. ticket: ticket1,
  929. article: article,
  930. recipient: agent2,
  931. changes: human_changes,
  932. }
  933. )
  934. assert_match(/Bobs's resumé/, result[:subject])
  935. assert_match(/Title/, result[:body])
  936. assert_match(/some notification template test old 1/, result[:body])
  937. assert_match(/some notification template test 1 #2/, result[:body])
  938. assert_match(/Priority/, result[:body])
  939. assert_match(/3 high/, result[:body])
  940. assert_match(/2 normal/, result[:body])
  941. assert_no_match(/Pending till/, result[:body])
  942. assert_no_match(/2015-01-11 23:33:47 UTC/, result[:body])
  943. assert_match(/update/, result[:body])
  944. assert_no_match(/pending_till/, result[:body])
  945. assert_no_match(/i18n/, result[:body])
  946. end
  947. end