report_test.rb 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. # encoding: utf-8
  2. require 'integration_test_helper'
  3. class ReportTest < ActiveSupport::TestCase
  4. # set config
  5. if !ENV['ES_URL']
  6. raise "ERROR: Need ES_URL - hint ES_URL='http://172.0.0.1:9200'"
  7. end
  8. Setting.set('es_url', ENV['ES_URL'])
  9. if !ENV['ES_INDEX'] && !ENV['ES_INDEX_RAND']
  10. raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
  11. end
  12. if ENV['ES_INDEX_RAND']
  13. ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
  14. end
  15. Setting.set('es_index', ENV['ES_INDEX'])
  16. # Setting.set('es_url', 'http://172.0.0.1:9200')
  17. # Setting.set('es_index', 'estest.local_zammad')
  18. # Setting.set('es_user', 'elasticsearch')
  19. # Setting.set('es_password', 'zammad')
  20. # Setting.set('es_attachment_max_size_in_mb', 1)
  21. # clear cache
  22. Cache.clear
  23. # remove background jobs
  24. Delayed::Job.destroy_all
  25. Ticket.destroy_all
  26. # drop/create indexes
  27. #Rake::Task["searchindex:drop"].execute
  28. #Rake::Task["searchindex:create"].execute
  29. system('rake searchindex:rebuild')
  30. group1 = Group.lookup(name: 'Users')
  31. group2 = Group.create_if_not_exists(
  32. name: 'Report Test',
  33. updated_by_id: 1,
  34. created_by_id: 1
  35. )
  36. load "#{Rails.root}/test/fixtures/seeds.rb"
  37. ticket1 = Ticket.create(
  38. title: 'test 1',
  39. group: group2,
  40. customer_id: 2,
  41. state: Ticket::State.lookup(name: 'new'),
  42. priority: Ticket::Priority.lookup(name: '2 normal'),
  43. created_at: '2015-10-28 09:30:00 UTC',
  44. updated_at: '2015-10-28 09:30:00 UTC',
  45. updated_by_id: 1,
  46. created_by_id: 1,
  47. )
  48. article1 = Ticket::Article.create(
  49. ticket_id: ticket1.id,
  50. from: 'some_sender@example.com',
  51. to: 'some_recipient@example.com',
  52. subject: 'some subject',
  53. message_id: 'some@id',
  54. body: 'some message article_inbound',
  55. internal: false,
  56. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  57. type: Ticket::Article::Type.where(name: 'email').first,
  58. created_at: '2015-10-28 09:30:00 UTC',
  59. updated_at: '2015-10-28 09:30:00 UTC',
  60. updated_by_id: 1,
  61. created_by_id: 1,
  62. )
  63. ticket1.update_attributes(
  64. group: Group.lookup(name: 'Users'),
  65. updated_at: '2015-10-28 14:30:00 UTC',
  66. )
  67. ticket2 = Ticket.create(
  68. title: 'test 2',
  69. group: group1,
  70. customer_id: 2,
  71. state: Ticket::State.lookup(name: 'new'),
  72. priority: Ticket::Priority.lookup(name: '2 normal'),
  73. created_at: '2015-10-28 09:30:01 UTC',
  74. updated_at: '2015-10-28 09:30:01 UTC',
  75. updated_by_id: 1,
  76. created_by_id: 1,
  77. )
  78. article2 = Ticket::Article.create(
  79. ticket_id: ticket2.id,
  80. from: 'some_sender@example.com',
  81. to: 'some_recipient@example.com',
  82. subject: 'some subject',
  83. message_id: 'some@id',
  84. body: 'some message article_inbound',
  85. internal: false,
  86. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  87. type: Ticket::Article::Type.where(name: 'email').first,
  88. created_at: '2015-10-28 09:30:01 UTC',
  89. updated_at: '2015-10-28 09:30:01 UTC',
  90. updated_by_id: 1,
  91. created_by_id: 1,
  92. )
  93. ticket2.update_attributes(
  94. group_id: group2.id,
  95. updated_at: '2015-10-28 14:30:00 UTC',
  96. )
  97. ticket3 = Ticket.create(
  98. title: 'test 3',
  99. group: group1,
  100. customer_id: 2,
  101. state: Ticket::State.lookup(name: 'open'),
  102. priority: Ticket::Priority.lookup(name: '3 high'),
  103. created_at: '2015-10-28 10:30:00 UTC',
  104. updated_at: '2015-10-28 10:30:00 UTC',
  105. updated_by_id: 1,
  106. created_by_id: 1,
  107. )
  108. article3 = Ticket::Article.create(
  109. ticket_id: ticket3.id,
  110. from: 'some_sender@example.com',
  111. to: 'some_recipient@example.com',
  112. subject: 'some subject',
  113. message_id: 'some@id',
  114. body: 'some message article_inbound',
  115. internal: false,
  116. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  117. type: Ticket::Article::Type.where(name: 'email').first,
  118. created_at: '2015-10-28 10:30:00 UTC',
  119. updated_at: '2015-10-28 10:30:00 UTC',
  120. updated_by_id: 1,
  121. created_by_id: 1,
  122. )
  123. ticket4 = Ticket.create(
  124. title: 'test 4',
  125. group: group1,
  126. customer_id: 2,
  127. state: Ticket::State.lookup(name: 'closed'),
  128. priority: Ticket::Priority.lookup(name: '2 normal'),
  129. close_at: '2015-10-28 11:30:00 UTC',
  130. created_at: '2015-10-28 10:30:00 UTC',
  131. updated_at: '2015-10-28 10:30:00 UTC',
  132. updated_by_id: 1,
  133. created_by_id: 1,
  134. )
  135. article4 = Ticket::Article.create(
  136. ticket_id: ticket4.id,
  137. from: 'some_sender@example.com',
  138. to: 'some_recipient@example.com',
  139. subject: 'some subject',
  140. message_id: 'some@id',
  141. body: 'some message article_inbound',
  142. internal: false,
  143. sender: Ticket::Article::Sender.where(name: 'Customer').first,
  144. type: Ticket::Article::Type.where(name: 'email').first,
  145. created_at: '2015-10-28 10:30:00 UTC',
  146. updated_at: '2015-10-28 10:30:00 UTC',
  147. updated_by_id: 1,
  148. created_by_id: 1,
  149. )
  150. ticket5 = Ticket.create(
  151. title: 'test 5',
  152. group: group1,
  153. customer_id: 2,
  154. state: Ticket::State.lookup(name: 'closed'),
  155. priority: Ticket::Priority.lookup(name: '3 high'),
  156. close_at: '2015-10-28 11:40:00 UTC',
  157. created_at: '2015-10-28 11:30:00 UTC',
  158. updated_at: '2015-10-28 11:30:00 UTC',
  159. updated_by_id: 1,
  160. created_by_id: 1,
  161. )
  162. article5 = Ticket::Article.create(
  163. ticket_id: ticket5.id,
  164. from: 'some_sender@example.com',
  165. to: 'some_recipient@example.com',
  166. subject: 'some subject',
  167. message_id: 'some@id',
  168. body: 'some message article_outbound',
  169. internal: false,
  170. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  171. type: Ticket::Article::Type.where(name: 'email').first,
  172. created_at: '2015-10-28 11:30:00 UTC',
  173. updated_at: '2015-10-28 11:30:00 UTC',
  174. updated_by_id: 1,
  175. created_by_id: 1,
  176. )
  177. ticket5.update_attributes(
  178. state: Ticket::State.lookup(name: 'open'),
  179. updated_at: '2015-10-28 14:30:00 UTC',
  180. )
  181. ticket6 = Ticket.create(
  182. title: 'test 6',
  183. group: group1,
  184. customer_id: 2,
  185. state: Ticket::State.lookup(name: 'closed'),
  186. priority: Ticket::Priority.lookup(name: '2 normal'),
  187. close_at: '2015-10-31 12:35:00 UTC',
  188. created_at: '2015-10-31 12:30:00 UTC',
  189. updated_at: '2015-10-31 12:30:00 UTC',
  190. updated_by_id: 1,
  191. created_by_id: 1,
  192. )
  193. article6 = Ticket::Article.create(
  194. ticket_id: ticket6.id,
  195. from: 'some_sender@example.com',
  196. to: 'some_recipient@example.com',
  197. subject: 'some subject',
  198. message_id: 'some@id',
  199. body: 'some message article_outbound',
  200. internal: false,
  201. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  202. type: Ticket::Article::Type.where(name: 'email').first,
  203. created_at: '2015-10-31 12:30:00 UTC',
  204. updated_at: '2015-10-31 12:30:00 UTC',
  205. updated_by_id: 1,
  206. created_by_id: 1,
  207. )
  208. ticket7 = Ticket.create(
  209. title: 'test 7',
  210. group: group1,
  211. customer_id: 2,
  212. state: Ticket::State.lookup(name: 'closed'),
  213. priority: Ticket::Priority.lookup(name: '2 normal'),
  214. close_at: '2015-11-01 12:30:00 UTC',
  215. created_at: '2015-11-01 12:30:00 UTC',
  216. updated_at: '2015-11-01 12:30:00 UTC',
  217. updated_by_id: 1,
  218. created_by_id: 1,
  219. )
  220. article7 = Ticket::Article.create(
  221. ticket_id: ticket7.id,
  222. from: 'some_sender@example.com',
  223. to: 'some_recipient@example.com',
  224. subject: 'some subject',
  225. message_id: 'some@id',
  226. body: 'some message article_outbound',
  227. internal: false,
  228. sender: Ticket::Article::Sender.where(name: 'Agent').first,
  229. type: Ticket::Article::Type.where(name: 'email').first,
  230. created_at: '2015-11-01 12:30:00 UTC',
  231. updated_at: '2015-11-01 12:30:00 UTC',
  232. updated_by_id: 1,
  233. created_by_id: 1,
  234. )
  235. # execute background jobs
  236. Scheduler.worker(true)
  237. sleep 6
  238. test 'a - first solution' do
  239. # month
  240. result = Report::TicketFirstSolution.aggs(
  241. range_start: '2015-01-01T00:00:00Z',
  242. range_end: '2015-12-31T23:59:59Z',
  243. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  244. selector: {}, # ticket selector to get only a collection of tickets
  245. )
  246. assert(result)
  247. assert_equal(0, result[0])
  248. assert_equal(0, result[1])
  249. assert_equal(0, result[2])
  250. assert_equal(0, result[3])
  251. assert_equal(0, result[4])
  252. assert_equal(0, result[5])
  253. assert_equal(0, result[6])
  254. assert_equal(0, result[7])
  255. assert_equal(0, result[8])
  256. assert_equal(2, result[9])
  257. assert_equal(1, result[10])
  258. assert_equal(0, result[11])
  259. assert_equal(nil, result[12])
  260. result = Report::TicketFirstSolution.items(
  261. range_start: '2015-01-01T00:00:00Z',
  262. range_end: '2015-12-31T23:59:59Z',
  263. selector: {}, # ticket selector to get only a collection of tickets
  264. )
  265. assert(result)
  266. assert_equal(ticket5.id, result[:ticket_ids][0])
  267. assert_equal(ticket6.id, result[:ticket_ids][1])
  268. assert_equal(ticket7.id, result[:ticket_ids][2])
  269. assert_equal(nil, result[:ticket_ids][3])
  270. # month - with selector #1
  271. result = Report::TicketFirstSolution.aggs(
  272. range_start: '2015-01-01T00:00:00Z',
  273. range_end: '2015-12-31T23:59:59Z',
  274. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  275. selector: {
  276. 'ticket.priority_id' => {
  277. 'operator' => 'is',
  278. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  279. }
  280. }, # ticket selector to get only a collection of tickets
  281. )
  282. assert(result)
  283. assert_equal(0, result[0])
  284. assert_equal(0, result[1])
  285. assert_equal(0, result[2])
  286. assert_equal(0, result[3])
  287. assert_equal(0, result[4])
  288. assert_equal(0, result[5])
  289. assert_equal(0, result[6])
  290. assert_equal(0, result[7])
  291. assert_equal(0, result[8])
  292. assert_equal(1, result[9])
  293. assert_equal(0, result[10])
  294. assert_equal(0, result[11])
  295. assert_equal(nil, result[12])
  296. result = Report::TicketFirstSolution.items(
  297. range_start: '2015-01-01T00:00:00Z',
  298. range_end: '2015-12-31T23:59:59Z',
  299. selector: {
  300. 'ticket.priority_id' => {
  301. 'operator' => 'is',
  302. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  303. }
  304. }, # ticket selector to get only a collection of tickets
  305. )
  306. assert(result)
  307. assert_equal(ticket5.id, result[:ticket_ids][0])
  308. assert_equal(nil, result[:ticket_ids][1])
  309. # month - with selector #2
  310. result = Report::TicketFirstSolution.aggs(
  311. range_start: '2015-01-01T00:00:00Z',
  312. range_end: '2015-12-31T23:59:59Z',
  313. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  314. selector: {
  315. 'ticket.priority_id' => {
  316. 'operator' => 'is not',
  317. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  318. }
  319. }, # ticket selector to get only a collection of tickets
  320. )
  321. assert(result)
  322. assert_equal(0, result[0])
  323. assert_equal(0, result[1])
  324. assert_equal(0, result[2])
  325. assert_equal(0, result[3])
  326. assert_equal(0, result[4])
  327. assert_equal(0, result[5])
  328. assert_equal(0, result[6])
  329. assert_equal(0, result[7])
  330. assert_equal(0, result[8])
  331. assert_equal(1, result[9])
  332. assert_equal(1, result[10])
  333. assert_equal(0, result[11])
  334. assert_equal(nil, result[12])
  335. result = Report::TicketFirstSolution.items(
  336. range_start: '2015-01-01T00:00:00Z',
  337. range_end: '2015-12-31T23:59:59Z',
  338. selector: {
  339. 'ticket.priority_id' => {
  340. 'operator' => 'is not',
  341. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  342. }
  343. }, # ticket selector to get only a collection of tickets
  344. )
  345. assert(result)
  346. assert_equal(ticket6.id, result[:ticket_ids][0])
  347. assert_equal(ticket7.id, result[:ticket_ids][1])
  348. assert_equal(nil, result[:ticket_ids][2])
  349. # week
  350. result = Report::TicketFirstSolution.aggs(
  351. range_start: '2015-10-26T00:00:00Z',
  352. range_end: '2015-10-31T23:59:59Z',
  353. interval: 'week', # year, quarter, month, week, day, hour, minute, second
  354. selector: {}, # ticket selector to get only a collection of tickets
  355. )
  356. assert(result)
  357. assert_equal(0, result[0])
  358. assert_equal(0, result[1])
  359. assert_equal(1, result[2])
  360. assert_equal(0, result[3])
  361. assert_equal(0, result[4])
  362. assert_equal(1, result[5])
  363. assert_equal(1, result[6])
  364. assert_equal(nil, result[7])
  365. result = Report::TicketFirstSolution.items(
  366. range_start: '2015-10-26T00:00:00Z',
  367. range_end: '2015-11-01T23:59:59Z',
  368. interval: 'week', # year, quarter, month, week, day, hour, minute, second
  369. selector: {}, # ticket selector to get only a collection of tickets
  370. )
  371. assert(result)
  372. assert_equal(ticket5.id, result[:ticket_ids][0])
  373. assert_equal(ticket6.id, result[:ticket_ids][1])
  374. assert_equal(ticket7.id, result[:ticket_ids][2])
  375. assert_equal(nil, result[:ticket_ids][3])
  376. # day
  377. result = Report::TicketFirstSolution.aggs(
  378. range_start: '2015-10-01T00:00:00Z',
  379. range_end: '2015-11-01T23:59:59Z',
  380. interval: 'day', # year, quarter, month, week, day, hour, minute, second
  381. selector: {}, # 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(0, result[9])
  394. assert_equal(0, result[10])
  395. assert_equal(0, result[11])
  396. assert_equal(0, result[12])
  397. assert_equal(0, result[13])
  398. assert_equal(0, result[14])
  399. assert_equal(0, result[15])
  400. assert_equal(0, result[16])
  401. assert_equal(0, result[17])
  402. assert_equal(0, result[18])
  403. assert_equal(0, result[19])
  404. assert_equal(0, result[20])
  405. assert_equal(0, result[21])
  406. assert_equal(0, result[22])
  407. assert_equal(0, result[23])
  408. assert_equal(0, result[24])
  409. assert_equal(0, result[25])
  410. assert_equal(0, result[26])
  411. assert_equal(1, result[27])
  412. assert_equal(0, result[28])
  413. assert_equal(0, result[29])
  414. assert_equal(1, result[30])
  415. assert_equal(nil, result[31])
  416. result = Report::TicketFirstSolution.items(
  417. range_start: '2015-10-01T00:00:00Z',
  418. range_end: '2015-10-31T23:59:59Z',
  419. interval: 'day', # year, quarter, month, week, day, hour, minute, second
  420. selector: {}, # ticket selector to get only a collection of tickets
  421. )
  422. assert(result)
  423. assert_equal(ticket5.id, result[:ticket_ids][0])
  424. assert_equal(ticket6.id, result[:ticket_ids][1])
  425. assert_equal(nil, result[:ticket_ids][2])
  426. # hour
  427. result = Report::TicketFirstSolution.aggs(
  428. range_start: '2015-10-28T00:00:00Z',
  429. range_end: '2015-10-28T23:59:59Z',
  430. interval: 'hour', # year, quarter, month, week, day, hour, minute, second
  431. selector: {}, # ticket selector to get only a collection of tickets
  432. )
  433. assert(result)
  434. assert_equal(0, result[0])
  435. assert_equal(0, result[1])
  436. assert_equal(0, result[2])
  437. assert_equal(0, result[3])
  438. assert_equal(0, result[4])
  439. assert_equal(0, result[5])
  440. assert_equal(0, result[6])
  441. assert_equal(0, result[7])
  442. assert_equal(0, result[8])
  443. assert_equal(0, result[9])
  444. assert_equal(0, result[10])
  445. assert_equal(1, result[11])
  446. assert_equal(0, result[12])
  447. assert_equal(0, result[13])
  448. assert_equal(0, result[14])
  449. assert_equal(0, result[15])
  450. assert_equal(0, result[16])
  451. assert_equal(0, result[17])
  452. assert_equal(0, result[18])
  453. assert_equal(0, result[19])
  454. assert_equal(0, result[20])
  455. assert_equal(0, result[21])
  456. assert_equal(0, result[22])
  457. assert_equal(0, result[23])
  458. assert_equal(nil, result[24])
  459. result = Report::TicketFirstSolution.items(
  460. range_start: '2015-10-28T00:00:00Z',
  461. range_end: '2015-10-28T23:59:59Z',
  462. interval: 'hour', # year, quarter, month, week, day, hour, minute, second
  463. selector: {}, # ticket selector to get only a collection of tickets
  464. )
  465. assert(result)
  466. assert_equal(ticket5.id, result[:ticket_ids][0])
  467. assert_equal(nil, result[:ticket_ids][1])
  468. # created by channel and direction
  469. end
  470. test 'b - reopen' do
  471. # month
  472. result = Report::TicketReopened.aggs(
  473. range_start: '2015-01-01T00:00:00Z',
  474. range_end: '2015-12-31T23:59:59Z',
  475. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  476. selector: {}, # ticket selector to get only a collection of tickets
  477. )
  478. assert(result)
  479. assert_equal(0, result[0])
  480. assert_equal(0, result[1])
  481. assert_equal(0, result[2])
  482. assert_equal(0, result[3])
  483. assert_equal(0, result[4])
  484. assert_equal(0, result[5])
  485. assert_equal(0, result[6])
  486. assert_equal(0, result[7])
  487. assert_equal(0, result[8])
  488. assert_equal(1, result[9])
  489. assert_equal(0, result[10])
  490. assert_equal(0, result[11])
  491. assert_equal(nil, result[12])
  492. result = Report::TicketReopened.items(
  493. range_start: '2015-01-01T00:00:00Z',
  494. range_end: '2015-12-31T23:59:59Z',
  495. selector: {}, # ticket selector to get only a collection of tickets
  496. )
  497. assert(result)
  498. assert_equal(ticket5.id, result[:ticket_ids][0])
  499. assert_equal(nil, result[:ticket_ids][1])
  500. # month - with selector #1
  501. result = Report::TicketReopened.aggs(
  502. range_start: '2015-01-01T00:00:00Z',
  503. range_end: '2015-12-31T23:59:59Z',
  504. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  505. selector: {
  506. 'ticket.priority_id' => {
  507. 'operator' => 'is',
  508. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  509. }
  510. }, # ticket selector to get only a collection of tickets
  511. )
  512. assert(result)
  513. assert_equal(0, result[0])
  514. assert_equal(0, result[1])
  515. assert_equal(0, result[2])
  516. assert_equal(0, result[3])
  517. assert_equal(0, result[4])
  518. assert_equal(0, result[5])
  519. assert_equal(0, result[6])
  520. assert_equal(0, result[7])
  521. assert_equal(0, result[8])
  522. assert_equal(1, result[9])
  523. assert_equal(0, result[10])
  524. assert_equal(0, result[11])
  525. assert_equal(nil, result[12])
  526. result = Report::TicketReopened.items(
  527. range_start: '2015-01-01T00:00:00Z',
  528. range_end: '2015-12-31T23:59:59Z',
  529. selector: {
  530. 'ticket.priority_id' => {
  531. 'operator' => 'is',
  532. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  533. }
  534. }, # ticket selector to get only a collection of tickets
  535. )
  536. assert(result)
  537. assert_equal(ticket5.id, result[:ticket_ids][0])
  538. assert_equal(nil, result[:ticket_ids][1])
  539. # month - with selector #2
  540. result = Report::TicketReopened.aggs(
  541. range_start: '2015-01-01T00:00:00Z',
  542. range_end: '2015-12-31T23:59:59Z',
  543. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  544. selector: {
  545. 'ticket.priority_id' => {
  546. 'operator' => 'is not',
  547. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  548. }
  549. }, # ticket selector to get only a collection of tickets
  550. )
  551. assert(result)
  552. assert_equal(0, result[0])
  553. assert_equal(0, result[1])
  554. assert_equal(0, result[2])
  555. assert_equal(0, result[3])
  556. assert_equal(0, result[4])
  557. assert_equal(0, result[5])
  558. assert_equal(0, result[6])
  559. assert_equal(0, result[7])
  560. assert_equal(0, result[8])
  561. assert_equal(0, result[9])
  562. assert_equal(0, result[10])
  563. assert_equal(0, result[11])
  564. assert_equal(nil, result[12])
  565. result = Report::TicketReopened.items(
  566. range_start: '2015-01-01T00:00:00Z',
  567. range_end: '2015-12-31T23:59:59Z',
  568. selector: {
  569. 'ticket.priority_id' => {
  570. 'operator' => 'is not',
  571. 'value' => [Ticket::Priority.lookup(name: '3 high').id],
  572. }
  573. }, # ticket selector to get only a collection of tickets
  574. )
  575. assert(result)
  576. assert_equal(nil, result[:ticket_ids][0])
  577. end
  578. test 'c - move in/out' do
  579. # month
  580. result = Report::TicketMoved.aggs(
  581. range_start: '2015-01-01T00:00:00Z',
  582. range_end: '2015-12-31T23:59:59Z',
  583. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  584. selector: {
  585. 'ticket.group_id' => {
  586. 'operator' => 'is',
  587. 'value' => [Group.lookup(name: 'Users').id],
  588. }
  589. }, # ticket selector to get only a collection of tickets
  590. params: {
  591. type: 'in',
  592. },
  593. )
  594. assert(result)
  595. assert_equal(0, result[0])
  596. assert_equal(0, result[1])
  597. assert_equal(0, result[2])
  598. assert_equal(0, result[3])
  599. assert_equal(0, result[4])
  600. assert_equal(0, result[5])
  601. assert_equal(0, result[6])
  602. assert_equal(0, result[7])
  603. assert_equal(0, result[8])
  604. assert_equal(1, result[9])
  605. assert_equal(0, result[10])
  606. assert_equal(0, result[11])
  607. assert_equal(nil, result[12])
  608. result = Report::TicketMoved.items(
  609. range_start: '2015-01-01T00:00:00Z',
  610. range_end: '2015-12-31T23:59:59Z',
  611. selector: {
  612. 'ticket.group_id' => {
  613. 'operator' => 'is',
  614. 'value' => [Group.lookup(name: 'Users').id],
  615. }
  616. }, # ticket selector to get only a collection of tickets
  617. params: {
  618. type: 'in',
  619. },
  620. )
  621. assert(result)
  622. assert_equal(ticket1.id, result[:ticket_ids][0])
  623. assert_equal(nil, result[:ticket_ids][1])
  624. # out
  625. result = Report::TicketMoved.aggs(
  626. range_start: '2015-01-01T00:00:00Z',
  627. range_end: '2015-12-31T23:59:59Z',
  628. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  629. selector: {
  630. 'ticket.group_id' => {
  631. 'operator' => 'is',
  632. 'value' => [Group.lookup(name: 'Users').id],
  633. }
  634. }, # ticket selector to get only a collection of tickets
  635. params: {
  636. type: 'out',
  637. },
  638. )
  639. assert(result)
  640. assert_equal(0, result[0])
  641. assert_equal(0, result[1])
  642. assert_equal(0, result[2])
  643. assert_equal(0, result[3])
  644. assert_equal(0, result[4])
  645. assert_equal(0, result[5])
  646. assert_equal(0, result[6])
  647. assert_equal(0, result[7])
  648. assert_equal(0, result[8])
  649. assert_equal(1, result[9])
  650. assert_equal(0, result[10])
  651. assert_equal(0, result[11])
  652. assert_equal(nil, result[12])
  653. result = Report::TicketMoved.items(
  654. range_start: '2015-01-01T00:00:00Z',
  655. range_end: '2015-12-31T23:59:59Z',
  656. selector: {
  657. 'ticket.group_id' => {
  658. 'operator' => 'is',
  659. 'value' => [Group.lookup(name: 'Users').id],
  660. }
  661. }, # ticket selector to get only a collection of tickets
  662. params: {
  663. type: 'out',
  664. },
  665. )
  666. assert(result)
  667. assert_equal(ticket2.id, result[:ticket_ids][0])
  668. assert_equal(nil, result[:ticket_ids][1])
  669. end
  670. test 'd - created at' do
  671. # month
  672. result = Report::TicketGenericTime.aggs(
  673. range_start: '2015-01-01T00:00:00Z',
  674. range_end: '2015-12-31T23:59:59Z',
  675. interval: 'month', # year, quarter, month, week, day, hour, minute, second
  676. selector: {}, # ticket selector to get only a collection of tickets
  677. params: { field: 'created_at' },
  678. )
  679. assert(result)
  680. assert_equal(0, result[0])
  681. assert_equal(0, result[1])
  682. assert_equal(0, result[2])
  683. assert_equal(0, result[3])
  684. assert_equal(0, result[4])
  685. assert_equal(0, result[5])
  686. assert_equal(0, result[6])
  687. assert_equal(0, result[7])
  688. assert_equal(0, result[8])
  689. assert_equal(6, result[9])
  690. assert_equal(1, result[10])
  691. assert_equal(0, result[11])
  692. assert_equal(nil, result[12])
  693. result = Report::TicketGenericTime.items(
  694. range_start: '2015-01-01T00:00:00Z',
  695. range_end: '2015-12-31T23:59:59Z',
  696. selector: {}, # ticket selector to get only a collection of tickets
  697. params: { field: 'created_at' },
  698. )
  699. assert(result)
  700. assert_equal(ticket7.id, result[:ticket_ids][0].to_i)
  701. assert_equal(ticket6.id, result[:ticket_ids][1].to_i)
  702. assert_equal(ticket5.id, result[:ticket_ids][2].to_i)
  703. assert_equal(ticket3.id, result[:ticket_ids][3].to_i)
  704. assert_equal(ticket4.id, result[:ticket_ids][4].to_i)
  705. assert_equal(ticket2.id, result[:ticket_ids][5].to_i)
  706. assert_equal(ticket1.id, result[:ticket_ids][6].to_i)
  707. assert_equal(nil, result[:ticket_ids][7])
  708. # cleanup
  709. system('rake searchindex:drop')
  710. end
  711. end