organization_ref_object_touch_test.rb 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. require 'test_helper'
  2. class OrganizationRefObjectTouchTest < ActiveSupport::TestCase
  3. test 'check if ticket and customer has been updated' do
  4. # create base
  5. groups = Group.where(name: 'Users')
  6. roles = Role.where(name: 'Agent')
  7. agent1 = User.create_or_update(
  8. login: 'organization-ref-object-update-agent1@example.com',
  9. firstname: 'Notification',
  10. lastname: 'Agent1',
  11. email: 'organization-ref-object-update-agent1@example.com',
  12. password: 'agentpw',
  13. active: true,
  14. roles: roles,
  15. groups: groups,
  16. updated_at: '2015-02-05 16:37:00',
  17. updated_by_id: 1,
  18. created_by_id: 1,
  19. )
  20. roles = Role.where(name: 'Customer')
  21. organization1 = Organization.create_if_not_exists(
  22. name: 'Ref Object Update Org 1',
  23. updated_at: '2015-02-05 16:37:00',
  24. updated_by_id: 1,
  25. created_by_id: 1,
  26. )
  27. organization2 = Organization.create_if_not_exists(
  28. name: 'Ref Object Update Org 2',
  29. updated_at: '2015-02-05 16:37:00',
  30. updated_by_id: 1,
  31. created_by_id: 1,
  32. )
  33. customer1 = User.create_or_update(
  34. login: 'organization-ref-object-update-customer1@example.com',
  35. firstname: 'Notification',
  36. lastname: 'Agent1',
  37. email: 'organization-ref-object-update-customer1@example.com',
  38. password: 'customerpw',
  39. active: true,
  40. organization_id: organization1.id,
  41. roles: roles,
  42. updated_at: '2015-02-05 16:37:00',
  43. updated_by_id: 1,
  44. created_by_id: 1,
  45. )
  46. customer2 = User.create_or_update(
  47. login: 'organization-ref-object-update-customer2@example.com',
  48. firstname: 'Notification',
  49. lastname: 'Agent2',
  50. email: 'organization-ref-object-update-customer2@example.com',
  51. password: 'customerpw',
  52. active: true,
  53. organization_id: organization2.id,
  54. roles: roles,
  55. updated_at: '2015-02-05 16:37:00',
  56. updated_by_id: 1,
  57. created_by_id: 1,
  58. )
  59. ticket = Ticket.create!(
  60. title: "some title1\n äöüß",
  61. group: Group.lookup(name: 'Users'),
  62. customer_id: customer1.id,
  63. owner_id: agent1.id,
  64. state: Ticket::State.lookup(name: 'new'),
  65. priority: Ticket::Priority.lookup(name: '2 normal'),
  66. updated_by_id: 1,
  67. created_by_id: 1,
  68. )
  69. assert(ticket, 'ticket created')
  70. assert_equal(ticket.customer.id, customer1.id)
  71. assert_equal(ticket.organization.id, organization1.id)
  72. travel 4.seconds
  73. organization1.name = 'Ref Object Update Org 1/1'
  74. organization1.save!
  75. # check if ticket and customer has been touched
  76. ticket = Ticket.find(ticket.id)
  77. if ticket.updated_at > 2.seconds.ago
  78. assert(true, 'ticket.updated_at has been updated')
  79. else
  80. assert(false, 'ticket.updated_at has not been updated')
  81. end
  82. customer1.reload
  83. if customer1.updated_at > 2.seconds.ago
  84. assert(true, 'customer1.updated_at has been updated')
  85. else
  86. assert(false, 'customer1.updated_at has not been updated')
  87. end
  88. travel 4.seconds
  89. customer2.organization_id = organization1.id
  90. customer2.save!
  91. # check if customer1 and organization has been touched
  92. customer1.reload
  93. if customer1.updated_at > 2.seconds.ago
  94. assert(true, 'customer1.updated_at has been updated')
  95. else
  96. assert(false, 'customer1.updated_at has not been updated')
  97. end
  98. organization1.reload
  99. if organization1.updated_at > 2.seconds.ago
  100. assert(true, 'organization1.updated_at has been updated')
  101. else
  102. assert(false, 'organization1.updated_at has not been updated')
  103. end
  104. assert(ticket.destroy, 'ticket destroy')
  105. travel_back
  106. end
  107. test 'check if ticket and customer has not been updated (different featrue propose)' do
  108. # create base
  109. groups = Group.where(name: 'Users')
  110. roles = Role.where(name: 'Agent')
  111. agent1 = User.create_or_update(
  112. login: 'organization-ref-object-not-update-agent1@example.com',
  113. firstname: 'Notification',
  114. lastname: 'Agent1',
  115. email: 'organization-ref-object-not-update-agent1@example.com',
  116. password: 'agentpw',
  117. active: true,
  118. roles: roles,
  119. groups: groups,
  120. updated_at: '2015-02-05 16:37:00',
  121. updated_by_id: 1,
  122. created_by_id: 1,
  123. )
  124. roles = Role.where(name: 'Customer')
  125. organization1 = Organization.create_if_not_exists(
  126. name: 'Ref Object Update Org 1 (no update)',
  127. updated_at: '2015-02-05 16:37:00',
  128. updated_by_id: 1,
  129. created_by_id: 1,
  130. )
  131. organization2 = Organization.create_if_not_exists(
  132. name: 'Ref Object Update Org 2 (no update)',
  133. updated_at: '2015-02-05 16:37:00',
  134. updated_by_id: 1,
  135. created_by_id: 1,
  136. )
  137. customer1 = User.create_or_update(
  138. login: 'organization-ref-object-not-update-customer1@example.com',
  139. firstname: 'Notification',
  140. lastname: 'Agent1',
  141. email: 'organization-ref-object-not-update-customer1@example.com',
  142. password: 'customerpw',
  143. active: true,
  144. organization_id: organization1.id,
  145. roles: roles,
  146. updated_at: '2015-02-05 16:37:00',
  147. updated_by_id: 1,
  148. created_by_id: 1,
  149. )
  150. customer2 = User.create_or_update(
  151. login: 'organization-ref-object-not-update-customer2@example.com',
  152. firstname: 'Notification',
  153. lastname: 'Agent2',
  154. email: 'organization-ref-object-not-update-customer2@example.com',
  155. password: 'customerpw',
  156. active: true,
  157. organization_id: organization2.id,
  158. roles: roles,
  159. updated_at: '2015-02-05 16:37:00',
  160. updated_by_id: 1,
  161. created_by_id: 1,
  162. )
  163. (1..100).each do |count|
  164. User.create_or_update(
  165. login: "organization-ref-object-update-customer3-#{count}@example.com",
  166. firstname: 'Notification',
  167. lastname: 'Agent2',
  168. email: "organization-ref-object-update-customer3-#{count}@example.com",
  169. password: 'customerpw',
  170. active: true,
  171. organization_id: organization1.id,
  172. roles: roles,
  173. updated_at: '2015-02-05 16:37:00',
  174. updated_by_id: 1,
  175. created_by_id: 1,
  176. )
  177. end
  178. ticket = Ticket.create!(
  179. title: "some title1\n äöüß",
  180. group: Group.lookup(name: 'Users'),
  181. customer_id: customer1.id,
  182. owner_id: agent1.id,
  183. state: Ticket::State.lookup(name: 'new'),
  184. priority: Ticket::Priority.lookup(name: '2 normal'),
  185. updated_at: '2015-02-05 16:39:00',
  186. updated_by_id: 1,
  187. created_by_id: 1,
  188. )
  189. assert(ticket, 'ticket created')
  190. assert_equal(ticket.customer.id, customer1.id)
  191. assert_equal(ticket.organization.id, organization1.id)
  192. customer1.reload
  193. assert_not_equal('2015-02-05 16:37:00 UTC', customer1.updated_at.to_s)
  194. customer1_updated_at = customer1.updated_at
  195. travel 4.seconds
  196. organization1.name = 'Ref Object Update Org 1 (no update)/1'
  197. organization1.save!
  198. organization1_updated_at = organization1.updated_at
  199. # check if ticket and customer has been touched
  200. ticket = Ticket.find(ticket.id)
  201. assert_equal('2015-02-05 16:39:00 UTC', ticket.updated_at.to_s)
  202. customer1.reload
  203. assert_equal(customer1_updated_at.to_s, customer1.updated_at.to_s)
  204. travel 4.seconds
  205. customer2.organization_id = organization1.id
  206. customer2.save!
  207. # check if customer1 and organization has been touched
  208. customer1.reload
  209. assert_equal(customer1_updated_at.to_s, customer1.updated_at.to_s)
  210. organization1.reload
  211. assert_equal(organization1_updated_at.to_s, organization1.updated_at.to_s)
  212. assert(ticket.destroy, 'ticket destroy')
  213. travel_back
  214. end
  215. end