online_notifiaction_test.rb 22 KB

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