report_test.rb 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  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. SearchIndexBackend.refresh
  299. end
  300. test 'compare' do
  301. # first solution
  302. result = Report::TicketFirstSolution.aggs(
  303. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  304. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  305. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  306. selector: {}, # ticket selector to get only a collection of tickets
  307. )
  308. assert(result)
  309. assert_equal(0, result[0])
  310. assert_equal(0, result[1])
  311. assert_equal(0, result[2])
  312. assert_equal(0, result[3])
  313. assert_equal(0, result[4])
  314. assert_equal(0, result[5])
  315. assert_equal(0, result[6])
  316. assert_equal(0, result[7])
  317. assert_equal(0, result[8])
  318. assert_equal(2, result[9])
  319. assert_equal(1, result[10])
  320. assert_equal(0, result[11])
  321. assert_nil(result[12])
  322. result = Report::TicketFirstSolution.items(
  323. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  324. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  325. selector: {}, # ticket selector to get only a collection of tickets
  326. )
  327. assert(result)
  328. assert_equal(@ticket5.id, result[:ticket_ids][0])
  329. assert_equal(@ticket6.id, result[:ticket_ids][1])
  330. assert_equal(@ticket7.id, result[:ticket_ids][2])
  331. assert_nil(result[:ticket_ids][3])
  332. # month - with selector #1
  333. result = Report::TicketFirstSolution.aggs(
  334. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  335. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  336. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  337. selector: {
  338. 'ticket.priority_id' => {
  339. 'operator' => 'is',
  340. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  341. }
  342. }, # ticket selector to get only a collection of tickets
  343. )
  344. assert(result)
  345. assert_equal(0, result[0])
  346. assert_equal(0, result[1])
  347. assert_equal(0, result[2])
  348. assert_equal(0, result[3])
  349. assert_equal(0, result[4])
  350. assert_equal(0, result[5])
  351. assert_equal(0, result[6])
  352. assert_equal(0, result[7])
  353. assert_equal(0, result[8])
  354. assert_equal(1, result[9])
  355. assert_equal(0, result[10])
  356. assert_equal(0, result[11])
  357. assert_nil(result[12])
  358. result = Report::TicketFirstSolution.items(
  359. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  360. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  361. selector: {
  362. 'ticket.priority_id' => {
  363. 'operator' => 'is',
  364. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  365. }
  366. }, # ticket selector to get only a collection of tickets
  367. )
  368. assert(result)
  369. assert_equal(@ticket5.id, result[:ticket_ids][0])
  370. assert_nil(result[:ticket_ids][1])
  371. # month - with merged tickets selector
  372. result = Report::TicketFirstSolution.aggs(
  373. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  374. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  375. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  376. selector: {
  377. 'ticket_state.name' => {
  378. 'operator' => 'is not',
  379. 'value' => 'merged',
  380. }
  381. }, # ticket selector to get only a collection of tickets
  382. )
  383. assert(result)
  384. assert_equal(0, result[0])
  385. assert_equal(0, result[1])
  386. assert_equal(0, result[2])
  387. assert_equal(0, result[3])
  388. assert_equal(0, result[4])
  389. assert_equal(0, result[5])
  390. assert_equal(0, result[6])
  391. assert_equal(0, result[7])
  392. assert_equal(0, result[8])
  393. assert_equal(2, result[9])
  394. assert_equal(1, result[10])
  395. assert_equal(0, result[11])
  396. assert_nil(result[12])
  397. result = Report::TicketFirstSolution.items(
  398. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  399. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  400. selector: {
  401. 'ticket_state.name' => {
  402. 'operator' => 'is not',
  403. 'value' => 'merged',
  404. }
  405. }, # ticket selector to get only a collection of tickets
  406. )
  407. assert(result)
  408. assert_equal(@ticket5.id, result[:ticket_ids][0])
  409. assert_nil(result[:ticket_ids][3])
  410. # month - with selector #2
  411. result = Report::TicketFirstSolution.aggs(
  412. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  413. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  414. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  415. selector: {
  416. 'ticket.priority_id' => {
  417. 'operator' => 'is not',
  418. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  419. }
  420. }, # ticket selector to get only a collection of tickets
  421. )
  422. assert(result)
  423. assert_equal(0, result[0])
  424. assert_equal(0, result[1])
  425. assert_equal(0, result[2])
  426. assert_equal(0, result[3])
  427. assert_equal(0, result[4])
  428. assert_equal(0, result[5])
  429. assert_equal(0, result[6])
  430. assert_equal(0, result[7])
  431. assert_equal(0, result[8])
  432. assert_equal(1, result[9])
  433. assert_equal(1, result[10])
  434. assert_equal(0, result[11])
  435. assert_nil(result[12])
  436. result = Report::TicketFirstSolution.items(
  437. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  438. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  439. selector: {
  440. 'ticket.priority_id' => {
  441. 'operator' => 'is not',
  442. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  443. }
  444. }, # ticket selector to get only a collection of tickets
  445. )
  446. assert(result)
  447. assert_equal(@ticket6.id, result[:ticket_ids][0])
  448. assert_equal(@ticket7.id, result[:ticket_ids][1])
  449. assert_nil(result[:ticket_ids][2])
  450. # week
  451. result = Report::TicketFirstSolution.aggs(
  452. range_start: Time.zone.parse('2015-10-26T00:00:00Z'),
  453. range_end: Time.zone.parse('2015-10-31T23:59:59Z'),
  454. interval: 'week', # year, quarter, month, week, day, hour, minute, second
  455. selector: {}, # ticket selector to get only a collection of tickets
  456. )
  457. assert(result)
  458. assert_equal(0, result[0])
  459. assert_equal(0, result[1])
  460. assert_equal(1, result[2])
  461. assert_equal(0, result[3])
  462. assert_equal(0, result[4])
  463. assert_equal(1, result[5])
  464. assert_equal(1, result[6])
  465. assert_nil(result[7])
  466. result = Report::TicketFirstSolution.items(
  467. range_start: Time.zone.parse('2015-10-26T00:00:00Z'),
  468. range_end: Time.zone.parse('2015-11-01T23:59:59Z'),
  469. interval: 'week', # year, quarter, month, week, day, hour, minute, second
  470. selector: {}, # ticket selector to get only a collection of tickets
  471. )
  472. assert(result)
  473. assert_equal(@ticket5.id, result[:ticket_ids][0])
  474. assert_equal(@ticket6.id, result[:ticket_ids][1])
  475. assert_equal(@ticket7.id, result[:ticket_ids][2])
  476. assert_nil(result[:ticket_ids][3])
  477. # day
  478. result = Report::TicketFirstSolution.aggs(
  479. range_start: Time.zone.parse('2015-10-01T00:00:00Z'),
  480. range_end: Time.zone.parse('2015-11-01T23:59:59Z'),
  481. interval: 'day', # year, quarter, month, week, day, hour, minute, second
  482. selector: {}, # ticket selector to get only a collection of tickets
  483. )
  484. assert(result)
  485. assert_equal(0, result[0])
  486. assert_equal(0, result[1])
  487. assert_equal(0, result[2])
  488. assert_equal(0, result[3])
  489. assert_equal(0, result[4])
  490. assert_equal(0, result[5])
  491. assert_equal(0, result[6])
  492. assert_equal(0, result[7])
  493. assert_equal(0, result[8])
  494. assert_equal(0, result[9])
  495. assert_equal(0, result[10])
  496. assert_equal(0, result[11])
  497. assert_equal(0, result[12])
  498. assert_equal(0, result[13])
  499. assert_equal(0, result[14])
  500. assert_equal(0, result[15])
  501. assert_equal(0, result[16])
  502. assert_equal(0, result[17])
  503. assert_equal(0, result[18])
  504. assert_equal(0, result[19])
  505. assert_equal(0, result[20])
  506. assert_equal(0, result[21])
  507. assert_equal(0, result[22])
  508. assert_equal(0, result[23])
  509. assert_equal(0, result[24])
  510. assert_equal(0, result[25])
  511. assert_equal(0, result[26])
  512. assert_equal(1, result[27])
  513. assert_equal(0, result[28])
  514. assert_equal(0, result[29])
  515. assert_equal(1, result[30])
  516. assert_nil(result[31])
  517. result = Report::TicketFirstSolution.items(
  518. range_start: Time.zone.parse('2015-10-01T00:00:00Z'),
  519. range_end: Time.zone.parse('2015-10-31T23:59:59Z'),
  520. interval: 'day', # year, quarter, month, week, day, hour, minute, second
  521. selector: {}, # ticket selector to get only a collection of tickets
  522. )
  523. assert(result)
  524. assert_equal(@ticket5.id, result[:ticket_ids][0])
  525. assert_equal(@ticket6.id, result[:ticket_ids][1])
  526. assert_nil(result[:ticket_ids][2])
  527. # hour
  528. result = Report::TicketFirstSolution.aggs(
  529. range_start: Time.zone.parse('2015-10-28T00:00:00Z'),
  530. range_end: Time.zone.parse('2015-10-28T23:59:59Z'),
  531. interval: 'hour', # year, quarter, month, week, day, hour, minute, second
  532. selector: {}, # ticket selector to get only a collection of tickets
  533. )
  534. assert(result)
  535. assert_equal(0, result[0])
  536. assert_equal(0, result[1])
  537. assert_equal(0, result[2])
  538. assert_equal(0, result[3])
  539. assert_equal(0, result[4])
  540. assert_equal(0, result[5])
  541. assert_equal(0, result[6])
  542. assert_equal(0, result[7])
  543. assert_equal(0, result[8])
  544. assert_equal(0, result[9])
  545. assert_equal(0, result[10])
  546. assert_equal(1, result[11])
  547. assert_equal(0, result[12])
  548. assert_equal(0, result[13])
  549. assert_equal(0, result[14])
  550. assert_equal(0, result[15])
  551. assert_equal(0, result[16])
  552. assert_equal(0, result[17])
  553. assert_equal(0, result[18])
  554. assert_equal(0, result[19])
  555. assert_equal(0, result[20])
  556. assert_equal(0, result[21])
  557. assert_equal(0, result[22])
  558. assert_equal(0, result[23])
  559. assert_nil(result[24])
  560. result = Report::TicketFirstSolution.items(
  561. range_start: Time.zone.parse('2015-10-28T00:00:00Z'),
  562. range_end: Time.zone.parse('2015-10-28T23:59:59Z'),
  563. interval: 'hour', # year, quarter, month, week, day, hour, minute, second
  564. selector: {}, # ticket selector to get only a collection of tickets
  565. )
  566. assert(result)
  567. assert_equal(@ticket5.id, result[:ticket_ids][0])
  568. assert_nil(result[:ticket_ids][1])
  569. # reopen
  570. result = Report::TicketReopened.aggs(
  571. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  572. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  573. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  574. selector: {}, # ticket selector to get only a collection of tickets
  575. )
  576. assert(result)
  577. assert_equal(0, result[0])
  578. assert_equal(0, result[1])
  579. assert_equal(0, result[2])
  580. assert_equal(0, result[3])
  581. assert_equal(0, result[4])
  582. assert_equal(0, result[5])
  583. assert_equal(0, result[6])
  584. assert_equal(0, result[7])
  585. assert_equal(0, result[8])
  586. assert_equal(1, result[9])
  587. assert_equal(0, result[10])
  588. assert_equal(0, result[11])
  589. assert_nil(result[12])
  590. result = Report::TicketReopened.items(
  591. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  592. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  593. selector: {}, # ticket selector to get only a collection of tickets
  594. )
  595. assert(result)
  596. assert_equal(@ticket5.id, result[:ticket_ids][0])
  597. assert_nil(result[:ticket_ids][1])
  598. # month - with selector #1
  599. result = Report::TicketReopened.aggs(
  600. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  601. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  602. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  603. selector: {
  604. 'ticket.priority_id' => {
  605. 'operator' => 'is',
  606. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  607. }
  608. }, # ticket selector to get only a collection of tickets
  609. )
  610. assert(result)
  611. assert_equal(0, result[0])
  612. assert_equal(0, result[1])
  613. assert_equal(0, result[2])
  614. assert_equal(0, result[3])
  615. assert_equal(0, result[4])
  616. assert_equal(0, result[5])
  617. assert_equal(0, result[6])
  618. assert_equal(0, result[7])
  619. assert_equal(0, result[8])
  620. assert_equal(1, result[9])
  621. assert_equal(0, result[10])
  622. assert_equal(0, result[11])
  623. assert_nil(result[12])
  624. result = Report::TicketReopened.items(
  625. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  626. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  627. selector: {
  628. 'ticket.priority_id' => {
  629. 'operator' => 'is',
  630. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  631. }
  632. }, # ticket selector to get only a collection of tickets
  633. )
  634. assert(result)
  635. assert_equal(@ticket5.id, result[:ticket_ids][0])
  636. assert_nil(result[:ticket_ids][1])
  637. # month - with selector #2
  638. result = Report::TicketReopened.aggs(
  639. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  640. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  641. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  642. selector: {
  643. 'ticket.priority_id' => {
  644. 'operator' => 'is not',
  645. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  646. }
  647. }, # ticket selector to get only a collection of tickets
  648. )
  649. assert(result)
  650. assert_equal(0, result[0])
  651. assert_equal(0, result[1])
  652. assert_equal(0, result[2])
  653. assert_equal(0, result[3])
  654. assert_equal(0, result[4])
  655. assert_equal(0, result[5])
  656. assert_equal(0, result[6])
  657. assert_equal(0, result[7])
  658. assert_equal(0, result[8])
  659. assert_equal(0, result[9])
  660. assert_equal(0, result[10])
  661. assert_equal(0, result[11])
  662. assert_nil(result[12])
  663. result = Report::TicketReopened.items(
  664. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  665. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  666. selector: {
  667. 'ticket.priority_id' => {
  668. 'operator' => 'is not',
  669. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  670. }
  671. }, # ticket selector to get only a collection of tickets
  672. )
  673. assert(result)
  674. assert_nil(result[:ticket_ids][0])
  675. # month - reopened with merge selector
  676. result = Report::TicketReopened.aggs(
  677. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  678. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  679. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  680. selector: {
  681. 'ticket_state.name' => {
  682. 'operator' => 'is not',
  683. 'value' => 'merged',
  684. }
  685. }, # ticket selector to get only a collection of tickets
  686. )
  687. assert(result)
  688. assert_equal(0, result[0])
  689. assert_equal(0, result[1])
  690. assert_equal(0, result[2])
  691. assert_equal(0, result[3])
  692. assert_equal(0, result[4])
  693. assert_equal(0, result[5])
  694. assert_equal(0, result[6])
  695. assert_equal(0, result[7])
  696. assert_equal(0, result[8])
  697. assert_equal(1, result[9])
  698. assert_equal(0, result[10])
  699. assert_equal(0, result[11])
  700. assert_nil(result[12])
  701. result = Report::TicketReopened.items(
  702. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  703. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  704. selector: {
  705. 'ticket_state.name' => {
  706. 'operator' => 'is not',
  707. 'value' => 'merged',
  708. }
  709. }, # ticket selector to get only a collection of tickets
  710. )
  711. assert(result)
  712. assert_equal(@ticket5.id, result[:ticket_ids][0])
  713. assert_nil(result[:ticket_ids][1])
  714. # move in/out without merged status
  715. result = Report::TicketMoved.aggs(
  716. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  717. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  718. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  719. selector: {
  720. 'ticket_state.name' => {
  721. 'operator' => 'is not',
  722. 'value' => 'merged',
  723. }
  724. }, # ticket selector to get only a collection of tickets
  725. params: {
  726. type: 'in',
  727. },
  728. )
  729. assert(result)
  730. assert_equal(0, result[0])
  731. assert_equal(0, result[1])
  732. assert_equal(0, result[2])
  733. assert_equal(0, result[3])
  734. assert_equal(0, result[4])
  735. assert_equal(0, result[5])
  736. assert_equal(0, result[6])
  737. assert_equal(0, result[7])
  738. assert_equal(0, result[8])
  739. assert_equal(0, result[9])
  740. assert_equal(0, result[10])
  741. assert_equal(0, result[11])
  742. assert_nil(result[12])
  743. result = Report::TicketMoved.items(
  744. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  745. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  746. selector: {
  747. 'ticket.group_id' => {
  748. 'operator' => 'is',
  749. 'value' => [Group.lookup(name: 'Users').id],
  750. }
  751. }, # ticket selector to get only a collection of tickets
  752. params: {
  753. type: 'in',
  754. },
  755. )
  756. assert(result)
  757. assert_equal(@ticket1.id, result[:ticket_ids][0])
  758. assert_nil(result[:ticket_ids][1])
  759. # move in/out
  760. result = Report::TicketMoved.aggs(
  761. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  762. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  763. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  764. selector: {
  765. 'ticket.group_id' => {
  766. 'operator' => 'is',
  767. 'value' => [Group.lookup(name: 'Users').id],
  768. }
  769. }, # ticket selector to get only a collection of tickets
  770. params: {
  771. type: 'in',
  772. },
  773. )
  774. assert(result)
  775. assert_equal(0, result[0])
  776. assert_equal(0, result[1])
  777. assert_equal(0, result[2])
  778. assert_equal(0, result[3])
  779. assert_equal(0, result[4])
  780. assert_equal(0, result[5])
  781. assert_equal(0, result[6])
  782. assert_equal(0, result[7])
  783. assert_equal(0, result[8])
  784. assert_equal(1, result[9])
  785. assert_equal(0, result[10])
  786. assert_equal(0, result[11])
  787. assert_nil(result[12])
  788. result = Report::TicketMoved.items(
  789. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  790. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  791. selector: {
  792. 'ticket.group_id' => {
  793. 'operator' => 'is',
  794. 'value' => [Group.lookup(name: 'Users').id],
  795. }
  796. }, # ticket selector to get only a collection of tickets
  797. params: {
  798. type: 'in',
  799. },
  800. )
  801. assert(result)
  802. assert_equal(@ticket1.id, result[:ticket_ids][0])
  803. assert_nil(result[:ticket_ids][1])
  804. # out without merged tickets
  805. result = Report::TicketMoved.aggs(
  806. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  807. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  808. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  809. selector: {
  810. 'ticket_state.name' => {
  811. 'operator' => 'is not',
  812. 'value' => 'merged',
  813. }
  814. }, # ticket selector to get only a collection of tickets
  815. params: {
  816. type: 'out',
  817. },
  818. )
  819. assert(result)
  820. assert_equal(0, result[0])
  821. assert_equal(0, result[1])
  822. assert_equal(0, result[2])
  823. assert_equal(0, result[3])
  824. assert_equal(0, result[4])
  825. assert_equal(0, result[5])
  826. assert_equal(0, result[6])
  827. assert_equal(0, result[7])
  828. assert_equal(0, result[8])
  829. assert_equal(0, result[9])
  830. assert_equal(0, result[10])
  831. assert_equal(0, result[11])
  832. assert_nil(result[12])
  833. result = Report::TicketMoved.items(
  834. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  835. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  836. selector: {
  837. 'ticket_state.name' => {
  838. 'operator' => 'is not',
  839. 'value' => 'merged',
  840. }
  841. }, # ticket selector to get only a collection of tickets
  842. params: {
  843. type: 'out',
  844. },
  845. )
  846. assert(result)
  847. assert_nil(result[:ticket_ids][0])
  848. # out
  849. result = Report::TicketMoved.aggs(
  850. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  851. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  852. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  853. selector: {
  854. 'ticket.group_id' => {
  855. 'operator' => 'is',
  856. 'value' => [Group.lookup(name: 'Users').id],
  857. }
  858. }, # ticket selector to get only a collection of tickets
  859. params: {
  860. type: 'out',
  861. },
  862. )
  863. assert(result)
  864. assert_equal(0, result[0])
  865. assert_equal(0, result[1])
  866. assert_equal(0, result[2])
  867. assert_equal(0, result[3])
  868. assert_equal(0, result[4])
  869. assert_equal(0, result[5])
  870. assert_equal(0, result[6])
  871. assert_equal(0, result[7])
  872. assert_equal(0, result[8])
  873. assert_equal(1, result[9])
  874. assert_equal(0, result[10])
  875. assert_equal(0, result[11])
  876. assert_nil(result[12])
  877. result = Report::TicketMoved.items(
  878. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  879. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  880. selector: {
  881. 'ticket.group_id' => {
  882. 'operator' => 'is',
  883. 'value' => [Group.lookup(name: 'Users').id],
  884. }
  885. }, # ticket selector to get only a collection of tickets
  886. params: {
  887. type: 'out',
  888. },
  889. )
  890. assert(result)
  891. assert_equal(@ticket2.id, result[:ticket_ids][0])
  892. assert_nil(result[:ticket_ids][1])
  893. # create at
  894. result = Report::TicketGenericTime.aggs(
  895. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  896. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  897. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  898. selector: {}, # ticket selector to get only a collection of tickets
  899. params: { field: 'created_at' },
  900. )
  901. assert(result)
  902. assert_equal(0, result[0])
  903. assert_equal(0, result[1])
  904. assert_equal(0, result[2])
  905. assert_equal(0, result[3])
  906. assert_equal(0, result[4])
  907. assert_equal(0, result[5])
  908. assert_equal(0, result[6])
  909. assert_equal(0, result[7])
  910. assert_equal(0, result[8])
  911. assert_equal(6, result[9])
  912. assert_equal(1, result[10])
  913. assert_equal(0, result[11])
  914. assert_nil(result[12])
  915. result = Report::TicketGenericTime.items(
  916. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  917. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  918. selector: {}, # ticket selector to get only a collection of tickets
  919. params: { field: 'created_at' },
  920. )
  921. assert(result)
  922. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  923. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  924. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  925. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  926. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  927. assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
  928. assert_equal(@ticket1.id, result[:ticket_ids][6].to_i)
  929. assert_nil(result[:ticket_ids][7])
  930. # create at - selector with merge
  931. result = Report::TicketGenericTime.aggs(
  932. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  933. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  934. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  935. selector: {
  936. 'state' => {
  937. 'operator' => 'is not',
  938. 'value' => 'merged'
  939. }
  940. }, # ticket selector to get only a collection of tickets
  941. params: { field: 'created_at' },
  942. )
  943. assert(result)
  944. assert_equal(0, result[0])
  945. assert_equal(0, result[1])
  946. assert_equal(0, result[2])
  947. assert_equal(0, result[3])
  948. assert_equal(0, result[4])
  949. assert_equal(0, result[5])
  950. assert_equal(0, result[6])
  951. assert_equal(0, result[7])
  952. assert_equal(0, result[8])
  953. assert_equal(6, result[9])
  954. assert_equal(1, result[10])
  955. assert_equal(0, result[11])
  956. assert_nil(result[12])
  957. result = Report::TicketGenericTime.items(
  958. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  959. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  960. selector: {
  961. 'state' => {
  962. 'operator' => 'is not',
  963. 'value' => 'merged'
  964. }
  965. }, # ticket selector to get only a collection of tickets
  966. params: { field: 'created_at' },
  967. )
  968. assert(result)
  969. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  970. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  971. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  972. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  973. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  974. assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
  975. assert_equal(@ticket1.id, result[:ticket_ids][6].to_i)
  976. assert_nil(result[:ticket_ids][7])
  977. result = Report::TicketGenericTime.items(
  978. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  979. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  980. selector: {
  981. 'created_at' => {
  982. 'operator' => 'before (absolute)',
  983. 'value' => '2015-10-31T00:00:00Z'
  984. }
  985. }, # ticket selector to get only a collection of tickets
  986. params: { field: 'created_at' },
  987. )
  988. assert(result)
  989. assert_equal(@ticket5.id, result[:ticket_ids][0].to_i)
  990. assert_equal(@ticket4.id, result[:ticket_ids][1].to_i)
  991. assert_equal(@ticket3.id, result[:ticket_ids][2].to_i)
  992. assert_equal(@ticket2.id, result[:ticket_ids][3].to_i)
  993. assert_equal(@ticket1.id, result[:ticket_ids][4].to_i)
  994. assert_nil(result[:ticket_ids][5])
  995. result = Report::TicketGenericTime.items(
  996. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  997. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  998. selector: {
  999. 'created_at' => {
  1000. 'operator' => 'after (absolute)',
  1001. 'value' => '2015-10-31T00:00:00Z'
  1002. }
  1003. }, # ticket selector to get only a collection of tickets
  1004. params: { field: 'created_at' },
  1005. )
  1006. assert(result)
  1007. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1008. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1009. assert_nil(result[:ticket_ids][2])
  1010. Report::TicketGenericTime.items(
  1011. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1012. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1013. selector: {
  1014. 'created_at' => {
  1015. 'operator' => 'before (relative)',
  1016. 'range' => 'day',
  1017. 'value' => '1'
  1018. }
  1019. }, # ticket selector to get only a collection of tickets
  1020. params: { field: 'created_at' },
  1021. )
  1022. result = Report::TicketGenericTime.items(
  1023. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1024. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1025. selector: {
  1026. 'created_at' => {
  1027. 'operator' => 'after (relative)',
  1028. 'range' => 'day',
  1029. 'value' => '1'
  1030. }
  1031. }, # ticket selector to get only a collection of tickets
  1032. params: { field: 'created_at' },
  1033. )
  1034. assert(result)
  1035. assert_nil(result[:ticket_ids][0])
  1036. result = Report::TicketGenericTime.items(
  1037. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1038. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1039. selector: {
  1040. 'created_at' => {
  1041. 'operator' => 'before (relative)',
  1042. 'range' => 'day',
  1043. 'value' => '1'
  1044. }
  1045. }, # ticket selector to get only a collection of tickets
  1046. params: { field: 'created_at' },
  1047. )
  1048. assert(result)
  1049. assert_nil(result[:ticket_ids][0])
  1050. result = Report::TicketGenericTime.items(
  1051. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1052. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1053. selector: {
  1054. 'created_at' => {
  1055. 'operator' => 'after (relative)',
  1056. 'range' => 'day',
  1057. 'value' => '5'
  1058. }
  1059. }, # ticket selector to get only a collection of tickets
  1060. params: { field: 'created_at' },
  1061. )
  1062. assert(result)
  1063. assert_equal(@ticket9.id, result[:ticket_ids][0].to_i)
  1064. assert_nil(result[:ticket_ids][1])
  1065. result = Report::TicketGenericTime.items(
  1066. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1067. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1068. selector: {
  1069. 'created_at' => {
  1070. 'operator' => 'before (relative)',
  1071. 'range' => 'month',
  1072. 'value' => '1'
  1073. }
  1074. }, # ticket selector to get only a collection of tickets
  1075. params: { field: 'created_at' },
  1076. )
  1077. assert(result)
  1078. assert_nil(result[:ticket_ids][0])
  1079. result = Report::TicketGenericTime.items(
  1080. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1081. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1082. selector: {
  1083. 'created_at' => {
  1084. 'operator' => 'after (relative)',
  1085. 'range' => 'month',
  1086. 'value' => '5'
  1087. }
  1088. }, # ticket selector to get only a collection of tickets
  1089. params: { field: 'created_at' },
  1090. )
  1091. assert(result)
  1092. assert_equal(@ticket9.id, result[:ticket_ids][0].to_i)
  1093. assert_nil(result[:ticket_ids][1])
  1094. result = Report::TicketGenericTime.items(
  1095. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1096. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1097. selector: {
  1098. 'created_at' => {
  1099. 'operator' => 'before (relative)',
  1100. 'range' => 'year',
  1101. 'value' => '1'
  1102. }
  1103. }, # ticket selector to get only a collection of tickets
  1104. params: { field: 'created_at' },
  1105. )
  1106. assert(result)
  1107. assert_nil(result[:ticket_ids][0])
  1108. result = Report::TicketGenericTime.items(
  1109. range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
  1110. range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
  1111. selector: {
  1112. 'created_at' => {
  1113. 'operator' => 'after (relative)',
  1114. 'range' => 'year',
  1115. 'value' => '5'
  1116. }
  1117. }, # ticket selector to get only a collection of tickets
  1118. params: { field: 'created_at' },
  1119. )
  1120. assert(result)
  1121. assert_equal(@ticket9.id, result[:ticket_ids][0].to_i)
  1122. assert_nil(result[:ticket_ids][1])
  1123. result = Report::TicketGenericTime.items(
  1124. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1125. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1126. selector: {
  1127. 'tags' => {
  1128. 'operator' => 'contains all',
  1129. 'value' => 'aaa, bbb'
  1130. }
  1131. }, # ticket selector to get only a collection of tickets
  1132. params: { field: 'created_at' },
  1133. )
  1134. assert(result)
  1135. assert_equal(@ticket1.id, result[:ticket_ids][0].to_i)
  1136. assert_nil(result[:ticket_ids][1])
  1137. result = Report::TicketGenericTime.items(
  1138. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1139. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1140. selector: {
  1141. 'tags' => {
  1142. 'operator' => 'contains all not',
  1143. 'value' => 'aaa, bbb'
  1144. }
  1145. }, # ticket selector to get only a collection of tickets
  1146. params: { field: 'created_at' },
  1147. )
  1148. assert(result)
  1149. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1150. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1151. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  1152. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  1153. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  1154. assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
  1155. assert_nil(result[:ticket_ids][6])
  1156. result = Report::TicketGenericTime.items(
  1157. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1158. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1159. selector: {
  1160. 'tags' => {
  1161. 'operator' => 'contains all',
  1162. 'value' => 'aaa'
  1163. }
  1164. }, # ticket selector to get only a collection of tickets
  1165. params: { field: 'created_at' },
  1166. )
  1167. assert(result)
  1168. assert_equal(@ticket2.id, result[:ticket_ids][0].to_i)
  1169. assert_equal(@ticket1.id, result[:ticket_ids][1].to_i)
  1170. assert_nil(result[:ticket_ids][2])
  1171. result = Report::TicketGenericTime.items(
  1172. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1173. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1174. selector: {
  1175. 'tags' => {
  1176. 'operator' => 'contains all not',
  1177. 'value' => 'aaa'
  1178. }
  1179. }, # ticket selector to get only a collection of tickets
  1180. params: { field: 'created_at' },
  1181. )
  1182. assert(result)
  1183. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1184. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1185. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  1186. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  1187. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  1188. assert_nil(result[:ticket_ids][5])
  1189. result = Report::TicketGenericTime.items(
  1190. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1191. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1192. selector: {
  1193. 'tags' => {
  1194. 'operator' => 'contains one not',
  1195. 'value' => 'aaa'
  1196. }
  1197. }, # ticket selector to get only a collection of tickets
  1198. params: { field: 'created_at' },
  1199. )
  1200. assert(result)
  1201. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1202. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1203. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  1204. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  1205. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  1206. assert_nil(result[:ticket_ids][5])
  1207. result = Report::TicketGenericTime.items(
  1208. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1209. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1210. selector: {
  1211. 'tags' => {
  1212. 'operator' => 'contains one not',
  1213. 'value' => 'aaa, bbb'
  1214. }
  1215. }, # ticket selector to get only a collection of tickets
  1216. params: { field: 'created_at' },
  1217. )
  1218. assert(result)
  1219. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1220. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1221. assert_equal(@ticket4.id, result[:ticket_ids][2].to_i)
  1222. assert_equal(@ticket3.id, result[:ticket_ids][3].to_i)
  1223. assert_nil(result[:ticket_ids][4])
  1224. result = Report::TicketGenericTime.items(
  1225. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1226. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1227. selector: {
  1228. 'tags' => {
  1229. 'operator' => 'contains one',
  1230. 'value' => 'aaa'
  1231. }
  1232. }, # ticket selector to get only a collection of tickets
  1233. params: { field: 'created_at' },
  1234. )
  1235. assert(result)
  1236. assert_equal(@ticket2.id, result[:ticket_ids][0].to_i)
  1237. assert_equal(@ticket1.id, result[:ticket_ids][1].to_i)
  1238. assert_nil(result[:ticket_ids][2])
  1239. result = Report::TicketGenericTime.items(
  1240. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1241. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1242. selector: {
  1243. 'tags' => {
  1244. 'operator' => 'contains one',
  1245. 'value' => 'aaa, bbb'
  1246. }
  1247. }, # ticket selector to get only a collection of tickets
  1248. params: { field: 'created_at' },
  1249. )
  1250. assert(result)
  1251. assert_equal(@ticket5.id, result[:ticket_ids][0].to_i)
  1252. assert_equal(@ticket2.id, result[:ticket_ids][1].to_i)
  1253. assert_equal(@ticket1.id, result[:ticket_ids][2].to_i)
  1254. assert_nil(result[:ticket_ids][3])
  1255. result = Report::TicketGenericTime.items(
  1256. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1257. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1258. selector: {
  1259. 'title' => {
  1260. 'operator' => 'contains',
  1261. 'value' => 'test'
  1262. }
  1263. }, # ticket selector to get only a collection of tickets
  1264. params: { field: 'created_at' },
  1265. )
  1266. assert(result)
  1267. assert_equal(@ticket7.id, result[:ticket_ids][0].to_i)
  1268. assert_equal(@ticket6.id, result[:ticket_ids][1].to_i)
  1269. assert_equal(@ticket5.id, result[:ticket_ids][2].to_i)
  1270. assert_equal(@ticket4.id, result[:ticket_ids][3].to_i)
  1271. assert_equal(@ticket3.id, result[:ticket_ids][4].to_i)
  1272. assert_equal(@ticket2.id, result[:ticket_ids][5].to_i)
  1273. assert_equal(@ticket1.id, result[:ticket_ids][6].to_i)
  1274. assert_nil(result[:ticket_ids][7])
  1275. result = Report::TicketGenericTime.items(
  1276. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1277. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1278. selector: {
  1279. 'title' => {
  1280. 'operator' => 'contains not',
  1281. 'value' => 'test'
  1282. }
  1283. }, # ticket selector to get only a collection of tickets
  1284. params: { field: 'created_at' },
  1285. )
  1286. assert(result)
  1287. assert_nil(result[:ticket_ids][0])
  1288. # search for test_category.keyword to find values with :: in query
  1289. result = Report::TicketGenericTime.items(
  1290. range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
  1291. range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
  1292. selector: {
  1293. 'test_category' => {
  1294. 'operator' => 'is',
  1295. 'value' => 'cc::bb'
  1296. },
  1297. }, # ticket selector to get only a collection of tickets
  1298. params: { field: 'created_at' },
  1299. )
  1300. assert(result)
  1301. assert_equal(@ticket1.id, result[:ticket_ids][0].to_i)
  1302. assert_nil(result[:ticket_ids][1])
  1303. end
  1304. end