ticket_notification_test.rb 44 KB

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