ticket_notification_test.rb 45 KB

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