online_notifiaction_test.rb 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class OnlineNotificationTest < ActiveSupport::TestCase
  4. role = Role.lookup(name: 'Agent')
  5. group = Group.lookup(name: 'Users')
  6. agent_user1 = User.create_or_update(
  7. login: 'agent_online_notify1',
  8. firstname: 'Bob',
  9. lastname: 'Smith',
  10. email: 'agent_online_notify1@example.com',
  11. password: 'some_pass',
  12. active: true,
  13. role_ids: [role.id],
  14. group_ids: [group.id],
  15. updated_by_id: 1,
  16. created_by_id: 1
  17. )
  18. agent_user2 = User.create_or_update(
  19. login: 'agent_online_notify2',
  20. firstname: 'Bob',
  21. lastname: 'Smith',
  22. email: 'agent_online_notify2@example.com',
  23. password: 'some_pass',
  24. active: true,
  25. role_ids: [role.id],
  26. group_ids: [group.id],
  27. updated_by_id: 1,
  28. created_by_id: 1
  29. )
  30. customer_user = User.lookup(email: 'nicole.braun@zammad.org')
  31. test 'ticket notification' do
  32. Rails.configuration.webserver_is_active = true
  33. # case #1
  34. ticket1 = Ticket.create(
  35. group_id: Group.lookup(name: 'Users').id,
  36. customer_id: customer_user.id,
  37. owner_id: User.lookup(login: '-').id,
  38. title: 'Unit Test 1 (äöüß)!',
  39. state_id: Ticket::State.lookup(name: 'closed').id,
  40. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  41. updated_by_id: agent_user1.id,
  42. created_by_id: agent_user1.id,
  43. )
  44. article1 = Ticket::Article.create(
  45. ticket_id: ticket1.id,
  46. updated_by_id: agent_user1.id,
  47. created_by_id: agent_user1.id,
  48. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  49. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  50. from: 'Unit Test <unittest@example.com>',
  51. body: 'Unit Test 123',
  52. internal: false
  53. )
  54. # remember ticket
  55. tickets = []
  56. tickets.push ticket1
  57. # execute ticket events
  58. Observer::Ticket::Notification.transaction
  59. #puts Delayed::Job.all.inspect
  60. Delayed::Worker.new.work_off
  61. # because it's already closed
  62. assert(OnlineNotification.all_seen?('Ticket', ticket1.id))
  63. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket1.id, 'create', agent_user1, false))
  64. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket1.id, 'create', agent_user1, true))
  65. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket1.id, 'create', agent_user1, false))
  66. assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket1.id, 'create', agent_user1, true))
  67. ticket1.update_attributes(
  68. title: 'Unit Test 1 (äöüß) - update!',
  69. state_id: Ticket::State.lookup(name: 'open').id,
  70. priority_id: Ticket::Priority.lookup(name: '1 low').id,
  71. updated_by_id: customer_user.id,
  72. )
  73. # execute ticket events
  74. Observer::Ticket::Notification.transaction
  75. #puts Delayed::Job.all.inspect
  76. Delayed::Worker.new.work_off
  77. # because it's already open
  78. assert(!OnlineNotification.all_seen?('Ticket', ticket1.id))
  79. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket1.id, 'update', customer_user, true))
  80. assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket1.id, 'update', customer_user, false))
  81. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket1.id, 'update', customer_user, true))
  82. assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket1.id, 'update', customer_user, false))
  83. # case #2
  84. ticket2 = Ticket.create(
  85. group_id: Group.lookup(name: 'Users').id,
  86. customer_id: customer_user.id,
  87. owner_id: agent_user1.id,
  88. title: 'Unit Test 1 (äöüß)!',
  89. state_id: Ticket::State.lookup(name: 'closed').id,
  90. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  91. updated_by_id: customer_user.id,
  92. created_by_id: customer_user.id,
  93. )
  94. article2 = Ticket::Article.create(
  95. ticket_id: ticket2.id,
  96. updated_by_id: customer_user.id,
  97. created_by_id: customer_user.id,
  98. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  99. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  100. from: 'Unit Test <unittest@example.com>',
  101. body: 'Unit Test 123',
  102. internal: false
  103. )
  104. # remember ticket
  105. tickets = []
  106. tickets.push ticket2
  107. # execute ticket events
  108. Observer::Ticket::Notification.transaction
  109. #puts Delayed::Job.all.inspect
  110. Delayed::Worker.new.work_off
  111. # because it's already closed
  112. assert(!OnlineNotification.all_seen?('Ticket', ticket2.id))
  113. assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket2.id, 'create', customer_user, false))
  114. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket2.id, 'create', customer_user, true))
  115. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket2.id, 'create', customer_user, false))
  116. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket2.id, 'create', customer_user, true))
  117. ticket2.update_attributes(
  118. title: 'Unit Test 1 (äöüß) - update!',
  119. state_id: Ticket::State.lookup(name: 'open').id,
  120. priority_id: Ticket::Priority.lookup(name: '1 low').id,
  121. updated_by_id: customer_user.id,
  122. )
  123. # execute ticket events
  124. Observer::Ticket::Notification.transaction
  125. #puts Delayed::Job.all.inspect
  126. Delayed::Worker.new.work_off
  127. # because it's already open
  128. assert(!OnlineNotification.all_seen?('Ticket', ticket2.id))
  129. assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket2.id, 'update', customer_user, false))
  130. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket2.id, 'update', customer_user, true))
  131. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket2.id, 'update', customer_user, true))
  132. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket2.id, 'update', customer_user, false))
  133. # case #3
  134. ticket3 = Ticket.create(
  135. group_id: Group.lookup(name: 'Users').id,
  136. customer_id: customer_user.id,
  137. owner_id: User.lookup(login: '-').id,
  138. title: 'Unit Test 2 (äöüß)!',
  139. state_id: Ticket::State.lookup(name: 'new').id,
  140. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  141. updated_by_id: agent_user1.id,
  142. created_by_id: agent_user1.id,
  143. )
  144. article3 = Ticket::Article.create(
  145. ticket_id: ticket3.id,
  146. updated_by_id: agent_user1.id,
  147. created_by_id: agent_user1.id,
  148. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  149. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  150. from: 'Unit Test <unittest@example.com>',
  151. body: 'Unit Test 123',
  152. internal: false,
  153. )
  154. # remember ticket
  155. tickets.push ticket3
  156. # execute ticket events
  157. Observer::Ticket::Notification.transaction
  158. #puts Delayed::Job.all.inspect
  159. Delayed::Worker.new.work_off
  160. # because it's already new
  161. assert(!OnlineNotification.all_seen?('Ticket', ticket3.id))
  162. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'create', agent_user1, false))
  163. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'create', agent_user1, true))
  164. assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'create', agent_user1, false))
  165. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'create', agent_user1, true))
  166. ticket3.update_attributes(
  167. title: 'Unit Test 2 (äöüß) - update!',
  168. state_id: Ticket::State.lookup(name: 'closed').id,
  169. priority_id: Ticket::Priority.lookup(name: '1 low').id,
  170. updated_by_id: customer_user.id,
  171. )
  172. # execute ticket events
  173. Observer::Ticket::Notification.transaction
  174. #puts Delayed::Job.all.inspect
  175. Delayed::Worker.new.work_off
  176. # because it's already closed
  177. assert(OnlineNotification.all_seen?('Ticket', ticket3.id))
  178. assert_equal(1, NotificationFactory.already_sent?(ticket3, agent_user1, 'update'))
  179. assert_equal(1, NotificationFactory.already_sent?(ticket3, agent_user2, 'update'))
  180. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'update', customer_user, false))
  181. assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'update', customer_user, true))
  182. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'update', customer_user, false))
  183. assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'update', customer_user, true))
  184. article3 = Ticket::Article.create(
  185. ticket_id: ticket3.id,
  186. updated_by_id: customer_user.id,
  187. created_by_id: customer_user.id,
  188. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  189. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  190. from: 'Unit Test <unittest@example.com>',
  191. body: 'Unit Test 123 # 2',
  192. internal: false
  193. )
  194. # execute ticket events
  195. Observer::Ticket::Notification.transaction
  196. #puts Delayed::Job.all.inspect
  197. Delayed::Worker.new.work_off
  198. # because it's already closed but an follow up arrived later
  199. assert(!OnlineNotification.all_seen?('Ticket', ticket3.id))
  200. assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'update', customer_user, false))
  201. assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'update', customer_user, true))
  202. assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'update', customer_user, false))
  203. assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'update', customer_user, true))
  204. assert_equal(2, NotificationFactory.already_sent?(ticket3, agent_user1, 'update'))
  205. assert_equal(2, NotificationFactory.already_sent?(ticket3, agent_user2, 'update'))
  206. # case #4
  207. ticket4 = Ticket.create(
  208. group_id: Group.lookup(name: 'Users').id,
  209. customer_id: customer_user.id,
  210. owner_id: agent_user1.id,
  211. title: 'Unit Test 3 (äöüß)!',
  212. state_id: Ticket::State.lookup(name: 'new').id,
  213. priority_id: Ticket::Priority.lookup(name: '2 normal').id,
  214. updated_by_id: customer_user.id,
  215. created_by_id: customer_user.id,
  216. )
  217. article4 = Ticket::Article.create(
  218. ticket_id: ticket4.id,
  219. updated_by_id: customer_user.id,
  220. created_by_id: customer_user.id,
  221. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  222. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  223. from: 'Unit Test <unittest@example.com>',
  224. body: 'Unit Test 123',
  225. internal: false,
  226. )
  227. # remember ticket
  228. tickets.push ticket4
  229. # execute ticket events
  230. Observer::Ticket::Notification.transaction
  231. #puts Delayed::Job.all.inspect
  232. Delayed::Worker.new.work_off
  233. # because it's already new
  234. assert(!OnlineNotification.all_seen?('Ticket', ticket4.id))
  235. assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket4.id, 'create', customer_user, false))
  236. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket4.id, 'create', customer_user, true))
  237. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket4.id, 'create', customer_user, false))
  238. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket4.id, 'create', customer_user, true))
  239. ticket4.update_attributes(
  240. title: 'Unit Test 3 (äöüß) - update!',
  241. state_id: Ticket::State.lookup(name: 'open').id,
  242. priority_id: Ticket::Priority.lookup(name: '1 low').id,
  243. updated_by_id: customer_user.id,
  244. )
  245. # execute ticket events
  246. Observer::Ticket::Notification.transaction
  247. #puts Delayed::Job.all.inspect
  248. Delayed::Worker.new.work_off
  249. # because it's already open
  250. assert(!OnlineNotification.all_seen?('Ticket', ticket4.id))
  251. assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket4.id, 'update', customer_user, false))
  252. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket4.id, 'update', customer_user, true))
  253. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket4.id, 'update', customer_user, false))
  254. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket4.id, 'update', customer_user, true))
  255. # case #5
  256. ticket5 = Ticket.create(
  257. group_id: Group.lookup(name: 'Users').id,
  258. customer_id: customer_user.id,
  259. owner_id: User.lookup(login: '-').id,
  260. title: 'Unit Test 4 (äöüß)!',
  261. state_id: Ticket::State.lookup(name: 'new').id,
  262. priority_id: Ticket::Priority.lookup( name: '2 normal').id,
  263. updated_by_id: agent_user1.id,
  264. created_by_id: agent_user1.id,
  265. )
  266. article5 = Ticket::Article.create(
  267. ticket_id: ticket5.id,
  268. updated_by_id: agent_user1.id,
  269. created_by_id: agent_user1.id,
  270. type_id: Ticket::Article::Type.lookup(name: 'phone').id,
  271. sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
  272. from: 'Unit Test <unittest@example.com>',
  273. body: 'Unit Test 123',
  274. internal: false,
  275. )
  276. # remember ticket
  277. tickets.push ticket5
  278. # execute ticket events
  279. Observer::Ticket::Notification.transaction
  280. #puts Delayed::Job.all.inspect
  281. Delayed::Worker.new.work_off
  282. # because it's already new
  283. assert(!OnlineNotification.all_seen?('Ticket', ticket5.id))
  284. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket5.id, 'create', agent_user1, true))
  285. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket5.id, 'create', agent_user1, false))
  286. assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket5.id, 'create', agent_user1, false))
  287. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket5.id, 'create', agent_user1, true))
  288. ticket5.update_attributes(
  289. title: 'Unit Test 4 (äöüß) - update!',
  290. state_id: Ticket::State.lookup(name: 'open').id,
  291. priority_id: Ticket::Priority.lookup(name: '1 low').id,
  292. updated_by_id: customer_user.id,
  293. )
  294. # execute ticket events
  295. Observer::Ticket::Notification.transaction
  296. #puts Delayed::Job.all.inspect
  297. Delayed::Worker.new.work_off
  298. # because it's already open
  299. assert(!OnlineNotification.all_seen?('Ticket', ticket5.id))
  300. assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket5.id, 'update', customer_user, false))
  301. assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket5.id, 'update', customer_user, true))
  302. assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket5.id, 'update', customer_user, false))
  303. assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket5.id, 'update', customer_user, true))
  304. # merge tickets - also remove notifications of merged tickets
  305. tickets[0].merge_to(
  306. ticket_id: tickets[1].id,
  307. user_id: 1,
  308. )
  309. Delayed::Worker.new.work_off
  310. notifications = OnlineNotification.list_by_object('Ticket', tickets[0].id)
  311. assert(!notifications.empty?, 'should have notifications')
  312. assert(OnlineNotification.all_seen?('Ticket', tickets[0].id), 'still not seen notifications for merged ticket available')
  313. notifications = OnlineNotification.list_by_object('Ticket', tickets[1].id)
  314. assert(!notifications.empty?, 'should have notifications')
  315. assert(!OnlineNotification.all_seen?('Ticket', tickets[1].id), 'no notifications for master ticket available')
  316. # delete tickets
  317. tickets.each { |ticket|
  318. ticket_id = ticket.id
  319. ticket.destroy
  320. found = Ticket.find_by(id: ticket_id)
  321. assert(!found, 'Ticket destroyed')
  322. # check if notifications for ticket still exist
  323. Delayed::Worker.new.work_off
  324. notifications = OnlineNotification.list_by_object('Ticket', ticket_id)
  325. assert(notifications.empty?, 'still notifications for destroyed ticket available')
  326. }
  327. end
  328. test 'ticket notification item check' do
  329. ticket1 = Ticket.create(
  330. title: 'some title',
  331. group: Group.lookup(name: 'Users'),
  332. customer_id: customer_user.id,
  333. state: Ticket::State.lookup(name: 'new'),
  334. priority: Ticket::Priority.lookup(name: '2 normal'),
  335. updated_by_id: 1,
  336. created_by_id: 1,
  337. )
  338. assert( ticket1, 'ticket created' )
  339. article_inbound = Ticket::Article.create(
  340. ticket_id: ticket1.id,
  341. from: 'some_sender@example.com',
  342. to: 'some_recipient@example.com',
  343. subject: 'some subject',
  344. message_id: 'some@id',
  345. body: 'some message article_inbound',
  346. internal: false,
  347. sender: Ticket::Article::Sender.lookup(name: 'Customer'),
  348. type: Ticket::Article::Type.lookup(name: 'email'),
  349. updated_by_id: 1,
  350. created_by_id: 1,
  351. )
  352. assert_equal(ticket1.online_notification_seen_state, false)
  353. assert_equal(ticket1.online_notification_seen_state(agent_user1), false)
  354. assert_equal(ticket1.online_notification_seen_state(agent_user2), false)
  355. # pending reminder, just let new owner to unseed
  356. ticket1.update_attributes(
  357. owner_id: agent_user1.id,
  358. state: Ticket::State.lookup(name: 'pending reminder'),
  359. updated_by_id: agent_user2.id,
  360. )
  361. assert_equal(ticket1.online_notification_seen_state, true)
  362. assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
  363. assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
  364. # pending reminder, just let new owner to unseed
  365. ticket1.update_attributes(
  366. owner_id: 1,
  367. state: Ticket::State.lookup(name: 'pending reminder'),
  368. updated_by_id: agent_user2.id,
  369. )
  370. assert_equal(ticket1.online_notification_seen_state, true)
  371. assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
  372. assert_equal(ticket1.online_notification_seen_state(agent_user2.id), false)
  373. # pending reminder, self done, all to unseed
  374. ticket1.update_attributes(
  375. owner_id: agent_user1.id,
  376. state: Ticket::State.lookup(name: 'pending reminder'),
  377. updated_by_id: agent_user1.id,
  378. )
  379. assert_equal(ticket1.online_notification_seen_state, true)
  380. assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true)
  381. assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
  382. # pending close, all to unseen
  383. ticket1.update_attributes(
  384. owner_id: agent_user1.id,
  385. state: Ticket::State.lookup(name: 'pending close'),
  386. updated_by_id: agent_user2.id,
  387. )
  388. assert_equal(ticket1.online_notification_seen_state, true)
  389. assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
  390. assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
  391. # to open, all to seen
  392. ticket1.update_attributes(
  393. owner_id: agent_user1.id,
  394. state: Ticket::State.lookup(name: 'open'),
  395. updated_by_id: agent_user2.id,
  396. )
  397. assert_equal(ticket1.online_notification_seen_state, false)
  398. assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
  399. assert_equal(ticket1.online_notification_seen_state(agent_user2.id), false)
  400. # to closed, all only others to seen
  401. ticket1.update_attributes(
  402. owner_id: agent_user1.id,
  403. state: Ticket::State.lookup(name: 'closed'),
  404. updated_by_id: agent_user2.id,
  405. )
  406. assert_equal(ticket1.online_notification_seen_state, true)
  407. assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false)
  408. assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
  409. # to closed by owner self, all to seen
  410. ticket1.update_attributes(
  411. owner_id: agent_user1.id,
  412. state: Ticket::State.lookup(name: 'closed'),
  413. updated_by_id: agent_user1.id,
  414. )
  415. assert_equal(ticket1.online_notification_seen_state, true)
  416. assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true)
  417. assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
  418. # to closed by owner self, all to seen
  419. ticket1.update_attributes(
  420. owner_id: agent_user1.id,
  421. state: Ticket::State.lookup(name: 'merged'),
  422. updated_by_id: agent_user2.id,
  423. )
  424. assert_equal(ticket1.online_notification_seen_state, true)
  425. assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true)
  426. assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true)
  427. end
  428. test 'cleanup check' do
  429. online_notification1 = OnlineNotification.add(
  430. type: 'create',
  431. object: 'Ticket',
  432. o_id: 123,
  433. seen: false,
  434. user_id: agent_user1.id,
  435. created_by_id: 1,
  436. updated_by_id: 1,
  437. created_at: Time.zone.now - 10.months,
  438. updated_at: Time.zone.now - 10.months,
  439. )
  440. online_notification2 = OnlineNotification.add(
  441. type: 'create',
  442. object: 'Ticket',
  443. o_id: 123,
  444. seen: true,
  445. user_id: agent_user1.id,
  446. created_by_id: 1,
  447. updated_by_id: 1,
  448. created_at: Time.zone.now - 10.months,
  449. updated_at: Time.zone.now - 10.months,
  450. )
  451. online_notification3 = OnlineNotification.add(
  452. type: 'create',
  453. object: 'Ticket',
  454. o_id: 123,
  455. seen: false,
  456. user_id: agent_user1.id,
  457. created_by_id: 1,
  458. updated_by_id: 1,
  459. created_at: Time.zone.now - 2.days,
  460. updated_at: Time.zone.now - 2.days,
  461. )
  462. online_notification4 = OnlineNotification.add(
  463. type: 'create',
  464. object: 'Ticket',
  465. o_id: 123,
  466. seen: true,
  467. user_id: agent_user1.id,
  468. created_by_id: agent_user1.id,
  469. updated_by_id: agent_user1.id,
  470. created_at: Time.zone.now - 2.days,
  471. updated_at: Time.zone.now - 2.days,
  472. )
  473. online_notification5 = OnlineNotification.add(
  474. type: 'create',
  475. object: 'Ticket',
  476. o_id: 123,
  477. seen: true,
  478. user_id: agent_user1.id,
  479. created_by_id: agent_user2.id,
  480. updated_by_id: agent_user2.id,
  481. created_at: Time.zone.now - 2.days,
  482. updated_at: Time.zone.now - 2.days,
  483. )
  484. online_notification6 = OnlineNotification.add(
  485. type: 'create',
  486. object: 'Ticket',
  487. o_id: 123,
  488. seen: true,
  489. user_id: agent_user1.id,
  490. created_by_id: agent_user1.id,
  491. updated_by_id: agent_user1.id,
  492. created_at: Time.zone.now - 5.minutes,
  493. updated_at: Time.zone.now - 5.minutes,
  494. )
  495. online_notification7 = OnlineNotification.add(
  496. type: 'create',
  497. object: 'Ticket',
  498. o_id: 123,
  499. seen: true,
  500. user_id: agent_user1.id,
  501. created_by_id: agent_user2.id,
  502. updated_by_id: agent_user2.id,
  503. created_at: Time.zone.now - 5.minutes,
  504. updated_at: Time.zone.now - 5.minutes,
  505. )
  506. OnlineNotification.cleanup
  507. assert(!OnlineNotification.find_by(id: online_notification1.id))
  508. assert(!OnlineNotification.find_by(id: online_notification2.id))
  509. assert(OnlineNotification.find_by(id: online_notification3.id))
  510. assert(!OnlineNotification.find_by(id: online_notification4.id))
  511. assert(!OnlineNotification.find_by(id: online_notification5.id))
  512. assert(OnlineNotification.find_by(id: online_notification6.id))
  513. assert(OnlineNotification.find_by(id: online_notification7.id))
  514. OnlineNotification.destroy_all
  515. end
  516. end