report_test.rb 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  1. require 'integration_test_helper'
  2. class ReportTest < ActiveSupport::TestCase
  3. include SearchindexHelper
  4. setup do
  5. # create attribute
  6. ObjectManager::Attribute.add(
  7. object: 'Ticket',
  8. name: 'test_category',
  9. display: 'Test 1',
  10. data_type: 'tree_select',
  11. data_option: {
  12. maxlength: 200,
  13. null: false,
  14. default: '',
  15. options: [
  16. { 'name' => 'aa', 'value' => 'aa', 'children' => [{ 'name' => 'aa', 'value' => 'aa::aa' }, { 'name' => 'bb', 'value' => 'aa::bb' }, { 'name' => 'cc', 'value' => 'aa::cc' }] },
  17. { 'name' => 'bb', 'value' => 'bb', 'children' => [{ 'name' => 'aa', 'value' => 'bb::aa' }, { 'name' => 'bb', 'value' => 'bb::bb' }, { 'name' => 'cc', 'value' => 'bb::cc' }] },
  18. { 'name' => 'cc', 'value' => 'cc', 'children' => [{ 'name' => 'aa', 'value' => 'cc::aa' }, { 'name' => 'bb', 'value' => 'cc::bb' }, { 'name' => 'cc', 'value' => 'cc::cc' }] },
  19. ]
  20. },
  21. active: true,
  22. screens: {},
  23. position: 20,
  24. created_by_id: 1,
  25. updated_by_id: 1,
  26. editable: false,
  27. to_migrate: false,
  28. )
  29. ObjectManager::Attribute.migration_execute
  30. configure_elasticsearch(required: true)
  31. Ticket.destroy_all
  32. rebuild_searchindex
  33. group1 = Group.lookup(name: 'Users')
  34. group2 = Group.create!(
  35. name: 'Report Test',
  36. updated_by_id: 1,
  37. created_by_id: 1
  38. )
  39. @ticket1 = Ticket.create!(
  40. title: 'test 1',
  41. group: group2,
  42. customer_id: 2,
  43. state: Ticket::State.lookup(name: 'new'),
  44. priority: Ticket::Priority.lookup(name: '2 normal'),
  45. created_at: '2015-10-28 09:30:00 UTC',
  46. updated_at: '2015-10-28 09:30:00 UTC',
  47. test_category: 'cc::bb',
  48. updated_by_id: 1,
  49. created_by_id: 1,
  50. )
  51. Ticket::Article.create!(
  52. ticket_id: @ticket1.id,
  53. from: 'some_sender@example.com',
  54. to: 'some_recipient@example.com',
  55. subject: 'some subject',
  56. message_id: 'some@id',
  57. body: 'some message article_inbound',
  58. internal: false,
  59. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  60. type: Ticket::Article::Type.where(name: 'email').first,
  61. created_at: '2015-10-28 09:30:00 UTC',
  62. updated_at: '2015-10-28 09:30:00 UTC',
  63. updated_by_id: 1,
  64. created_by_id: 1,
  65. )
  66. @ticket1.tag_add('aaa', 1)
  67. @ticket1.tag_add('bbb', 1)
  68. @ticket1.update!(
  69. group: Group.lookup(name: 'Users'),
  70. updated_at: '2015-10-28 14:30:00 UTC',
  71. )
  72. @ticket2 = Ticket.create!(
  73. title: 'test 2',
  74. group: group1,
  75. customer_id: 2,
  76. state: Ticket::State.lookup(name: 'new'),
  77. priority: Ticket::Priority.lookup(name: '2 normal'),
  78. created_at: '2015-10-28 09:30:01 UTC',
  79. updated_at: '2015-10-28 09:30:01 UTC',
  80. updated_by_id: 1,
  81. created_by_id: 1,
  82. )
  83. Ticket::Article.create!(
  84. ticket_id: @ticket2.id,
  85. from: 'some_sender@example.com',
  86. to: 'some_recipient@example.com',
  87. subject: 'some subject',
  88. message_id: 'some@id',
  89. body: 'some message article_inbound',
  90. internal: false,
  91. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  92. type: Ticket::Article::Type.where(name: 'email').first,
  93. created_at: '2015-10-28 09:30:01 UTC',
  94. updated_at: '2015-10-28 09:30:01 UTC',
  95. updated_by_id: 1,
  96. created_by_id: 1,
  97. )
  98. @ticket2.tag_add('aaa', 1)
  99. @ticket2.update!(
  100. group_id: group2.id,
  101. updated_at: '2015-10-28 14:30:00 UTC',
  102. )
  103. @ticket3 = Ticket.create!(
  104. title: 'test 3',
  105. group: group1,
  106. customer_id: 2,
  107. state: Ticket::State.lookup(name: 'open'),
  108. priority: Ticket::Priority.lookup(name: '3 high'),
  109. created_at: '2015-10-28 10:30:00 UTC',
  110. updated_at: '2015-10-28 10:30:00 UTC',
  111. updated_by_id: 1,
  112. created_by_id: 1,
  113. )
  114. Ticket::Article.create!(
  115. ticket_id: @ticket3.id,
  116. from: 'some_sender@example.com',
  117. to: 'some_recipient@example.com',
  118. subject: 'some subject',
  119. message_id: 'some@id',
  120. body: 'some message article_inbound',
  121. internal: false,
  122. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  123. type: Ticket::Article::Type.where(name: 'email').first,
  124. created_at: '2015-10-28 10:30:00 UTC',
  125. updated_at: '2015-10-28 10:30:00 UTC',
  126. updated_by_id: 1,
  127. created_by_id: 1,
  128. )
  129. @ticket4 = Ticket.create!(
  130. title: 'test 4',
  131. group: group1,
  132. customer_id: 2,
  133. state: Ticket::State.lookup(name: 'closed'),
  134. priority: Ticket::Priority.lookup(name: '2 normal'),
  135. close_at: '2015-10-28 11:30:00 UTC',
  136. created_at: '2015-10-28 10:30:01 UTC',
  137. updated_at: '2015-10-28 10:30:01 UTC',
  138. updated_by_id: 1,
  139. created_by_id: 1,
  140. )
  141. Ticket::Article.create!(
  142. ticket_id: @ticket4.id,
  143. from: 'some_sender@example.com',
  144. to: 'some_recipient@example.com',
  145. subject: 'some subject',
  146. message_id: 'some@id',
  147. body: 'some message article_inbound',
  148. internal: false,
  149. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  150. type: Ticket::Article::Type.where(name: 'email').first,
  151. created_at: '2015-10-28 10:30:01 UTC',
  152. updated_at: '2015-10-28 10:30:01 UTC',
  153. updated_by_id: 1,
  154. created_by_id: 1,
  155. )
  156. @ticket5 = Ticket.create!(
  157. title: 'test 5',
  158. group: group1,
  159. customer_id: 2,
  160. state: Ticket::State.lookup(name: 'closed'),
  161. priority: Ticket::Priority.lookup(name: '3 high'),
  162. close_at: '2015-10-28 11:40:00 UTC',
  163. created_at: '2015-10-28 11:30:00 UTC',
  164. updated_at: '2015-10-28 11:30:00 UTC',
  165. updated_by_id: 1,
  166. created_by_id: 1,
  167. )
  168. Ticket::Article.create!(
  169. ticket_id: @ticket5.id,
  170. from: 'some_sender@example.com',
  171. to: 'some_recipient@example.com',
  172. subject: 'some subject',
  173. message_id: 'some@id',
  174. body: 'some message article_outbound',
  175. internal: false,
  176. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  177. type: Ticket::Article::Type.where(name: 'email').first,
  178. created_at: '2015-10-28 11:30:00 UTC',
  179. updated_at: '2015-10-28 11:30:00 UTC',
  180. updated_by_id: 1,
  181. created_by_id: 1,
  182. )
  183. @ticket5.tag_add('bbb', 1)
  184. @ticket5.update!(
  185. state: Ticket::State.lookup(name: 'open'),
  186. updated_at: '2015-10-28 14:30:00 UTC',
  187. )
  188. @ticket6 = Ticket.create!(
  189. title: 'test 6',
  190. group: group1,
  191. customer_id: 2,
  192. state: Ticket::State.lookup(name: 'closed'),
  193. priority: Ticket::Priority.lookup(name: '2 normal'),
  194. close_at: '2015-10-31 12:35:00 UTC',
  195. created_at: '2015-10-31 12:30:00 UTC',
  196. updated_at: '2015-10-31 12:30:00 UTC',
  197. updated_by_id: 1,
  198. created_by_id: 1,
  199. )
  200. Ticket::Article.create!(
  201. ticket_id: @ticket6.id,
  202. from: 'some_sender@example.com',
  203. to: 'some_recipient@example.com',
  204. subject: 'some subject',
  205. message_id: 'some@id',
  206. body: 'some message article_outbound',
  207. internal: false,
  208. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  209. type: Ticket::Article::Type.where(name: 'email').first,
  210. created_at: '2015-10-31 12:30:00 UTC',
  211. updated_at: '2015-10-31 12:30:00 UTC',
  212. updated_by_id: 1,
  213. created_by_id: 1,
  214. )
  215. @ticket7 = Ticket.create!(
  216. title: 'test 7',
  217. group: group1,
  218. customer_id: 2,
  219. state: Ticket::State.lookup(name: 'closed'),
  220. priority: Ticket::Priority.lookup(name: '2 normal'),
  221. close_at: '2015-11-01 12:30:00 UTC',
  222. created_at: '2015-11-01 12:30:00 UTC',
  223. updated_at: '2015-11-01 12:30:00 UTC',
  224. updated_by_id: 1,
  225. created_by_id: 1,
  226. )
  227. Ticket::Article.create!(
  228. ticket_id: @ticket7.id,
  229. from: 'some_sender@example.com',
  230. to: 'some_recipient@example.com',
  231. subject: 'some subject',
  232. message_id: 'some@id',
  233. body: 'some message article_outbound',
  234. internal: false,
  235. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  236. type: Ticket::Article::Type.where(name: 'email').first,
  237. created_at: '2015-11-01 12:30:00 UTC',
  238. updated_at: '2015-11-01 12:30:00 UTC',
  239. updated_by_id: 1,
  240. created_by_id: 1,
  241. )
  242. @ticket8 = Ticket.create!(
  243. title: 'test 8',
  244. group: group1,
  245. customer_id: 2,
  246. state: Ticket::State.lookup(name: 'merged'),
  247. priority: Ticket::Priority.lookup(name: '2 normal'),
  248. close_at: '2015-11-02 12:30:00 UTC',
  249. created_at: '2015-11-02 12:30:00 UTC',
  250. updated_at: '2015-11-02 12:30:00 UTC',
  251. updated_by_id: 1,
  252. created_by_id: 1,
  253. )
  254. Ticket::Article.create!(
  255. ticket_id: @ticket8.id,
  256. from: 'some_sender@example.com',
  257. to: 'some_recipient@example.com',
  258. subject: 'some subject',
  259. message_id: 'some@id',
  260. body: 'some message article_outbound',
  261. internal: false,
  262. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  263. type: Ticket::Article::Type.where(name: 'email').first,
  264. created_at: '2015-11-02 12:30:00 UTC',
  265. updated_at: '2015-11-02 12:30:00 UTC',
  266. updated_by_id: 1,
  267. created_by_id: 1,
  268. )
  269. @ticket9 = Ticket.create!(
  270. title: 'test 9',
  271. group: group1,
  272. customer_id: 2,
  273. state: Ticket::State.lookup(name: 'open'),
  274. priority: Ticket::Priority.lookup(name: '2 normal'),
  275. close_at: '2037-11-02 12:30:00 UTC',
  276. created_at: '2037-11-02 12:30:00 UTC',
  277. updated_at: '2037-11-02 12:30:00 UTC',
  278. updated_by_id: 1,
  279. created_by_id: 1,
  280. )
  281. Ticket::Article.create!(
  282. ticket_id: @ticket9.id,
  283. from: 'some_sender@example.com',
  284. to: 'some_recipient@example.com',
  285. subject: 'some subject',
  286. message_id: 'some@id',
  287. body: 'some message article_outbound',
  288. internal: false,
  289. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  290. type: Ticket::Article::Type.where(name: 'email').first,
  291. created_at: '2037-11-02 12:30:00 UTC',
  292. updated_at: '2037-11-02 12:30:00 UTC',
  293. updated_by_id: 1,
  294. created_by_id: 1,
  295. )
  296. # execute background jobs
  297. Scheduler.worker(true)
  298. end
  299. test 'compare' do
  300. # first solution
  301. result = Report::TicketFirstSolution.aggs(
  302. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  303. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  304. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  305. selector: {}, # ticket selector to get only a collection of tickets
  306. )
  307. assert(result)
  308. assert_equal(0, result[0])
  309. assert_equal(0, result[1])
  310. assert_equal(0, result[2])
  311. assert_equal(0, result[3])
  312. assert_equal(0, result[4])
  313. assert_equal(0, result[5])
  314. assert_equal(0, result[6])
  315. assert_equal(0, result[7])
  316. assert_equal(0, result[8])
  317. assert_equal(2, result[9])
  318. assert_equal(1, result[10])
  319. assert_equal(0, result[11])
  320. assert_nil(result[12])
  321. result = Report::TicketFirstSolution.items(
  322. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  323. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  324. selector: {}, # ticket selector to get only a collection of tickets
  325. )
  326. assert(result)
  327. assert_equal(@ticket5.id, result[:ticket_ids][0])
  328. assert_equal(@ticket6.id, result[:ticket_ids][1])
  329. assert_equal(@ticket7.id, result[:ticket_ids][2])
  330. assert_nil(result[:ticket_ids][3])
  331. # month - with selector #1
  332. result = Report::TicketFirstSolution.aggs(
  333. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  334. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  335. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  336. selector: {
  337. 'ticket.priority_id' => {
  338. 'operator' => 'is',
  339. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  340. }
  341. }, # ticket selector to get only a collection of tickets
  342. )
  343. assert(result)
  344. assert_equal(0, result[0])
  345. assert_equal(0, result[1])
  346. assert_equal(0, result[2])
  347. assert_equal(0, result[3])
  348. assert_equal(0, result[4])
  349. assert_equal(0, result[5])
  350. assert_equal(0, result[6])
  351. assert_equal(0, result[7])
  352. assert_equal(0, result[8])
  353. assert_equal(1, result[9])
  354. assert_equal(0, result[10])
  355. assert_equal(0, result[11])
  356. assert_nil(result[12])
  357. result = Report::TicketFirstSolution.items(
  358. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  359. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  360. selector: {
  361. 'ticket.priority_id' => {
  362. 'operator' => 'is',
  363. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  364. }
  365. }, # ticket selector to get only a collection of tickets
  366. )
  367. assert(result)
  368. assert_equal(@ticket5.id, result[:ticket_ids][0])
  369. assert_nil(result[:ticket_ids][1])
  370. # month - with merged tickets selector
  371. result = Report::TicketFirstSolution.aggs(
  372. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  373. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  374. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  375. selector: {
  376. 'ticket_state.name' => {
  377. 'operator' => 'is not',
  378. 'value' => 'merged',
  379. }
  380. }, # ticket selector to get only a collection of tickets
  381. )
  382. assert(result)
  383. assert_equal(0, result[0])
  384. assert_equal(0, result[1])
  385. assert_equal(0, result[2])
  386. assert_equal(0, result[3])
  387. assert_equal(0, result[4])
  388. assert_equal(0, result[5])
  389. assert_equal(0, result[6])
  390. assert_equal(0, result[7])
  391. assert_equal(0, result[8])
  392. assert_equal(2, result[9])
  393. assert_equal(1, result[10])
  394. assert_equal(0, result[11])
  395. assert_nil(result[12])
  396. result = Report::TicketFirstSolution.items(
  397. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  398. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  399. selector: {
  400. 'ticket_state.name' => {
  401. 'operator' => 'is not',
  402. 'value' => 'merged',
  403. }
  404. }, # ticket selector to get only a collection of tickets
  405. )
  406. assert(result)
  407. assert_equal(@ticket5.id, result[:ticket_ids][0])
  408. assert_nil(result[:ticket_ids][3])
  409. # month - with selector #2
  410. result = Report::TicketFirstSolution.aggs(
  411. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  412. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  413. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  414. selector: {
  415. 'ticket.priority_id' => {
  416. 'operator' => 'is not',
  417. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  418. }
  419. }, # ticket selector to get only a collection of tickets
  420. )
  421. assert(result)
  422. assert_equal(0, result[0])
  423. assert_equal(0, result[1])
  424. assert_equal(0, result[2])
  425. assert_equal(0, result[3])
  426. assert_equal(0, result[4])
  427. assert_equal(0, result[5])
  428. assert_equal(0, result[6])
  429. assert_equal(0, result[7])
  430. assert_equal(0, result[8])
  431. assert_equal(1, result[9])
  432. assert_equal(1, result[10])
  433. assert_equal(0, result[11])
  434. assert_nil(result[12])
  435. result = Report::TicketFirstSolution.items(
  436. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  437. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  438. selector: {
  439. 'ticket.priority_id' => {
  440. 'operator' => 'is not',
  441. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  442. }
  443. }, # ticket selector to get only a collection of tickets
  444. )
  445. assert(result)
  446. assert_equal(@ticket6.id, result[:ticket_ids][0])
  447. assert_equal(@ticket7.id, result[:ticket_ids][1])
  448. assert_nil(result[:ticket_ids][2])
  449. # week
  450. result = Report::TicketFirstSolution.aggs(
  451. range_start: Time.zone.parse('2015-10-26T00:00:00Z'),
  452. range_end: Time.zone.parse('2015-10-31T23:59:59Z'),
  453. interval: 'week', # year, quarter, month, week, day, hour, minute, second
  454. selector: {}, # ticket selector to get only a collection of tickets
  455. )
  456. assert(result)
  457. assert_equal(0, result[0])
  458. assert_equal(0, result[1])
  459. assert_equal(1, result[2])
  460. assert_equal(0, result[3])
  461. assert_equal(0, result[4])
  462. assert_equal(1, result[5])
  463. assert_equal(1, result[6])
  464. assert_nil(result[7])
  465. result = Report::TicketFirstSolution.items(
  466. range_start: Time.zone.parse('2015-10-26T00:00:00Z'),
  467. range_end: Time.zone.parse('2015-11-01T23:59:59Z'),
  468. interval: 'week', # year, quarter, month, week, day, hour, minute, second
  469. selector: {}, # ticket selector to get only a collection of tickets
  470. )
  471. assert(result)
  472. assert_equal(@ticket5.id, result[:ticket_ids][0])
  473. assert_equal(@ticket6.id, result[:ticket_ids][1])
  474. assert_equal(@ticket7.id, result[:ticket_ids][2])
  475. assert_nil(result[:ticket_ids][3])
  476. # day
  477. result = Report::TicketFirstSolution.aggs(
  478. range_start: Time.zone.parse('2015-10-01T00:00:00Z'),
  479. range_end: Time.zone.parse('2015-11-01T23:59:59Z'),
  480. interval: 'day', # year, quarter, month, week, day, hour, minute, second
  481. selector: {}, # ticket selector to get only a collection of tickets
  482. )
  483. assert(result)
  484. assert_equal(0, result[0])
  485. assert_equal(0, result[1])
  486. assert_equal(0, result[2])
  487. assert_equal(0, result[3])
  488. assert_equal(0, result[4])
  489. assert_equal(0, result[5])
  490. assert_equal(0, result[6])
  491. assert_equal(0, result[7])
  492. assert_equal(0, result[8])
  493. assert_equal(0, result[9])
  494. assert_equal(0, result[10])
  495. assert_equal(0, result[11])
  496. assert_equal(0, result[12])
  497. assert_equal(0, result[13])
  498. assert_equal(0, result[14])
  499. assert_equal(0, result[15])
  500. assert_equal(0, result[16])
  501. assert_equal(0, result[17])
  502. assert_equal(0, result[18])
  503. assert_equal(0, result[19])
  504. assert_equal(0, result[20])
  505. assert_equal(0, result[21])
  506. assert_equal(0, result[22])
  507. assert_equal(0, result[23])
  508. assert_equal(0, result[24])
  509. assert_equal(0, result[25])
  510. assert_equal(0, result[26])
  511. assert_equal(1, result[27])
  512. assert_equal(0, result[28])
  513. assert_equal(0, result[29])
  514. assert_equal(1, result[30])
  515. assert_nil(result[31])
  516. result = Report::TicketFirstSolution.items(
  517. range_start: Time.zone.parse('2015-10-01T00:00:00Z'),
  518. range_end: Time.zone.parse('2015-10-31T23:59:59Z'),
  519. interval: 'day', # year, quarter, month, week, day, hour, minute, second
  520. selector: {}, # ticket selector to get only a collection of tickets
  521. )
  522. assert(result)
  523. assert_equal(@ticket5.id, result[:ticket_ids][0])
  524. assert_equal(@ticket6.id, result[:ticket_ids][1])
  525. assert_nil(result[:ticket_ids][2])
  526. # hour
  527. result = Report::TicketFirstSolution.aggs(
  528. range_start: Time.zone.parse('2015-10-28T00:00:00Z'),
  529. range_end: Time.zone.parse('2015-10-28T23:59:59Z'),
  530. interval: 'hour', # year, quarter, month, week, day, hour, minute, second
  531. selector: {}, # ticket selector to get only a collection of tickets
  532. )
  533. assert(result)
  534. assert_equal(0, result[0])
  535. assert_equal(0, result[1])
  536. assert_equal(0, result[2])
  537. assert_equal(0, result[3])
  538. assert_equal(0, result[4])
  539. assert_equal(0, result[5])
  540. assert_equal(0, result[6])
  541. assert_equal(0, result[7])
  542. assert_equal(0, result[8])
  543. assert_equal(0, result[9])
  544. assert_equal(0, result[10])
  545. assert_equal(1, result[11])
  546. assert_equal(0, result[12])
  547. assert_equal(0, result[13])
  548. assert_equal(0, result[14])
  549. assert_equal(0, result[15])
  550. assert_equal(0, result[16])
  551. assert_equal(0, result[17])
  552. assert_equal(0, result[18])
  553. assert_equal(0, result[19])
  554. assert_equal(0, result[20])
  555. assert_equal(0, result[21])
  556. assert_equal(0, result[22])
  557. assert_equal(0, result[23])
  558. assert_nil(result[24])
  559. result = Report::TicketFirstSolution.items(
  560. range_start: Time.zone.parse('2015-10-28T00:00:00Z'),
  561. range_end: Time.zone.parse('2015-10-28T23:59:59Z'),
  562. interval: 'hour', # year, quarter, month, week, day, hour, minute, second
  563. selector: {}, # ticket selector to get only a collection of tickets
  564. )
  565. assert(result)
  566. assert_equal(@ticket5.id, result[:ticket_ids][0])
  567. assert_nil(result[:ticket_ids][1])
  568. # reopen
  569. result = Report::TicketReopened.aggs(
  570. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  571. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  572. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  573. selector: {}, # ticket selector to get only a collection of tickets
  574. )
  575. assert(result)
  576. assert_equal(0, result[0])
  577. assert_equal(0, result[1])
  578. assert_equal(0, result[2])
  579. assert_equal(0, result[3])
  580. assert_equal(0, result[4])
  581. assert_equal(0, result[5])
  582. assert_equal(0, result[6])
  583. assert_equal(0, result[7])
  584. assert_equal(0, result[8])
  585. assert_equal(1, result[9])
  586. assert_equal(0, result[10])
  587. assert_equal(0, result[11])
  588. assert_nil(result[12])
  589. result = Report::TicketReopened.items(
  590. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  591. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  592. selector: {}, # ticket selector to get only a collection of tickets
  593. )
  594. assert(result)
  595. assert_equal(@ticket5.id, result[:ticket_ids][0])
  596. assert_nil(result[:ticket_ids][1])
  597. # month - with selector #1
  598. result = Report::TicketReopened.aggs(
  599. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  600. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  601. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  602. selector: {
  603. 'ticket.priority_id' => {
  604. 'operator' => 'is',
  605. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  606. }
  607. }, # ticket selector to get only a collection of tickets
  608. )
  609. assert(result)
  610. assert_equal(0, result[0])
  611. assert_equal(0, result[1])
  612. assert_equal(0, result[2])
  613. assert_equal(0, result[3])
  614. assert_equal(0, result[4])
  615. assert_equal(0, result[5])
  616. assert_equal(0, result[6])
  617. assert_equal(0, result[7])
  618. assert_equal(0, result[8])
  619. assert_equal(1, result[9])
  620. assert_equal(0, result[10])
  621. assert_equal(0, result[11])
  622. assert_nil(result[12])
  623. result = Report::TicketReopened.items(
  624. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  625. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  626. selector: {
  627. 'ticket.priority_id' => {
  628. 'operator' => 'is',
  629. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  630. }
  631. }, # ticket selector to get only a collection of tickets
  632. )
  633. assert(result)
  634. assert_equal(@ticket5.id, result[:ticket_ids][0])
  635. assert_nil(result[:ticket_ids][1])
  636. # month - with selector #2
  637. result = Report::TicketReopened.aggs(
  638. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  639. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  640. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  641. selector: {
  642. 'ticket.priority_id' => {
  643. 'operator' => 'is not',
  644. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  645. }
  646. }, # ticket selector to get only a collection of tickets
  647. )
  648. assert(result)
  649. assert_equal(0, result[0])
  650. assert_equal(0, result[1])
  651. assert_equal(0, result[2])
  652. assert_equal(0, result[3])
  653. assert_equal(0, result[4])
  654. assert_equal(0, result[5])
  655. assert_equal(0, result[6])
  656. assert_equal(0, result[7])
  657. assert_equal(0, result[8])
  658. assert_equal(0, result[9])
  659. assert_equal(0, result[10])
  660. assert_equal(0, result[11])
  661. assert_nil(result[12])
  662. result = Report::TicketReopened.items(
  663. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  664. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  665. selector: {
  666. 'ticket.priority_id' => {
  667. 'operator' => 'is not',
  668. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  669. }
  670. }, # ticket selector to get only a collection of tickets
  671. )
  672. assert(result)
  673. assert_nil(result[:ticket_ids][0])
  674. # month - reopened with merge selector
  675. result = Report::TicketReopened.aggs(
  676. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  677. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  678. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  679. selector: {
  680. 'ticket_state.name' => {
  681. 'operator' => 'is not',
  682. 'value' => 'merged',
  683. }
  684. }, # ticket selector to get only a collection of tickets
  685. )
  686. assert(result)
  687. assert_equal(0, result[0])
  688. assert_equal(0, result[1])
  689. assert_equal(0, result[2])
  690. assert_equal(0, result[3])
  691. assert_equal(0, result[4])
  692. assert_equal(0, result[5])
  693. assert_equal(0, result[6])
  694. assert_equal(0, result[7])
  695. assert_equal(0, result[8])
  696. assert_equal(1, result[9])
  697. assert_equal(0, result[10])
  698. assert_equal(0, result[11])
  699. assert_nil(result[12])
  700. result = Report::TicketReopened.items(
  701. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  702. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  703. selector: {
  704. 'ticket_state.name' => {
  705. 'operator' => 'is not',
  706. 'value' => 'merged',
  707. }
  708. }, # ticket selector to get only a collection of tickets
  709. )
  710. assert(result)
  711. assert_equal(@ticket5.id, result[:ticket_ids][0])
  712. assert_nil(result[:ticket_ids][1])
  713. # move in/out without merged status
  714. result = Report::TicketMoved.aggs(
  715. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  716. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  717. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  718. selector: {
  719. 'ticket_state.name' => {
  720. 'operator' => 'is not',
  721. 'value' => 'merged',
  722. }
  723. }, # ticket selector to get only a collection of tickets
  724. params: {
  725. type: 'in',
  726. },
  727. )
  728. assert(result)
  729. assert_equal(0, result[0])
  730. assert_equal(0, result[1])
  731. assert_equal(0, result[2])
  732. assert_equal(0, result[3])
  733. assert_equal(0, result[4])
  734. assert_equal(0, result[5])
  735. assert_equal(0, result[6])
  736. assert_equal(0, result[7])
  737. assert_equal(0, result[8])
  738. assert_equal(0, result[9])
  739. assert_equal(0, result[10])
  740. assert_equal(0, result[11])
  741. assert_nil(result[12])
  742. result = Report::TicketMoved.items(
  743. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  744. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  745. selector: {
  746. 'ticket.group_id' => {
  747. 'operator' => 'is',
  748. 'value' => [Group.lookup(name: 'Users').id],
  749. }
  750. }, # ticket selector to get only a collection of tickets
  751. params: {
  752. type: 'in',
  753. },
  754. )
  755. assert(result)
  756. assert_equal(@ticket1.id, result[:ticket_ids][0])
  757. assert_nil(result[:ticket_ids][1])
  758. # move in/out
  759. result = Report::TicketMoved.aggs(
  760. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  761. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  762. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  763. selector: {
  764. 'ticket.group_id' => {
  765. 'operator' => 'is',
  766. 'value' => [Group.lookup(name: 'Users').id],
  767. }
  768. }, # ticket selector to get only a collection of tickets
  769. params: {
  770. type: 'in',
  771. },
  772. )
  773. assert(result)
  774. assert_equal(0, result[0])
  775. assert_equal(0, result[1])
  776. assert_equal(0, result[2])
  777. assert_equal(0, result[3])
  778. assert_equal(0, result[4])
  779. assert_equal(0, result[5])
  780. assert_equal(0, result[6])
  781. assert_equal(0, result[7])
  782. assert_equal(0, result[8])
  783. assert_equal(1, result[9])
  784. assert_equal(0, result[10])
  785. assert_equal(0, result[11])
  786. assert_nil(result[12])
  787. result = Report::TicketMoved.items(
  788. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  789. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  790. selector: {
  791. 'ticket.group_id' => {
  792. 'operator' => 'is',
  793. 'value' => [Group.lookup(name: 'Users').id],
  794. }
  795. }, # ticket selector to get only a collection of tickets
  796. params: {
  797. type: 'in',
  798. },
  799. )
  800. assert(result)
  801. assert_equal(@ticket1.id, result[:ticket_ids][0])
  802. assert_nil(result[:ticket_ids][1])
  803. # out without merged tickets
  804. result = Report::TicketMoved.aggs(
  805. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  806. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  807. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  808. selector: {
  809. 'ticket_state.name' => {
  810. 'operator' => 'is not',
  811. 'value' => 'merged',
  812. }
  813. }, # ticket selector to get only a collection of tickets
  814. params: {
  815. type: 'out',
  816. },
  817. )
  818. assert(result)
  819. assert_equal(0, result[0])
  820. assert_equal(0, result[1])
  821. assert_equal(0, result[2])
  822. assert_equal(0, result[3])
  823. assert_equal(0, result[4])
  824. assert_equal(0, result[5])
  825. assert_equal(0, result[6])
  826. assert_equal(0, result[7])
  827. assert_equal(0, result[8])
  828. assert_equal(0, result[9])
  829. assert_equal(0, result[10])
  830. assert_equal(0, result[11])
  831. assert_nil(result[12])
  832. result = Report::TicketMoved.items(
  833. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  834. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  835. selector: {
  836. 'ticket_state.name' => {
  837. 'operator' => 'is not',
  838. 'value' => 'merged',
  839. }
  840. }, # ticket selector to get only a collection of tickets
  841. params: {
  842. type: 'out',
  843. },
  844. )
  845. assert(result)
  846. assert_nil(result[:ticket_ids][0])
  847. # out
  848. result = Report::TicketMoved.aggs(
  849. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  850. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  851. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  852. selector: {
  853. 'ticket.group_id' => {
  854. 'operator' => 'is',
  855. 'value' => [Group.lookup(name: 'Users').id],
  856. }
  857. }, # ticket selector to get only a collection of tickets
  858. params: {
  859. type: 'out',
  860. },
  861. )
  862. assert(result)
  863. assert_equal(0, result[0])
  864. assert_equal(0, result[1])
  865. assert_equal(0, result[2])
  866. assert_equal(0, result[3])
  867. assert_equal(0, result[4])
  868. assert_equal(0, result[5])
  869. assert_equal(0, result[6])
  870. assert_equal(0, result[7])
  871. assert_equal(0, result[8])
  872. assert_equal(1, result[9])
  873. assert_equal(0, result[10])
  874. assert_equal(0, result[11])
  875. assert_nil(result[12])
  876. result = Report::TicketMoved.items(
  877. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  878. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  879. selector: {
  880. 'ticket.group_id' => {
  881. 'operator' => 'is',
  882. 'value' => [Group.lookup(name: 'Users').id],
  883. }
  884. }, # ticket selector to get only a collection of tickets
  885. params: {
  886. type: 'out',
  887. },
  888. )
  889. assert(result)
  890. assert_equal(@ticket2.id, result[:ticket_ids][0])
  891. assert_nil(result[:ticket_ids][1])
  892. # create at
  893. result = Report::TicketGenericTime.aggs(
  894. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  895. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  896. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  897. selector: {}, # ticket selector to get only a collection of tickets
  898. params: { field: 'created_at' },
  899. )
  900. assert(result)
  901. assert_equal(0, result[0])
  902. assert_equal(0, result[1])
  903. assert_equal(0, result[2])
  904. assert_equal(0, result[3])
  905. assert_equal(0, result[4])
  906. assert_equal(0, result[5])
  907. assert_equal(0, result[6])
  908. assert_equal(0, result[7])
  909. assert_equal(0, result[8])
  910. assert_equal(6, result[9])
  911. assert_equal(1, result[10])
  912. assert_equal(0, result[11])
  913. assert_nil(result[12])
  914. result = Report::TicketGenericTime.items(
  915. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  916. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  917. selector: {}, # ticket selector to get only a collection of tickets
  918. params: { field: 'created_at' },
  919. )
  920. assert(result)
  921. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  922. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  923. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  924. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  925. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  926. assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
  927. assert_equal(@ticket1.id, result[:ticket_ids][6].to_i)
  928. assert_nil(result[:ticket_ids][7])
  929. # create at - selector with merge
  930. result = Report::TicketGenericTime.aggs(
  931. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  932. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  933. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  934. selector: {
  935. 'state' => {
  936. 'operator' => 'is not',
  937. 'value' => 'merged'
  938. }
  939. }, # ticket selector to get only a collection of tickets
  940. params: { field: 'created_at' },
  941. )
  942. assert(result)
  943. assert_equal(0, result[0])
  944. assert_equal(0, result[1])
  945. assert_equal(0, result[2])
  946. assert_equal(0, result[3])
  947. assert_equal(0, result[4])
  948. assert_equal(0, result[5])
  949. assert_equal(0, result[6])
  950. assert_equal(0, result[7])
  951. assert_equal(0, result[8])
  952. assert_equal(6, result[9])
  953. assert_equal(1, result[10])
  954. assert_equal(0, result[11])
  955. assert_nil(result[12])
  956. result = Report::TicketGenericTime.items(
  957. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  958. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  959. selector: {
  960. 'state' => {
  961. 'operator' => 'is not',
  962. 'value' => 'merged'
  963. }
  964. }, # ticket selector to get only a collection of tickets
  965. params: { field: 'created_at' },
  966. )
  967. assert(result)
  968. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  969. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  970. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  971. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  972. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  973. assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
  974. assert_equal(@ticket1.id, result[:ticket_ids][6].to_i)
  975. assert_nil(result[:ticket_ids][7])
  976. result = Report::TicketGenericTime.items(
  977. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  978. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  979. selector: {
  980. 'created_at' => {
  981. 'operator' => 'before (absolute)',
  982. 'value' => '2015-10-31T00:00:00Z'
  983. }
  984. }, # ticket selector to get only a collection of tickets
  985. params: { field: 'created_at' },
  986. )
  987. assert(result)
  988. assert_equal(@ticket5.id, result[:ticket_ids][0].to_i)
  989. assert_equal(@ticket4.id, result[:ticket_ids][1].to_i)
  990. assert_equal(@ticket3.id, result[:ticket_ids][2].to_i)
  991. assert_equal(@ticket2.id, result[:ticket_ids][3].to_i)
  992. assert_equal(@ticket1.id, result[:ticket_ids][4].to_i)
  993. assert_nil(result[:ticket_ids][5])
  994. result = Report::TicketGenericTime.items(
  995. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  996. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  997. selector: {
  998. 'created_at' => {
  999. 'operator' => 'after (absolute)',
  1000. 'value' => '2015-10-31T00:00:00Z'
  1001. }
  1002. }, # ticket selector to get only a collection of tickets
  1003. params: { field: 'created_at' },
  1004. )
  1005. assert(result)
  1006. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1007. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1008. assert_nil(result[:ticket_ids][2])
  1009. Report::TicketGenericTime.items(
  1010. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1011. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1012. selector: {
  1013. 'created_at' => {
  1014. 'operator' => 'before (relative)',
  1015. 'range' => 'day',
  1016. 'value' => '1'
  1017. }
  1018. }, # ticket selector to get only a collection of tickets
  1019. params: { field: 'created_at' },
  1020. )
  1021. result = Report::TicketGenericTime.items(
  1022. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1023. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1024. selector: {
  1025. 'created_at' => {
  1026. 'operator' => 'after (relative)',
  1027. 'range' => 'day',
  1028. 'value' => '1'
  1029. }
  1030. }, # ticket selector to get only a collection of tickets
  1031. params: { field: 'created_at' },
  1032. )
  1033. assert(result)
  1034. assert_nil(result[:ticket_ids][0])
  1035. result = Report::TicketGenericTime.items(
  1036. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1037. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1038. selector: {
  1039. 'created_at' => {
  1040. 'operator' => 'before (relative)',
  1041. 'range' => 'day',
  1042. 'value' => '1'
  1043. }
  1044. }, # ticket selector to get only a collection of tickets
  1045. params: { field: 'created_at' },
  1046. )
  1047. assert(result)
  1048. assert_nil(result[:ticket_ids][0])
  1049. result = Report::TicketGenericTime.items(
  1050. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1051. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1052. selector: {
  1053. 'created_at' => {
  1054. 'operator' => 'after (relative)',
  1055. 'range' => 'day',
  1056. 'value' => '5'
  1057. }
  1058. }, # ticket selector to get only a collection of tickets
  1059. params: { field: 'created_at' },
  1060. )
  1061. assert(result)
  1062. assert_equal(@ticket9.id, result[:ticket_ids][0].to_i)
  1063. assert_nil(result[:ticket_ids][1])
  1064. result = Report::TicketGenericTime.items(
  1065. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1066. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1067. selector: {
  1068. 'created_at' => {
  1069. 'operator' => 'before (relative)',
  1070. 'range' => 'month',
  1071. 'value' => '1'
  1072. }
  1073. }, # ticket selector to get only a collection of tickets
  1074. params: { field: 'created_at' },
  1075. )
  1076. assert(result)
  1077. assert_nil(result[:ticket_ids][0])
  1078. result = Report::TicketGenericTime.items(
  1079. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1080. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1081. selector: {
  1082. 'created_at' => {
  1083. 'operator' => 'after (relative)',
  1084. 'range' => 'month',
  1085. 'value' => '5'
  1086. }
  1087. }, # ticket selector to get only a collection of tickets
  1088. params: { field: 'created_at' },
  1089. )
  1090. assert(result)
  1091. assert_equal(@ticket9.id, result[:ticket_ids][0].to_i)
  1092. assert_nil(result[:ticket_ids][1])
  1093. result = Report::TicketGenericTime.items(
  1094. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1095. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1096. selector: {
  1097. 'created_at' => {
  1098. 'operator' => 'before (relative)',
  1099. 'range' => 'year',
  1100. 'value' => '1'
  1101. }
  1102. }, # ticket selector to get only a collection of tickets
  1103. params: { field: 'created_at' },
  1104. )
  1105. assert(result)
  1106. assert_nil(result[:ticket_ids][0])
  1107. result = Report::TicketGenericTime.items(
  1108. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1109. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1110. selector: {
  1111. 'created_at' => {
  1112. 'operator' => 'after (relative)',
  1113. 'range' => 'year',
  1114. 'value' => '5'
  1115. }
  1116. }, # ticket selector to get only a collection of tickets
  1117. params: { field: 'created_at' },
  1118. )
  1119. assert(result)
  1120. assert_equal(@ticket9.id, result[:ticket_ids][0].to_i)
  1121. assert_nil(result[:ticket_ids][1])
  1122. result = Report::TicketGenericTime.items(
  1123. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1124. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1125. selector: {
  1126. 'tags' => {
  1127. 'operator' => 'contains all',
  1128. 'value' => 'aaa, bbb'
  1129. }
  1130. }, # ticket selector to get only a collection of tickets
  1131. params: { field: 'created_at' },
  1132. )
  1133. assert(result)
  1134. assert_equal(@ticket1.id, result[:ticket_ids][0].to_i)
  1135. assert_nil(result[:ticket_ids][1])
  1136. result = Report::TicketGenericTime.items(
  1137. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1138. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1139. selector: {
  1140. 'tags' => {
  1141. 'operator' => 'contains all not',
  1142. 'value' => 'aaa, bbb'
  1143. }
  1144. }, # ticket selector to get only a collection of tickets
  1145. params: { field: 'created_at' },
  1146. )
  1147. assert(result)
  1148. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1149. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1150. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  1151. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  1152. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  1153. assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
  1154. assert_nil(result[:ticket_ids][6])
  1155. result = Report::TicketGenericTime.items(
  1156. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1157. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1158. selector: {
  1159. 'tags' => {
  1160. 'operator' => 'contains all',
  1161. 'value' => 'aaa'
  1162. }
  1163. }, # ticket selector to get only a collection of tickets
  1164. params: { field: 'created_at' },
  1165. )
  1166. assert(result)
  1167. assert_equal(@ticket2.id, result[:ticket_ids][0].to_i)
  1168. assert_equal(@ticket1.id, result[:ticket_ids][1].to_i)
  1169. assert_nil(result[:ticket_ids][2])
  1170. result = Report::TicketGenericTime.items(
  1171. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1172. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1173. selector: {
  1174. 'tags' => {
  1175. 'operator' => 'contains all not',
  1176. 'value' => 'aaa'
  1177. }
  1178. }, # ticket selector to get only a collection of tickets
  1179. params: { field: 'created_at' },
  1180. )
  1181. assert(result)
  1182. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1183. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1184. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  1185. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  1186. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  1187. assert_nil(result[:ticket_ids][5])
  1188. result = Report::TicketGenericTime.items(
  1189. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1190. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1191. selector: {
  1192. 'tags' => {
  1193. 'operator' => 'contains one not',
  1194. 'value' => 'aaa'
  1195. }
  1196. }, # ticket selector to get only a collection of tickets
  1197. params: { field: 'created_at' },
  1198. )
  1199. assert(result)
  1200. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1201. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1202. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  1203. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  1204. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  1205. assert_nil(result[:ticket_ids][5])
  1206. result = Report::TicketGenericTime.items(
  1207. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1208. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1209. selector: {
  1210. 'tags' => {
  1211. 'operator' => 'contains one not',
  1212. 'value' => 'aaa, bbb'
  1213. }
  1214. }, # ticket selector to get only a collection of tickets
  1215. params: { field: 'created_at' },
  1216. )
  1217. assert(result)
  1218. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1219. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1220. assert_equal(@ticket4.id, result[:ticket_ids][2].to_i)
  1221. assert_equal(@ticket3.id, result[:ticket_ids][3].to_i)
  1222. assert_nil(result[:ticket_ids][4])
  1223. result = Report::TicketGenericTime.items(
  1224. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1225. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1226. selector: {
  1227. 'tags' => {
  1228. 'operator' => 'contains one',
  1229. 'value' => 'aaa'
  1230. }
  1231. }, # ticket selector to get only a collection of tickets
  1232. params: { field: 'created_at' },
  1233. )
  1234. assert(result)
  1235. assert_equal(@ticket2.id, result[:ticket_ids][0].to_i)
  1236. assert_equal(@ticket1.id, result[:ticket_ids][1].to_i)
  1237. assert_nil(result[:ticket_ids][2])
  1238. result = Report::TicketGenericTime.items(
  1239. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1240. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1241. selector: {
  1242. 'tags' => {
  1243. 'operator' => 'contains one',
  1244. 'value' => 'aaa, bbb'
  1245. }
  1246. }, # ticket selector to get only a collection of tickets
  1247. params: { field: 'created_at' },
  1248. )
  1249. assert(result)
  1250. assert_equal(@ticket5.id, result[:ticket_ids][0].to_i)
  1251. assert_equal(@ticket2.id, result[:ticket_ids][1].to_i)
  1252. assert_equal(@ticket1.id, result[:ticket_ids][2].to_i)
  1253. assert_nil(result[:ticket_ids][3])
  1254. result = Report::TicketGenericTime.items(
  1255. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1256. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1257. selector: {
  1258. 'title' => {
  1259. 'operator' => 'contains',
  1260. 'value' => 'test'
  1261. }
  1262. }, # ticket selector to get only a collection of tickets
  1263. params: { field: 'created_at' },
  1264. )
  1265. assert(result)
  1266. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1267. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1268. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  1269. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  1270. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  1271. assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
  1272. assert_equal(@ticket1.id, result[:ticket_ids][6].to_i)
  1273. assert_nil(result[:ticket_ids][7])
  1274. result = Report::TicketGenericTime.items(
  1275. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1276. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1277. selector: {
  1278. 'title' => {
  1279. 'operator' => 'contains not',
  1280. 'value' => 'test'
  1281. }
  1282. }, # ticket selector to get only a collection of tickets
  1283. params: { field: 'created_at' },
  1284. )
  1285. assert(result)
  1286. assert_nil(result[:ticket_ids][0])
  1287. # search for test_category.keyword to find values with :: in query
  1288. result = Report::TicketGenericTime.items(
  1289. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1290. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1291. selector: {
  1292. 'test_category' => {
  1293. 'operator' => 'is',
  1294. 'value' => 'cc::bb'
  1295. },
  1296. }, # ticket selector to get only a collection of tickets
  1297. params: { field: 'created_at' },
  1298. )
  1299. assert(result)
  1300. assert_equal(@ticket1.id, result[:ticket_ids][0].to_i)
  1301. assert_nil(result[:ticket_ids][1])
  1302. end
  1303. end