report_examples.rb 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. # Copyright (C) 2012-2023 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: 'merged',
  132. priority_name: '2 normal',
  133. close_at: Time.zone.now)
  134. create(:ticket_article,
  135. :inbound_email,
  136. ticket: ticket)
  137. travel_back
  138. ticket
  139. end
  140. let(:ticket_9) do
  141. travel_to DateTime.new 2037, 11, 2, 12, 30
  142. ticket = create(:ticket,
  143. group: group_1,
  144. customer: customer,
  145. state_name: 'merged',
  146. priority_name: '2 normal',
  147. close_at: Time.zone.now)
  148. create(:ticket_article,
  149. :inbound_email,
  150. ticket: ticket)
  151. travel_back
  152. ticket
  153. end
  154. let(:ticket_after_72h) do
  155. travel 72.hours do
  156. ticket = create(:ticket,
  157. group: group_1,
  158. customer: customer,
  159. state_name: 'closed',
  160. priority_name: '2 normal',
  161. close_at: 5.minutes.from_now)
  162. create(:ticket_article,
  163. :outbound_email,
  164. ticket: ticket)
  165. ticket
  166. end
  167. end
  168. let(:ticket_before_40d) do
  169. travel(-40.days) do
  170. ticket = create(:ticket,
  171. group: group_1,
  172. customer: customer,
  173. state_name: 'closed',
  174. priority_name: '2 normal',
  175. close_at: 5.minutes.from_now)
  176. create(:ticket_article,
  177. :outbound_email,
  178. ticket: ticket)
  179. ticket
  180. end
  181. end
  182. matcher :match_tickets do
  183. match do
  184. if expected_tickets.blank?
  185. actual_ticket_ids.blank?
  186. else
  187. # GenericTime returns string ids :o
  188. actual_ticket_ids.map(&:to_i) == expected_tickets.map(&:id)
  189. end
  190. end
  191. def expected_tickets
  192. Array(expected)
  193. end
  194. def actual_ticket_ids
  195. actual[:ticket_ids]
  196. end
  197. end
  198. end