report_examples.rb 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_context 'with report examples' do
  3. before do |example|
  4. next if !example.metadata[:searchindex]
  5. ticket_1
  6. ticket_2
  7. ticket_3
  8. ticket_4
  9. ticket_5
  10. ticket_6
  11. ticket_7
  12. ticket_8
  13. ticket_9
  14. ticket_after_72h
  15. ticket_before_40d
  16. searchindex_model_reload([Ticket])
  17. end
  18. let(:group_1) { Group.lookup(name: 'Users') }
  19. let(:group_2) { create(:group) }
  20. let(:customer) { User.lookup(email: 'nicole.braun@zammad.org') }
  21. let(:ticket_1) do
  22. travel_to DateTime.new 2015, 10, 28, 9, 30
  23. ticket = create(:ticket,
  24. group: group_2,
  25. customer: customer,
  26. state_name: 'new',
  27. priority_name: '2 normal')
  28. ticket.tag_add('aaa', 1)
  29. ticket.tag_add('bbb', 1)
  30. create(:ticket_article,
  31. :inbound_email,
  32. ticket: ticket)
  33. travel 5.hours
  34. ticket.update! group: group_1
  35. travel_back
  36. ticket
  37. end
  38. let(:ticket_2) do
  39. travel_to DateTime.new 2015, 10, 28, 9, 30, 1
  40. ticket = create(:ticket,
  41. group: group_1,
  42. customer: customer,
  43. state_name: 'new',
  44. priority_name: '2 normal')
  45. ticket.tag_add('aaa', 1)
  46. create(:ticket_article,
  47. :inbound_email,
  48. ticket: ticket)
  49. travel 5.hours - 1.second
  50. ticket.update! group: group_2
  51. travel_back
  52. ticket
  53. end
  54. let(:ticket_3) do
  55. travel_to DateTime.new 2015, 10, 28, 10, 30
  56. ticket = create(:ticket,
  57. group: group_1,
  58. customer: customer,
  59. state_name: 'open',
  60. priority_name: '3 high')
  61. create(:ticket_article,
  62. :inbound_email,
  63. ticket: ticket)
  64. travel_back
  65. ticket
  66. end
  67. let(:ticket_4) do
  68. travel_to DateTime.new 2015, 10, 28, 10, 30, 1
  69. ticket = create(:ticket,
  70. group: group_1,
  71. customer: customer,
  72. state_name: 'closed',
  73. priority_name: '2 normal',
  74. close_at: (1.hour - 1.second).from_now)
  75. create(:ticket_article,
  76. :inbound_email,
  77. ticket: ticket)
  78. travel_back
  79. ticket
  80. end
  81. let(:ticket_5) do
  82. travel_to DateTime.new 2015, 10, 28, 11, 30
  83. ticket = create(:ticket,
  84. group: group_1,
  85. customer: customer,
  86. state_name: 'closed',
  87. priority_name: '3 high',
  88. close_at: 10.minutes.from_now)
  89. ticket.tag_add('bbb', 1)
  90. create(:ticket_article,
  91. :outbound_email,
  92. ticket: ticket)
  93. ticket.update! state: Ticket::State.lookup(name: 'open')
  94. travel 3.hours
  95. travel_back
  96. ticket
  97. end
  98. let(:ticket_6) do
  99. travel_to DateTime.new 2015, 10, 31, 12, 30
  100. ticket = create(:ticket,
  101. group: group_1,
  102. customer: customer,
  103. state_name: 'closed',
  104. priority_name: '2 normal',
  105. close_at: 5.minutes.from_now)
  106. create(:ticket_article,
  107. :outbound_email,
  108. ticket: ticket)
  109. travel_back
  110. ticket
  111. end
  112. let(:ticket_7) do
  113. travel_to DateTime.new 2015, 11, 1, 12, 30
  114. ticket = create(:ticket,
  115. group: group_1,
  116. customer: customer,
  117. state_name: 'closed',
  118. priority_name: '2 normal',
  119. close_at: Time.zone.now)
  120. create(:ticket_article,
  121. :inbound_email,
  122. ticket: ticket)
  123. travel_back
  124. ticket
  125. end
  126. let(:ticket_8) do
  127. travel_to DateTime.new 2015, 11, 2, 12, 30
  128. ticket = create(:ticket,
  129. group: group_1,
  130. customer: customer,
  131. state_name: 'open',
  132. priority_name: '2 normal',
  133. close_at: Time.zone.now)
  134. create(:ticket_article,
  135. :inbound_email,
  136. ticket: ticket)
  137. travel 10.minutes
  138. ticket.update!(state: Ticket::State.lookup(name: 'merged'))
  139. travel_back
  140. ticket
  141. end
  142. let(:ticket_9) do
  143. travel_to DateTime.new 2037, 11, 2, 12, 30
  144. ticket = create(:ticket,
  145. group: group_1,
  146. customer: customer,
  147. state_name: 'merged',
  148. priority_name: '2 normal',
  149. close_at: Time.zone.now)
  150. create(:ticket_article,
  151. :inbound_email,
  152. ticket: ticket)
  153. travel 10.minutes
  154. ticket.update!(state: Ticket::State.lookup(name: 'merged'))
  155. travel_back
  156. ticket
  157. end
  158. let(:ticket_after_72h) do
  159. travel 72.hours do
  160. ticket = create(:ticket,
  161. group: group_1,
  162. customer: customer,
  163. state_name: 'closed',
  164. priority_name: '2 normal',
  165. close_at: 5.minutes.from_now)
  166. create(:ticket_article,
  167. :outbound_email,
  168. ticket: ticket)
  169. ticket
  170. end
  171. end
  172. let(:ticket_before_40d) do
  173. travel(-40.days) do
  174. ticket = create(:ticket,
  175. group: group_1,
  176. customer: customer,
  177. state_name: 'closed',
  178. priority_name: '2 normal',
  179. close_at: 5.minutes.from_now)
  180. create(:ticket_article,
  181. :outbound_email,
  182. ticket: ticket)
  183. ticket
  184. end
  185. end
  186. matcher :match_tickets do
  187. match do
  188. if expected_tickets.blank?
  189. actual_ticket_ids.blank?
  190. else
  191. # GenericTime returns string ids :o
  192. actual_ticket_ids.map(&:to_i) == expected_tickets.map(&:id)
  193. end
  194. end
  195. def expected_tickets
  196. Array(expected)
  197. end
  198. def actual_ticket_ids
  199. actual[:ticket_ids]
  200. end
  201. end
  202. end