report_examples.rb 5.9 KB

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