123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763 |
- # encoding: utf-8
- require 'integration_test_helper'
- class ReportTest < ActiveSupport::TestCase
- # set config
- if !ENV['ES_URL']
- raise "ERROR: Need ES_URL - hint ES_URL='http://172.0.0.1:9200'"
- end
- Setting.set('es_url', ENV['ES_URL'])
- if !ENV['ES_INDEX'] && !ENV['ES_INDEX_RAND']
- raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
- end
- if ENV['ES_INDEX_RAND']
- ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
- end
- Setting.set('es_index', ENV['ES_INDEX'])
- # Setting.set('es_url', 'http://172.0.0.1:9200')
- # Setting.set('es_index', 'estest.local_zammad')
- # Setting.set('es_user', 'elasticsearch')
- # Setting.set('es_password', 'zammad')
- # Setting.set('es_attachment_max_size_in_mb', 1)
- # clear cache
- Cache.clear
- # remove background jobs
- Delayed::Job.destroy_all
- Ticket.destroy_all
- # drop/create indexes
- #Rake::Task["searchindex:drop"].execute
- #Rake::Task["searchindex:create"].execute
- system('rake searchindex:rebuild')
- group1 = Group.lookup(name: 'Users')
- group2 = Group.create_if_not_exists(
- name: 'Report Test',
- updated_by_id: 1,
- created_by_id: 1
- )
- load "#{Rails.root}/test/fixtures/seeds.rb"
- ticket1 = Ticket.create(
- title: 'test 1',
- group: group2,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2015-10-28 09:30:00 UTC',
- updated_at: '2015-10-28 09:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- article1 = Ticket::Article.create(
- ticket_id: ticket1.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message article_inbound',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- created_at: '2015-10-28 09:30:00 UTC',
- updated_at: '2015-10-28 09:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket1.update_attributes(
- group: Group.lookup(name: 'Users'),
- updated_at: '2015-10-28 14:30:00 UTC',
- )
- ticket2 = Ticket.create(
- title: 'test 2',
- group: group1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'new'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- created_at: '2015-10-28 09:30:01 UTC',
- updated_at: '2015-10-28 09:30:01 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- article2 = Ticket::Article.create(
- ticket_id: ticket2.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message article_inbound',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- created_at: '2015-10-28 09:30:01 UTC',
- updated_at: '2015-10-28 09:30:01 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket2.update_attributes(
- group_id: group2.id,
- updated_at: '2015-10-28 14:30:00 UTC',
- )
- ticket3 = Ticket.create(
- title: 'test 3',
- group: group1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'open'),
- priority: Ticket::Priority.lookup(name: '3 high'),
- created_at: '2015-10-28 10:30:00 UTC',
- updated_at: '2015-10-28 10:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- article3 = Ticket::Article.create(
- ticket_id: ticket3.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message article_inbound',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- created_at: '2015-10-28 10:30:00 UTC',
- updated_at: '2015-10-28 10:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket4 = Ticket.create(
- title: 'test 4',
- group: group1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- close_at: '2015-10-28 11:30:00 UTC',
- created_at: '2015-10-28 10:30:00 UTC',
- updated_at: '2015-10-28 10:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- article4 = Ticket::Article.create(
- ticket_id: ticket4.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message article_inbound',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Customer').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- created_at: '2015-10-28 10:30:00 UTC',
- updated_at: '2015-10-28 10:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket5 = Ticket.create(
- title: 'test 5',
- group: group1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- priority: Ticket::Priority.lookup(name: '3 high'),
- close_at: '2015-10-28 11:40:00 UTC',
- created_at: '2015-10-28 11:30:00 UTC',
- updated_at: '2015-10-28 11:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- article5 = Ticket::Article.create(
- ticket_id: ticket5.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message article_outbound',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- created_at: '2015-10-28 11:30:00 UTC',
- updated_at: '2015-10-28 11:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket5.update_attributes(
- state: Ticket::State.lookup(name: 'open'),
- updated_at: '2015-10-28 14:30:00 UTC',
- )
- ticket6 = Ticket.create(
- title: 'test 6',
- group: group1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- close_at: '2015-10-31 12:35:00 UTC',
- created_at: '2015-10-31 12:30:00 UTC',
- updated_at: '2015-10-31 12:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- article6 = Ticket::Article.create(
- ticket_id: ticket6.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message article_outbound',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- created_at: '2015-10-31 12:30:00 UTC',
- updated_at: '2015-10-31 12:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- ticket7 = Ticket.create(
- title: 'test 7',
- group: group1,
- customer_id: 2,
- state: Ticket::State.lookup(name: 'closed'),
- priority: Ticket::Priority.lookup(name: '2 normal'),
- close_at: '2015-11-01 12:30:00 UTC',
- created_at: '2015-11-01 12:30:00 UTC',
- updated_at: '2015-11-01 12:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- article7 = Ticket::Article.create(
- ticket_id: ticket7.id,
- from: 'some_sender@example.com',
- to: 'some_recipient@example.com',
- subject: 'some subject',
- message_id: 'some@id',
- body: 'some message article_outbound',
- internal: false,
- sender: Ticket::Article::Sender.where(name: 'Agent').first,
- type: Ticket::Article::Type.where(name: 'email').first,
- created_at: '2015-11-01 12:30:00 UTC',
- updated_at: '2015-11-01 12:30:00 UTC',
- updated_by_id: 1,
- created_by_id: 1,
- )
- # execute background jobs
- Scheduler.worker(true)
- sleep 6
- test 'a - first solution' do
- # month
- result = Report::TicketFirstSolution.aggs(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- interval: 'month', # year, quarter, month, week, day, hour, minute, second
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(2, result[9])
- assert_equal(1, result[10])
- assert_equal(0, result[11])
- assert_equal(nil, result[12])
- result = Report::TicketFirstSolution.items(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(ticket5.id, result[:ticket_ids][0])
- assert_equal(ticket6.id, result[:ticket_ids][1])
- assert_equal(ticket7.id, result[:ticket_ids][2])
- assert_equal(nil, result[:ticket_ids][3])
- # month - with selector #1
- result = Report::TicketFirstSolution.aggs(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- interval: 'month', # year, quarter, month, week, day, hour, minute, second
- selector: {
- 'ticket.priority_id' => {
- 'operator' => 'is',
- 'value' => [Ticket::Priority.lookup(name: '3 high').id],
- }
- }, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(1, result[9])
- assert_equal(0, result[10])
- assert_equal(0, result[11])
- assert_equal(nil, result[12])
- result = Report::TicketFirstSolution.items(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- selector: {
- 'ticket.priority_id' => {
- 'operator' => 'is',
- 'value' => [Ticket::Priority.lookup(name: '3 high').id],
- }
- }, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(ticket5.id, result[:ticket_ids][0])
- assert_equal(nil, result[:ticket_ids][1])
- # month - with selector #2
- result = Report::TicketFirstSolution.aggs(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- interval: 'month', # year, quarter, month, week, day, hour, minute, second
- selector: {
- 'ticket.priority_id' => {
- 'operator' => 'is not',
- 'value' => [Ticket::Priority.lookup(name: '3 high').id],
- }
- }, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(1, result[9])
- assert_equal(1, result[10])
- assert_equal(0, result[11])
- assert_equal(nil, result[12])
- result = Report::TicketFirstSolution.items(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- selector: {
- 'ticket.priority_id' => {
- 'operator' => 'is not',
- 'value' => [Ticket::Priority.lookup(name: '3 high').id],
- }
- }, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(ticket6.id, result[:ticket_ids][0])
- assert_equal(ticket7.id, result[:ticket_ids][1])
- assert_equal(nil, result[:ticket_ids][2])
- # week
- result = Report::TicketFirstSolution.aggs(
- range_start: '2015-10-26T00:00:00Z',
- range_end: '2015-10-31T23:59:59Z',
- interval: 'week', # year, quarter, month, week, day, hour, minute, second
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(1, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(1, result[5])
- assert_equal(1, result[6])
- assert_equal(nil, result[7])
- result = Report::TicketFirstSolution.items(
- range_start: '2015-10-26T00:00:00Z',
- range_end: '2015-11-01T23:59:59Z',
- interval: 'week', # year, quarter, month, week, day, hour, minute, second
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(ticket5.id, result[:ticket_ids][0])
- assert_equal(ticket6.id, result[:ticket_ids][1])
- assert_equal(ticket7.id, result[:ticket_ids][2])
- assert_equal(nil, result[:ticket_ids][3])
- # day
- result = Report::TicketFirstSolution.aggs(
- range_start: '2015-10-01T00:00:00Z',
- range_end: '2015-11-01T23:59:59Z',
- interval: 'day', # year, quarter, month, week, day, hour, minute, second
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(0, result[9])
- assert_equal(0, result[10])
- assert_equal(0, result[11])
- assert_equal(0, result[12])
- assert_equal(0, result[13])
- assert_equal(0, result[14])
- assert_equal(0, result[15])
- assert_equal(0, result[16])
- assert_equal(0, result[17])
- assert_equal(0, result[18])
- assert_equal(0, result[19])
- assert_equal(0, result[20])
- assert_equal(0, result[21])
- assert_equal(0, result[22])
- assert_equal(0, result[23])
- assert_equal(0, result[24])
- assert_equal(0, result[25])
- assert_equal(0, result[26])
- assert_equal(1, result[27])
- assert_equal(0, result[28])
- assert_equal(0, result[29])
- assert_equal(1, result[30])
- assert_equal(nil, result[31])
- result = Report::TicketFirstSolution.items(
- range_start: '2015-10-01T00:00:00Z',
- range_end: '2015-10-31T23:59:59Z',
- interval: 'day', # year, quarter, month, week, day, hour, minute, second
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(ticket5.id, result[:ticket_ids][0])
- assert_equal(ticket6.id, result[:ticket_ids][1])
- assert_equal(nil, result[:ticket_ids][2])
- # hour
- result = Report::TicketFirstSolution.aggs(
- range_start: '2015-10-28T00:00:00Z',
- range_end: '2015-10-28T23:59:59Z',
- interval: 'hour', # year, quarter, month, week, day, hour, minute, second
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(0, result[9])
- assert_equal(0, result[10])
- assert_equal(1, result[11])
- assert_equal(0, result[12])
- assert_equal(0, result[13])
- assert_equal(0, result[14])
- assert_equal(0, result[15])
- assert_equal(0, result[16])
- assert_equal(0, result[17])
- assert_equal(0, result[18])
- assert_equal(0, result[19])
- assert_equal(0, result[20])
- assert_equal(0, result[21])
- assert_equal(0, result[22])
- assert_equal(0, result[23])
- assert_equal(nil, result[24])
- result = Report::TicketFirstSolution.items(
- range_start: '2015-10-28T00:00:00Z',
- range_end: '2015-10-28T23:59:59Z',
- interval: 'hour', # year, quarter, month, week, day, hour, minute, second
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(ticket5.id, result[:ticket_ids][0])
- assert_equal(nil, result[:ticket_ids][1])
- # created by channel and direction
- end
- test 'b - reopen' do
- # month
- result = Report::TicketReopened.aggs(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- interval: 'month', # year, quarter, month, week, day, hour, minute, second
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(1, result[9])
- assert_equal(0, result[10])
- assert_equal(0, result[11])
- assert_equal(nil, result[12])
- result = Report::TicketReopened.items(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- selector: {}, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(ticket5.id, result[:ticket_ids][0])
- assert_equal(nil, result[:ticket_ids][1])
- # month - with selector #1
- result = Report::TicketReopened.aggs(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- interval: 'month', # year, quarter, month, week, day, hour, minute, second
- selector: {
- 'ticket.priority_id' => {
- 'operator' => 'is',
- 'value' => [Ticket::Priority.lookup(name: '3 high').id],
- }
- }, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(1, result[9])
- assert_equal(0, result[10])
- assert_equal(0, result[11])
- assert_equal(nil, result[12])
- result = Report::TicketReopened.items(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- selector: {
- 'ticket.priority_id' => {
- 'operator' => 'is',
- 'value' => [Ticket::Priority.lookup(name: '3 high').id],
- }
- }, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(ticket5.id, result[:ticket_ids][0])
- assert_equal(nil, result[:ticket_ids][1])
- # month - with selector #2
- result = Report::TicketReopened.aggs(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- interval: 'month', # year, quarter, month, week, day, hour, minute, second
- selector: {
- 'ticket.priority_id' => {
- 'operator' => 'is not',
- 'value' => [Ticket::Priority.lookup(name: '3 high').id],
- }
- }, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(0, result[9])
- assert_equal(0, result[10])
- assert_equal(0, result[11])
- assert_equal(nil, result[12])
- result = Report::TicketReopened.items(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- selector: {
- 'ticket.priority_id' => {
- 'operator' => 'is not',
- 'value' => [Ticket::Priority.lookup(name: '3 high').id],
- }
- }, # ticket selector to get only a collection of tickets
- )
- assert(result)
- assert_equal(nil, result[:ticket_ids][0])
- end
- test 'c - move in/out' do
- # month
- result = Report::TicketMoved.aggs(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- interval: 'month', # year, quarter, month, week, day, hour, minute, second
- selector: {
- 'ticket.group_id' => {
- 'operator' => 'is',
- 'value' => [Group.lookup(name: 'Users').id],
- }
- }, # ticket selector to get only a collection of tickets
- params: {
- type: 'in',
- },
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(1, result[9])
- assert_equal(0, result[10])
- assert_equal(0, result[11])
- assert_equal(nil, result[12])
- result = Report::TicketMoved.items(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- selector: {
- 'ticket.group_id' => {
- 'operator' => 'is',
- 'value' => [Group.lookup(name: 'Users').id],
- }
- }, # ticket selector to get only a collection of tickets
- params: {
- type: 'in',
- },
- )
- assert(result)
- assert_equal(ticket1.id, result[:ticket_ids][0])
- assert_equal(nil, result[:ticket_ids][1])
- # out
- result = Report::TicketMoved.aggs(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- interval: 'month', # year, quarter, month, week, day, hour, minute, second
- selector: {
- 'ticket.group_id' => {
- 'operator' => 'is',
- 'value' => [Group.lookup(name: 'Users').id],
- }
- }, # ticket selector to get only a collection of tickets
- params: {
- type: 'out',
- },
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(1, result[9])
- assert_equal(0, result[10])
- assert_equal(0, result[11])
- assert_equal(nil, result[12])
- result = Report::TicketMoved.items(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- selector: {
- 'ticket.group_id' => {
- 'operator' => 'is',
- 'value' => [Group.lookup(name: 'Users').id],
- }
- }, # ticket selector to get only a collection of tickets
- params: {
- type: 'out',
- },
- )
- assert(result)
- assert_equal(ticket2.id, result[:ticket_ids][0])
- assert_equal(nil, result[:ticket_ids][1])
- end
- test 'd - created at' do
- # month
- result = Report::TicketGenericTime.aggs(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- interval: 'month', # year, quarter, month, week, day, hour, minute, second
- selector: {}, # ticket selector to get only a collection of tickets
- params: { field: 'created_at' },
- )
- assert(result)
- assert_equal(0, result[0])
- assert_equal(0, result[1])
- assert_equal(0, result[2])
- assert_equal(0, result[3])
- assert_equal(0, result[4])
- assert_equal(0, result[5])
- assert_equal(0, result[6])
- assert_equal(0, result[7])
- assert_equal(0, result[8])
- assert_equal(6, result[9])
- assert_equal(1, result[10])
- assert_equal(0, result[11])
- assert_equal(nil, result[12])
- result = Report::TicketGenericTime.items(
- range_start: '2015-01-01T00:00:00Z',
- range_end: '2015-12-31T23:59:59Z',
- selector: {}, # ticket selector to get only a collection of tickets
- params: { field: 'created_at' },
- )
- assert(result)
- assert_equal(ticket7.id, result[:ticket_ids][0].to_i)
- assert_equal(ticket6.id, result[:ticket_ids][1].to_i)
- assert_equal(ticket5.id, result[:ticket_ids][2].to_i)
- assert_equal(ticket3.id, result[:ticket_ids][3].to_i)
- assert_equal(ticket4.id, result[:ticket_ids][4].to_i)
- assert_equal(ticket2.id, result[:ticket_ids][5].to_i)
- assert_equal(ticket1.id, result[:ticket_ids][6].to_i)
- assert_equal(nil, result[:ticket_ids][7])
- # cleanup
- system('rake searchindex:drop')
- end
- end
|