ticket_first_solution_spec.rb 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'lib/report_examples'
  4. RSpec.describe Report::TicketFirstSolution, searchindex: true do
  5. include_examples 'with report examples'
  6. describe '.aggs' do
  7. it 'gets monthly aggregated results' do
  8. result = described_class.aggs(
  9. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  10. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  11. interval: 'month',
  12. selector: {},
  13. )
  14. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0]
  15. end
  16. it 'gets monthly aggregated results with high priority' do
  17. result = described_class.aggs(
  18. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  19. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  20. interval: 'month',
  21. selector: {
  22. 'ticket.priority_id' => {
  23. 'operator' => 'is',
  24. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  25. }
  26. },
  27. )
  28. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
  29. end
  30. it 'gets monthly aggregated results not in merged state' do
  31. result = described_class.aggs(
  32. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  33. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  34. interval: 'month',
  35. selector: {
  36. 'ticket_state.name' => {
  37. 'operator' => 'is not',
  38. 'value' => 'merged',
  39. }
  40. },
  41. )
  42. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0]
  43. end
  44. it 'gets monthly aggregated results with not high priority' do
  45. result = described_class.aggs(
  46. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  47. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  48. interval: 'month',
  49. selector: {
  50. 'ticket.priority_id' => {
  51. 'operator' => 'is not',
  52. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  53. }
  54. },
  55. )
  56. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0]
  57. end
  58. it 'gets weekly aggregated results' do
  59. result = described_class.aggs(
  60. range_start: Time.zone.parse('2015-10-26T00:00:00Z'),
  61. range_end: Time.zone.parse('2015-10-31T23:59:59Z'),
  62. interval: 'week',
  63. selector: {},
  64. )
  65. expect(result).to eq [0, 0, 1, 0, 0, 1, 1]
  66. end
  67. it 'gets daily aggregated results' do
  68. result = described_class.aggs(
  69. range_start: Time.zone.parse('2015-10-01T00:00:00Z'),
  70. range_end: Time.zone.parse('2015-11-01T23:59:59Z'),
  71. interval: 'day',
  72. selector: {},
  73. )
  74. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1]
  75. end
  76. it 'gets hourly aggregated results' do
  77. result = described_class.aggs(
  78. range_start: Time.zone.parse('2015-10-28T00:00:00Z'),
  79. range_end: Time.zone.parse('2015-10-28T23:59:59Z'),
  80. interval: 'hour',
  81. selector: {},
  82. )
  83. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  84. end
  85. end
  86. describe '.items' do
  87. it 'gets items in year range' do
  88. result = described_class.items(
  89. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  90. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  91. selector: {},
  92. )
  93. expect(result).to match_tickets ticket_5, ticket_6, ticket_7
  94. end
  95. it 'gets items in year range with high priority' do
  96. result = described_class.items(
  97. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  98. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  99. selector: {
  100. 'ticket.priority_id' => {
  101. 'operator' => 'is',
  102. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  103. }
  104. }
  105. )
  106. expect(result).to match_tickets ticket_5
  107. end
  108. it 'gets items in year range not in merged state' do
  109. result = described_class.items(
  110. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  111. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  112. selector: {
  113. 'ticket_state.name' => {
  114. 'operator' => 'is not',
  115. 'value' => 'merged',
  116. }
  117. }
  118. )
  119. expect(result).to match_tickets ticket_5, ticket_6, ticket_7
  120. end
  121. it 'gets items in year range with not high priority' do
  122. result = described_class.items(
  123. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  124. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  125. selector: {
  126. 'ticket.priority_id' => {
  127. 'operator' => 'is not',
  128. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  129. }
  130. }
  131. )
  132. expect(result).to match_tickets ticket_6, ticket_7
  133. end
  134. it 'gets items in week range' do
  135. result = described_class.items(
  136. range_start: Time.zone.parse('2015-10-26T00:00:00Z'),
  137. range_end: Time.zone.parse('2015-11-01T23:59:59Z'),
  138. selector: {}
  139. )
  140. expect(result).to match_tickets ticket_5, ticket_6, ticket_7
  141. end
  142. it 'gets items in day range' do
  143. result = described_class.items(
  144. range_start: Time.zone.parse('2015-10-01T00:00:00Z'),
  145. range_end: Time.zone.parse('2015-10-31T23:59:59Z'),
  146. selector: {}
  147. )
  148. expect(result).to match_tickets ticket_5, ticket_6
  149. end
  150. it 'gets items in hour range' do
  151. result = described_class.items(
  152. range_start: Time.zone.parse('2015-10-28T00:00:00Z'),
  153. range_end: Time.zone.parse('2015-10-28T23:59:59Z'),
  154. interval: 'hour',
  155. selector: {},
  156. )
  157. expect(result).to match_tickets ticket_5
  158. end
  159. end
  160. end