ticket_ref_object_touch_test.rb 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. require 'test_helper'
  2. class TicketRefObjectTouchTest < ActiveSupport::TestCase
  3. setup do
  4. groups = Group.where(name: 'Users')
  5. roles = Role.where(name: 'Agent')
  6. @agent1 = User.create_or_update(
  7. login: 'ticket-ref-object-update-agent1@example.com',
  8. firstname: 'Notification',
  9. lastname: 'Agent1',
  10. email: 'ticket-ref-object-update-agent1@example.com',
  11. password: 'agentpw',
  12. active: true,
  13. roles: roles,
  14. groups: groups,
  15. updated_at: '2015-02-05 16:37:00',
  16. updated_by_id: 1,
  17. created_by_id: 1,
  18. )
  19. roles = Role.where(name: 'Customer')
  20. @organization1 = Organization.create_if_not_exists(
  21. name: 'Ref Object Update Org',
  22. updated_at: '2015-02-05 16:37:00',
  23. updated_by_id: 1,
  24. created_by_id: 1,
  25. )
  26. @customer1 = User.create_or_update(
  27. login: 'ticket-ref-object-update-customer1@example.com',
  28. firstname: 'Notification',
  29. lastname: 'Customer1',
  30. email: 'ticket-ref-object-update-customer1@example.com',
  31. password: 'customerpw',
  32. active: true,
  33. organization_id: @organization1.id,
  34. roles: roles,
  35. updated_at: '2015-02-05 16:37:00',
  36. updated_by_id: 1,
  37. created_by_id: 1,
  38. )
  39. @customer2 = User.create_or_update(
  40. login: 'ticket-ref-object-update-customer2@example.com',
  41. firstname: 'Notification',
  42. lastname: 'Customer2',
  43. email: 'ticket-ref-object-update-customer2@example.com',
  44. password: 'customerpw',
  45. active: true,
  46. organization_id: nil,
  47. roles: roles,
  48. updated_at: '2015-02-05 16:37:00',
  49. updated_by_id: 1,
  50. created_by_id: 1,
  51. )
  52. end
  53. test 'b - check if customer and organization has been updated' do
  54. ticket = Ticket.create(
  55. title: "some title1\n äöüß",
  56. group: Group.lookup(name: 'Users'),
  57. customer_id: @customer1.id,
  58. owner_id: @agent1.id,
  59. state: Ticket::State.lookup(name: 'new'),
  60. priority: Ticket::Priority.lookup(name: '2 normal'),
  61. updated_by_id: 1,
  62. created_by_id: 1,
  63. )
  64. assert(ticket, 'ticket created')
  65. assert_equal(ticket.customer.id, @customer1.id)
  66. assert_equal(ticket.organization.id, @organization1.id)
  67. # check if customer and organization has been touched
  68. @customer1 = User.find(@customer1.id)
  69. if @customer1.updated_at > 3.seconds.ago
  70. assert(true, 'customer1.updated_at has been updated')
  71. else
  72. assert(false, 'customer1.updated_at has not been updated')
  73. end
  74. @organization1 = Organization.find(@organization1.id)
  75. if @organization1.updated_at > 3.seconds.ago
  76. assert(true, 'organization1.updated_at has been updated')
  77. else
  78. assert(false, 'organization1.updated_at has not been updated')
  79. end
  80. travel 4.seconds
  81. delete = ticket.destroy
  82. assert(delete, 'ticket destroy')
  83. # check if customer and organization has been touched
  84. @customer1.reload
  85. if @customer1.updated_at > 3.seconds.ago
  86. assert(true, 'customer1.updated_at has been updated')
  87. else
  88. assert(false, 'customer1.updated_at has not been updated')
  89. end
  90. @organization1.reload
  91. if @organization1.updated_at > 3.seconds.ago
  92. assert(true, 'organization1.updated_at has been updated')
  93. else
  94. assert(false, 'organization1.updated_at has not been updated')
  95. end
  96. travel_back
  97. end
  98. test 'c - check if customer (not organization) has been updated' do
  99. travel 8.seconds
  100. ticket = Ticket.create(
  101. title: "some title2\n äöüß",
  102. group: Group.lookup(name: 'Users'),
  103. customer_id: @customer2.id,
  104. owner_id: @agent1.id,
  105. state: Ticket::State.lookup(name: 'new'),
  106. priority: Ticket::Priority.lookup(name: '2 normal'),
  107. updated_by_id: 1,
  108. created_by_id: 1,
  109. )
  110. assert(ticket, 'ticket created')
  111. assert_equal(ticket.customer.id, @customer2.id)
  112. assert_nil(ticket.organization)
  113. # check if customer and organization has been touched
  114. @customer2.reload
  115. if @customer2.updated_at > 3.seconds.ago
  116. assert(true, 'customer2.updated_at has been updated')
  117. else
  118. assert(false, 'customer2.updated_at has not been updated')
  119. end
  120. @organization1.reload
  121. if @organization1.updated_at > 3.seconds.ago
  122. assert(false, 'organization1.updated_at has been updated')
  123. else
  124. assert(true, 'organization1.updated_at has not been updated')
  125. end
  126. travel 4.seconds
  127. delete = ticket.destroy
  128. assert(delete, 'ticket destroy')
  129. # check if customer and organization has been touched
  130. @customer2.reload
  131. if @customer2.updated_at > 3.seconds.ago
  132. assert(true, 'customer2.updated_at has been updated')
  133. else
  134. assert(false, 'customer2.updated_at has not been updated')
  135. end
  136. @organization1.reload
  137. if @organization1.updated_at > 3.seconds.ago
  138. assert(false, 'organization1.updated_at has been updated')
  139. else
  140. assert(true, 'organization1.updated_at has not been updated')
  141. end
  142. travel_back
  143. end
  144. end