session_basic_ticket_test.rb 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. require 'test_helper'
  2. class SessionBasicTicketTest < ActiveSupport::TestCase
  3. setup do
  4. UserInfo.current_user_id = 1
  5. roles = Role.where(name: ['Agent'])
  6. groups = Group.all
  7. @agent1 = User.create_or_update(
  8. login: 'session-basic-ticket-agent-1',
  9. firstname: 'Session',
  10. lastname: 'session basic ' + rand(99_999).to_s,
  11. email: 'session-basic-ticket-agent-1@example.com',
  12. password: 'agentpw',
  13. active: true,
  14. roles: roles,
  15. groups: groups,
  16. )
  17. @agent2 = User.create_or_update(
  18. login: 'session-basic-ticket-agent-2',
  19. firstname: 'Session',
  20. lastname: 'session basic ' + rand(99_999).to_s,
  21. email: 'session-basic-ticket-agent-2@example.com',
  22. password: 'agentpw',
  23. active: true,
  24. roles: roles,
  25. groups: groups,
  26. )
  27. Overview.destroy_all
  28. load Rails.root.join('db', 'seeds', 'overviews.rb')
  29. end
  30. test 'asset needed' do
  31. client1 = Sessions::Backend::TicketOverviewList.new(@agent1, {}, false, '123-1', 2)
  32. client2 = Sessions::Backend::TicketOverviewList.new(@agent2, {}, false, '123-2', 2)
  33. ticket = Ticket.create!(title: 'default overview test', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
  34. assert(client1.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  35. client1.asset_push(ticket, {})
  36. assert_not(client1.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  37. assert(client2.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  38. client2.asset_push(ticket, {})
  39. assert_not(client2.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  40. travel 30.minutes
  41. assert_not(client1.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  42. assert_not(client2.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  43. travel 120.minutes
  44. client1.time_now = Time.zone.now.to_i
  45. assert(client1.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  46. client1.asset_push(ticket, {})
  47. client2.time_now = Time.zone.now.to_i
  48. assert(client2.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  49. client2.asset_push(ticket, {})
  50. client1.time_now = Time.zone.now.to_i
  51. assert_not(client1.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  52. client1.asset_push(ticket, {})
  53. client2.time_now = Time.zone.now.to_i
  54. assert_not(client2.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  55. client2.asset_push(ticket, {})
  56. ticket.touch
  57. client1.time_now = Time.zone.now.to_i
  58. assert(client1.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  59. client1.asset_push(ticket, {})
  60. client2.time_now = Time.zone.now.to_i
  61. assert(client2.asset_needed_by_updated_at?(ticket.class.to_s, ticket.id, ticket.updated_at))
  62. client2.asset_push(ticket, {})
  63. assert_not(client1.asset_needed?(ticket))
  64. assert_not(client2.asset_needed?(ticket))
  65. travel 125.minutes
  66. client1.time_now = Time.zone.now.to_i
  67. assert(client1.asset_needed?(ticket))
  68. client1.asset_push(ticket, {})
  69. client2.time_now = Time.zone.now.to_i
  70. assert(client2.asset_needed?(ticket))
  71. client2.asset_push(ticket, {})
  72. assert_not(client1.asset_needed?(ticket))
  73. assert_not(client2.asset_needed?(ticket))
  74. travel_back
  75. end
  76. test 'ticket_overview_List' do
  77. ticket1 = Ticket.create!(title: 'default overview test 1', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
  78. ticket2 = Ticket.create!(title: 'default overview test 2', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
  79. client1 = Sessions::Backend::TicketOverviewList.new(@agent1, {}, false, '123-1', 2)
  80. result1 = client1.push
  81. assert(result1, 'check ticket_overview_List')
  82. assert(result1[1][:data][:assets])
  83. assert(result1[1][:data][:assets][:Overview])
  84. assert(result1[1][:data][:assets][:User])
  85. assert_equal(result1[1][:data][:assets][:Ticket][ticket1.id]['title'], ticket1.title)
  86. assert_equal(result1[1][:data][:assets][:Ticket][ticket2.id]['title'], ticket2.title)
  87. # next check should be empty / no changes
  88. result1 = client1.push
  89. assert_not(result1, 'check ticket_overview_index - recall')
  90. # next check should be empty / no changes
  91. travel 3.seconds
  92. result1 = client1.push
  93. assert_not(result1, 'check ticket_overview_index - recall 2')
  94. # create ticket
  95. ticket3 = Ticket.create!(title: '12323', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
  96. travel 3.seconds
  97. result1 = client1.push
  98. assert(result1, 'check ticket_overview_index - recall 3')
  99. assert(result1[1][:data][:assets])
  100. assert_not(result1[1][:data][:assets][:Ticket][ticket1.id])
  101. assert_not(result1[1][:data][:assets][:Ticket][ticket2.id])
  102. assert_equal(result1[1][:data][:assets][:Ticket][ticket3.id]['title'], ticket3.title)
  103. travel 3.seconds
  104. # chnage overview
  105. overviews = Ticket::Overviews.all(
  106. current_user: @agent1,
  107. )
  108. overviews.first.touch
  109. result1 = client1.push
  110. assert(result1, 'check ticket_overview_index - recall 4')
  111. assert(result1[1][:data][:assets])
  112. assert_not(result1[1][:data][:assets][:Ticket])
  113. result1 = client1.push
  114. assert_not(result1, 'check ticket_overview_index - recall 5')
  115. Sessions::Backend::TicketOverviewList.reset(@agent1.id)
  116. result1 = client1.push
  117. assert_not(result1, 'check ticket_overview_index - recall 6')
  118. ticket4 = Ticket.create!(title: '12323 - 2', group_id: 1, priority_id: 1, state_id: 1, customer_id: 1)
  119. Sessions::Backend::TicketOverviewList.reset(@agent1.id)
  120. result1 = client1.push
  121. assert(result1, 'check ticket_overview_index - recall 7')
  122. assert(result1[1][:data][:assets])
  123. assert_not(result1[1][:data][:assets][:Ticket][ticket1.id])
  124. assert_not(result1[1][:data][:assets][:Ticket][ticket2.id])
  125. assert_not(result1[1][:data][:assets][:Ticket][ticket3.id])
  126. assert_equal(result1[1][:data][:assets][:Ticket][ticket4.id]['title'], ticket4.title)
  127. travel 125.minutes
  128. ticket1.touch
  129. result1 = client1.push
  130. assert(result1, 'check ticket_overview_index - recall 8')
  131. assert(result1[1][:data][:assets])
  132. assert_equal(result1[1][:data][:assets][:Ticket][ticket1.id]['title'], ticket1.title)
  133. assert_equal(result1[1][:data][:assets][:Ticket][ticket2.id]['title'], ticket2.title)
  134. assert_equal(result1[1][:data][:assets][:Ticket][ticket3.id]['title'], ticket3.title)
  135. assert_equal(result1[1][:data][:assets][:Ticket][ticket4.id]['title'], ticket4.title)
  136. travel 10.seconds
  137. Sessions.destroy_idle_sessions(3)
  138. travel_back
  139. end
  140. end