ticket_moved_spec.rb 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. #
  3. # rubocop:disable RSpec/ExampleLength
  4. require 'rails_helper'
  5. require 'lib/report_examples'
  6. RSpec.describe Report::TicketMoved, searchindex: true do
  7. include_examples 'with report examples'
  8. describe '.aggs' do
  9. it 'gets monthly aggregated results not in merged state' do
  10. result = described_class.aggs(
  11. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  12. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  13. interval: 'month',
  14. selector: {
  15. 'ticket_state.name' => {
  16. 'operator' => 'is not',
  17. 'value' => 'merged',
  18. }
  19. },
  20. params: {
  21. type: 'in',
  22. },
  23. )
  24. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  25. end
  26. it 'gets monthly aggregated results in users group' do
  27. result = described_class.aggs(
  28. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  29. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  30. interval: 'month',
  31. selector: {
  32. 'ticket.group_id' => {
  33. 'operator' => 'is',
  34. 'value' => [Group.lookup(name: 'Users').id],
  35. }
  36. },
  37. params: {
  38. type: 'in',
  39. },
  40. )
  41. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
  42. end
  43. it 'gets monthly aggregated results not in merged state and outgoing' do
  44. result = described_class.aggs(
  45. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  46. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  47. interval: 'month',
  48. selector: {
  49. 'ticket_state.name' => {
  50. 'operator' => 'is not',
  51. 'value' => 'merged',
  52. }
  53. },
  54. params: {
  55. type: 'out',
  56. },
  57. )
  58. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  59. end
  60. it 'gets monthly aggregated results in users group and outgoing' do
  61. result = described_class.aggs(
  62. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  63. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  64. interval: 'month',
  65. selector: {
  66. 'ticket.group_id' => {
  67. 'operator' => 'is',
  68. 'value' => [Group.lookup(name: 'Users').id],
  69. }
  70. },
  71. params: {
  72. type: 'out',
  73. },
  74. )
  75. expect(result).to eq [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0]
  76. end
  77. end
  78. describe '.items' do
  79. it 'gets items in year range in users group' do
  80. result = described_class.items(
  81. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  82. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  83. selector: {
  84. 'ticket.group_id' => {
  85. 'operator' => 'is',
  86. 'value' => [Group.lookup(name: 'Users').id],
  87. }
  88. },
  89. params: {
  90. type: 'in',
  91. },
  92. )
  93. expect(result).to match_tickets ticket_1
  94. end
  95. it 'gets items in year range not merged and outgoing' 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_state.name' => {
  101. 'operator' => 'is not',
  102. 'value' => 'merged',
  103. }
  104. }, # ticket selector to get only a collection of tickets
  105. params: {
  106. type: 'out',
  107. },
  108. )
  109. expect(result).to match_tickets []
  110. end
  111. it 'gets items in year range in users group and outgoing' do
  112. result = described_class.items(
  113. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  114. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  115. selector: {
  116. 'ticket.group_id' => {
  117. 'operator' => 'is',
  118. 'value' => [Group.lookup(name: 'Users').id],
  119. }
  120. },
  121. params: {
  122. type: 'out',
  123. },
  124. )
  125. expect(result).to match_tickets ticket_2
  126. end
  127. end
  128. end
  129. # rubocop:enable RSpec/ExampleLength