Fixed issue #2089 - timezone issue with report graphs not displaying or displaying $timezone hours out of step.

This commit is contained in:
Martin Edenhofer 2019-03-26 01:17:17 +01:00
parent a1bb61bf56
commit f72b44234e
22 changed files with 730 additions and 480 deletions

View file

@ -186,7 +186,7 @@ class Graph extends App.ControllerContent
xaxis.push [minute, '']
else if @params.timeRange is 'day'
for hour in [0..23]
xaxis.push [hour, hour+1]
xaxis.push [hour, hour]
else if @params.timeRange is 'month'
for day in [0..30]
xaxis.push [day, day+1]

View file

@ -32,29 +32,16 @@ class ReportsController < ApplicationController
next if !backend[:adapter]
result[backend[:name]] = backend[:adapter].aggs(
range_start: get_params[:start],
range_end: get_params[:stop],
interval: get_params[:range],
selector: backend[:condition],
params: backend[:params],
range_start: get_params[:start],
range_end: get_params[:stop],
interval: get_params[:range],
selector: backend[:condition],
params: backend[:params],
timezone: get_params[:timezone],
timezone_offset: get_params[:timezone_offset],
)
end
#created = aggs(start, stop, range, 'created_at', profile.condition)
#closed = aggs(start, stop, range, 'close_at', profile.condition)
#first_solution =
#reopend = backend(start, stop, range, Report::TicketReopened, profile.condition)
# add backlog
#backlogs = []
#position = -1
#created.each {|_not_used|
# position += 1
# diff = created[position][1] - closed[position][1]
# backlog = [position+1, diff]
# backlogs.push backlog
#}
render json: {
data: result
}
@ -86,12 +73,14 @@ class ReportsController < ApplicationController
next if !backend[:adapter]
result = backend[:adapter].items(
range_start: get_params[:start],
range_end: get_params[:stop],
interval: get_params[:range],
selector: backend[:condition],
params: backend[:params],
sheet: params[:sheet],
range_start: get_params[:start],
range_end: get_params[:stop],
interval: get_params[:range],
selector: backend[:condition],
params: backend[:params],
sheet: params[:sheet],
timezone: get_params[:timezone],
timezone_offset: get_params[:timezone_offset],
)
result = { count: 0, ticket_ids: [] } if result.nil?
@ -138,36 +127,46 @@ class ReportsController < ApplicationController
metric = local_config[:metric][params[:metric].to_sym]
#{"metric"=>"count", "year"=>2015, "month"=>10, "week"=>43, "day"=>20, "timeSlot"=>"year", "report"=>{"metric"=>"count", "year"=>2015, "month"=>10, "week"=>43, "day"=>20, "timeSlot"=>"year"}}
if params[:timeRange] == 'realtime'
start = (Time.zone.now - 60.minutes).iso8601
stop = Time.zone.now.iso8601
start_at = (Time.zone.now - 60.minutes)
stop_at = Time.zone.now
range = 'minute'
elsif params[:timeRange] == 'day'
date = Date.parse("#{params[:year]}-#{params[:month]}-#{params[:day]}").to_s
start = "#{date}T00:00:00Z"
stop = "#{date}T23:59:59Z"
start_at = Time.zone.parse("#{date}T00:00:00Z")
stop_at = Time.zone.parse("#{date}T23:59:59Z")
range = 'hour'
elsif params[:timeRange] == 'week'
start = Date.commercial(params[:year].to_i, params[:week].to_i).iso8601
stop = Date.parse(start).end_of_week.iso8601
start_week_at = Date.commercial(params[:year].to_i, params[:week].to_i)
stop_week_at = start_week_at.end_of_week
start_at = Time.zone.parse("#{start_week_at.year}-#{start_week_at.month}-#{start_week_at.day}T00:00:00Z")
stop_at = Time.zone.parse("#{stop_week_at.year}-#{stop_week_at.month}-#{stop_week_at.day}T23:59:59Z")
range = 'week'
elsif params[:timeRange] == 'month'
start = Date.parse("#{params[:year]}-#{params[:month]}-01}").iso8601
stop = Date.parse(start).end_of_month.iso8601
start_at = Time.zone.parse("#{params[:year]}-#{params[:month]}-01T00:00:00Z")
stop_at = Time.zone.parse("#{params[:year]}-#{params[:month]}-#{start_at.end_of_month.day}T23:59:59Z")
range = 'day'
else
start = "#{params[:year]}-01-01"
stop = Date.parse("#{params[:year]}-12-31").iso8601
start_at = Time.zone.parse("#{params[:year]}-01-01T00:00:00Z")
stop_at = Time.zone.parse("#{params[:year]}-12-31T23:59:59Z")
range = 'month'
end
params[:timezone] ||= Setting.get('timezone_default')
if params[:timezone].present? && params[:timeRange] != 'realtime'
offset = stop_at.in_time_zone(params[:timezone]).utc_offset
start_at -= offset
stop_at -= offset
end
{
profile: profile,
metric: metric,
config: local_config,
start: start,
stop: stop,
range: range,
profile: profile,
metric: metric,
config: local_config,
start: start_at,
stop: stop_at,
range: range,
timezone: params[:timezone],
timezone_offset: offset,
}
end

View file

@ -40,6 +40,12 @@ class SearchController < ApplicationController
objects_in_order.push objects_in_order_hash[prio]
end
generic_search_params = {
query: query,
limit: limit,
current_user: current_user,
}
# try search index backend
assets = {}
result = []
@ -76,7 +82,7 @@ class SearchController < ApplicationController
# e. g. do ticket query by Ticket class to handle ticket permissions
objects_without_direct_search_index.each do |object|
object_result = search_generic_backend(object.constantize, query, limit, current_user, assets)
object_result = search_generic_backend(object.constantize, assets, generic_search_params)
if object_result.present?
result = result.concat(object_result)
end
@ -98,7 +104,7 @@ class SearchController < ApplicationController
# do query
objects_in_order.each do |object|
object_result = search_generic_backend(object, query, limit, current_user, assets)
object_result = search_generic_backend(object, assets, generic_search_params)
if object_result.present?
result = result.concat(object_result)
end
@ -113,12 +119,22 @@ class SearchController < ApplicationController
private
def search_generic_backend(object, query, limit, current_user, assets)
found_objects = object.search(
query: query,
limit: limit,
current_user: current_user,
)
=begin
search generic backend
SearchController#search_generic_backend(
Ticket, # object
{}, # assets
query: "search query",
limit: 10,
current_user: user,
)
=end
def search_generic_backend(object, assets, params)
found_objects = object.search(params)
result = []
found_objects.each do |found_object|
item = {

View file

@ -482,7 +482,7 @@ class TicketsController < ApplicationController
def selector
permission_check('admin.*')
ticket_count, tickets = Ticket.selectors(params[:condition], 6)
ticket_count, tickets = Ticket.selectors(params[:condition], limit: 6)
assets = {}
ticket_ids = []

View file

@ -26,7 +26,7 @@ module ChecksConditionValidation
value: 1,
}
ticket_count, tickets = Ticket.selectors(validate_condition, 1, User.find(1))
ticket_count, tickets = Ticket.selectors(validate_condition, limit: 1, current_user: User.find(1))
return true if ticket_count.present?
raise Exceptions::UnprocessableEntity, 'Invalid ticket selector conditions'

View file

@ -72,7 +72,7 @@ job.run(true)
end
# find tickets to change
ticket_count, tickets = Ticket.selectors(condition, 2_000)
ticket_count, tickets = Ticket.selectors(condition, limit: 2_000)
logger.debug { "Job #{name} with #{ticket_count} tickets" }
@ -135,7 +135,7 @@ job.run(true)
end
def matching_count
ticket_count, tickets = Ticket.selectors(condition, 1)
ticket_count, tickets = Ticket.selectors(condition, limit: 1)
ticket_count || 0
end

View file

@ -424,14 +424,17 @@ returns
get count of tickets and tickets which match on selector
ticket_count, tickets = Ticket.selectors(params[:condition], limit, current_user, 'full')
ticket_count, tickets = Ticket.selectors(params[:condition], limit: limit, current_user: current_user, access: 'full')
=end
def self.selectors(selectors, limit = 10, current_user = nil, access = 'full')
def self.selectors(selectors, options)
limit = options[:limit] || 10
current_user = options[:current_user]
access = options[:access] || 'full'
raise 'no selectors given' if !selectors
query, bind_params, tables = selector2sql(selectors, current_user)
query, bind_params, tables = selector2sql(selectors, current_user: current_user)
return [] if !query
ActiveRecord::Base.transaction(requires_new: true) do
@ -459,7 +462,7 @@ get count of tickets and tickets which match on selector
generate condition query to search for tickets based on condition
query_condition, bind_condition, tables = selector2sql(params[:condition], current_user)
query_condition, bind_condition, tables = selector2sql(params[:condition], current_user: current_user)
condition example
@ -502,7 +505,8 @@ condition example
=end
def self.selector2sql(selectors, current_user = nil)
def self.selector2sql(selectors, options = {})
current_user = options[:current_user]
current_user_id = UserInfo.current_user_id
if current_user
current_user_id = current_user.id
@ -1102,7 +1106,7 @@ perform active triggers on ticket
end
# verify is condition is matching
ticket_count, tickets = Ticket.selectors(condition, 1)
ticket_count, tickets = Ticket.selectors(condition, limit: 1)
next if ticket_count.blank?
next if ticket_count.zero?

View file

@ -87,7 +87,7 @@ returns
ticket_attributes = Ticket.new.attributes
list = []
overviews.each do |overview|
query_condition, bind_condition, tables = Ticket.selector2sql(overview.condition, user)
query_condition, bind_condition, tables = Ticket.selector2sql(overview.condition, current_user: user)
direction = overview.order[:direction]
order_by = overview.order[:by]

View file

@ -3,8 +3,8 @@ class Report::ArticleByTypeSender < Report::Base
=begin
result = Report::ArticleByTypeSender.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # quarter, month, week, day, hour, minute, second
selector: selector, # ticket selector to get only a collection of tickets
params: {
@ -19,7 +19,8 @@ returns
=end
def self.aggs(params)
def self.aggs(params_origin)
params = params_origin.dup
interval = params[:interval]
if params[:interval] == 'week'
@ -28,32 +29,27 @@ returns
result = []
if params[:interval] == 'month'
start = Date.parse(params[:range_start])
stop_interval = 12
elsif params[:interval] == 'week'
start = Date.parse(params[:range_start])
stop_interval = 7
elsif params[:interval] == 'day'
start = Date.parse(params[:range_start])
stop_interval = 31
elsif params[:interval] == 'hour'
start = Time.zone.parse(params[:range_start])
stop_interval = 24
elsif params[:interval] == 'minute'
start = Time.zone.parse(params[:range_start])
stop_interval = 60
end
(1..stop_interval).each do |_counter|
if params[:interval] == 'month'
stop = start.next_month
params[:range_end] = params[:range_start].next_month
elsif params[:interval] == 'week'
stop = start.next_day
params[:range_end] = params[:range_start].next_day
elsif params[:interval] == 'day'
stop = start.next_day
params[:range_end] = params[:range_start].next_day
elsif params[:interval] == 'hour'
stop = start + 1.hour
params[:range_end] = params[:range_start] + 1.hour
elsif params[:interval] == 'minute'
stop = start + 1.minute
params[:range_end] = params[:range_start] + 1.minute
end
query, bind_params, tables = Ticket.selector2sql(params[:selector])
sender = Ticket::Article::Sender.lookup(name: params[:params][:sender])
@ -62,13 +58,13 @@ returns
.where(query, *bind_params).joins(tables)
.where(
'ticket_articles.created_at >= ? AND ticket_articles.created_at <= ? AND ticket_articles.type_id = ? AND ticket_articles.sender_id = ?',
start,
stop,
params[:range_start],
params[:range_end],
type.id,
sender.id,
).count
result.push count
start = stop
params[:range_start] = params[:range_end]
end
result
end
@ -76,8 +72,8 @@ returns
=begin
result = Report::ArticleByTypeSender.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: selector, # ticket selector to get only a collection of tickets
selector: selector, # ticket selector to get only a collection of tickets
params: {

View file

@ -16,7 +16,7 @@ class Report::Base
# created
if params[:type] == 'created'
history_type = History::Type.lookup( name: 'created' )
history_type = History::Type.lookup(name: 'created')
return History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
.where(
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', params[:start], params[:end], history_object.id, history_type.id
@ -26,8 +26,8 @@ class Report::Base
# updated
if params[:type] == 'updated'
history_type = History::Type.lookup( name: 'updated' )
history_attribute = History::Attribute.lookup( name: params[:attribute] )
history_type = History::Type.lookup(name: 'updated')
history_attribute = History::Attribute.lookup(name: params[:attribute])
result = nil
if !history_attribute || !history_type
@ -114,7 +114,7 @@ class Report::Base
# :condition
def self.history(data)
history_object = History::Object.lookup( name: data[:object] )
history_object = History::Object.lookup(name: data[:object])
query, bind_params, tables = Ticket.selector2sql(data[:selector])
@ -123,7 +123,7 @@ class Report::Base
# created
if data[:type] == 'created'
history_type = History::Type.lookup( name: 'created' )
history_type = History::Type.lookup(name: 'created')
histories = History.select('histories.o_id').joins('INNER JOIN tickets ON tickets.id = histories.o_id')
.where(
'histories.created_at >= ? AND histories.created_at <= ? AND histories.history_object_id = ? AND histories.history_type_id = ?', data[:start], data[:end], history_object.id, history_type.id
@ -141,8 +141,8 @@ class Report::Base
# updated
if data[:type] == 'updated'
history_type = History::Type.lookup( name: 'updated' )
history_attribute = History::Attribute.lookup( name: data[:attribute] )
history_type = History::Type.lookup(name: 'updated')
history_attribute = History::Attribute.lookup(name: data[:attribute])
if !history_attribute || !history_type
count = 0
else
@ -229,7 +229,7 @@ class Report::Base
# :condition
def self.time_average(data)
query, bind_params, tables = Ticket.selector2sql(data[:condition])
ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] )
ticket_list = Ticket.where('tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end])
.where(query, *bind_params).joins(tables)
tickets = 0
time_total = 0
@ -261,7 +261,7 @@ class Report::Base
# :condition
def self.time_min(data)
query, bind_params, tables = Ticket.selector2sql(data[:condition])
ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] )
ticket_list = Ticket.where('tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end])
.where(query, *bind_params).joins(tables)
tickets = 0
time_min = 0
@ -299,7 +299,7 @@ class Report::Base
# :condition
def self.time_max(data)
query, bind_params, tables = Ticket.selector2sql(data[:condition])
ticket_list = Ticket.where( 'tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end] )
ticket_list = Ticket.where('tickets.created_at >= ? AND tickets.created_at <= ?', data[:start], data[:end])
.where(query, *bind_params).joins(tables)
tickets = 0
time_max = 0

View file

@ -3,10 +3,11 @@ class Report::TicketBacklog < Report::Base
=begin
result = Report::TicketBacklog.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # quarter, month, week, day, hour, minute, second
selector: selector, # ticket selector to get only a collection of tickets
timezone: 'Europe/Berlin',
)
returns
@ -15,7 +16,8 @@ returns
=end
def self.aggs(params)
def self.aggs(params_origin)
params = params_origin.dup
local_params = params.clone
local_params[:params] = {}
@ -37,8 +39,8 @@ returns
=begin
result = Report::TicketBacklog.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: selector, # ticket selector to get only a collection of tickets
)

View file

@ -3,8 +3,8 @@ class Report::TicketFirstSolution
=begin
result = Report::TicketFirstSolution.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # quarter, month, week, day, hour, minute, second
selector: selector, # ticket selector to get only a collection of tickets
)
@ -15,7 +15,8 @@ returns
=end
def self.aggs(params)
def self.aggs(params_origin)
params = params_origin.dup
interval = params[:interval]
if params[:interval] == 'week'
interval = 'day'
@ -23,32 +24,27 @@ returns
result = []
if params[:interval] == 'month'
start = Date.parse(params[:range_start])
stop_interval = 12
elsif params[:interval] == 'week'
start = Date.parse(params[:range_start])
stop_interval = 7
elsif params[:interval] == 'day'
start = Date.parse(params[:range_start])
stop_interval = 31
elsif params[:interval] == 'hour'
start = Time.zone.parse(params[:range_start])
stop_interval = 24
elsif params[:interval] == 'minute'
start = Time.zone.parse(params[:range_start])
stop_interval = 60
end
(1..stop_interval).each do |_counter|
if params[:interval] == 'month'
stop = start.next_month
params[:range_end] = params[:range_start].next_month
elsif params[:interval] == 'week'
stop = start.next_day
params[:range_end] = params[:range_start].next_day
elsif params[:interval] == 'day'
stop = start.next_day
params[:range_end] = params[:range_start].next_day
elsif params[:interval] == 'hour'
stop = start + 1.hour
params[:range_end] = params[:range_start] + 1.hour
elsif params[:interval] == 'minute'
stop = start + 1.minute
params[:range_end] = params[:range_start] + 1.minute
end
without_merged_tickets = {
@ -61,8 +57,8 @@ returns
query, bind_params, tables = Ticket.selector2sql(params[:selector])
ticket_list = Ticket.select('tickets.id, tickets.close_at, tickets.created_at').where(
'tickets.close_at IS NOT NULL AND tickets.close_at >= ? AND tickets.close_at < ?',
start,
stop,
params[:range_start],
params[:range_end],
).where(query, *bind_params).joins(tables)
count = 0
ticket_list.each do |ticket|
@ -73,7 +69,7 @@ returns
end
end
result.push count
start = stop
params[:range_start] = params[:range_end]
end
result
end
@ -81,9 +77,10 @@ returns
=begin
result = Report::TicketFirstSolution.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: selector, # ticket selector to get only a collection of tickets
timezone: 'Europe/Berlin',
)
returns

View file

@ -3,11 +3,12 @@ class Report::TicketGenericTime
=begin
result = Report::TicketGenericTime.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: selector, # ticket selector to get only a collection of tickets
params: { field: 'created_at', selector: selector_sub },
timezone: 'Europe/Berlin',
)
returns
@ -16,17 +17,19 @@ returns
=end
def self.aggs(params)
def self.aggs(params_origin)
params = params_origin.dup
interval_es = params[:interval]
if params[:interval] == 'week'
interval_es = 'day'
end
aggs_interval = {
from: params[:range_start],
to: params[:range_end],
from: params[:range_start].iso8601,
to: params[:range_end].iso8601,
interval: interval_es, # year, quarter, month, week, day, hour, minute, second
field: params[:params][:field],
timezone: params[:timezone],
}
without_merged_tickets = {
@ -42,22 +45,16 @@ returns
end
selector.merge!(without_merged_tickets) # do not show merged tickets in reports
result_es = SearchIndexBackend.selectors(['Ticket'], selector, nil, nil, aggs_interval)
result_es = SearchIndexBackend.selectors(['Ticket'], selector, {}, aggs_interval)
if params[:interval] == 'month'
start = Date.parse(params[:range_start])
stop_interval = 12
elsif params[:interval] == 'week'
start = Date.parse(params[:range_start])
stop_interval = 7
elsif params[:interval] == 'day'
start = Date.parse(params[:range_start])
stop_interval = 31
stop_interval = ((params[:range_end] - params[:range_start]) / 86_400).to_i + 1
elsif params[:interval] == 'hour'
start = Time.zone.parse(params[:range_start])
stop_interval = 24
elsif params[:interval] == 'minute'
start = Time.zone.parse(params[:range_start])
stop_interval = 60
end
result = []
@ -77,43 +74,51 @@ returns
end
result_es['aggregations']['time_buckets']['buckets'].each do |item|
if params[:interval] == 'minute'
item['key_as_string'] = item['key_as_string'].sub(/:\d\d.\d\d\dZ$/, '')
start_string = start.iso8601.sub(/:\d\dZ$/, '')
else
start_string = start.iso8601.sub(/:\d\d:\d\d.+?$/, '')
end
key_as_string = Time.zone.parse(item['key_as_string'])
next if !item['doc_count']
next if item['key_as_string'] !~ /#{start_string}/
next if item['doc_count'].zero?
# only compare date - in certain cases elasticsearch timezone offset will not match
replace = ':\d\dZ$'
if params[:interval] == 'month'
replace = '\d\dT\d\d:\d\d:\d\dZ$'
elsif params[:interval] == 'day' || params[:interval] == 'week'
replace = '\d\d:\d\d:\d\dZ$'
end
Rails.logger.error '-----'
Rails.logger.error item
Rails.logger.error params[:range_start].iso8601.sub(/#{replace}/, '')
next if key_as_string.iso8601.sub(/#{replace}/, '') != params[:range_start].iso8601.sub(/#{replace}/, '')
next if match
match = true
result.push item['doc_count']
if params[:interval] == 'month'
start = start.next_month
params[:range_start] = params[:range_start].next_month
elsif params[:interval] == 'week'
start = start.next_day
params[:range_start] = params[:range_start].next_day
elsif params[:interval] == 'day'
start = start.next_day
params[:range_start] = params[:range_start].next_day
elsif params[:interval] == 'hour'
start = start + 1.hour
params[:range_start] = params[:range_start] + 1.hour
elsif params[:interval] == 'minute'
start = start + 1.minute
params[:range_start] = params[:range_start] + 1.minute
end
end
next if match
result.push 0
if params[:interval] == 'month'
start = start.next_month
params[:range_start] = params[:range_start].next_month
elsif params[:interval] == 'week'
start = start.next_day
params[:range_start] = params[:range_start].next_day
elsif params[:interval] == 'day'
start = start + 1.day
params[:range_start] = params[:range_start] + 1.day
elsif params[:interval] == 'hour'
start = start + 1.hour
params[:range_start] = params[:range_start] + 1.hour
elsif params[:interval] == 'minute'
start = start + 1.minute
params[:range_start] = params[:range_start] + 1.minute
end
end
result
@ -122,8 +127,8 @@ returns
=begin
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: selector, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
@ -141,8 +146,8 @@ returns
def self.items(params)
aggs_interval = {
from: params[:range_start],
to: params[:range_end],
from: params[:range_start].iso8601,
to: params[:range_end].iso8601,
field: params[:params][:field],
}
@ -164,7 +169,7 @@ returns
end
selector.merge!(without_merged_tickets) # do not show merged tickets in reports
result = SearchIndexBackend.selectors(['Ticket'], selector, limit, nil, aggs_interval)
result = SearchIndexBackend.selectors(['Ticket'], selector, { limit: limit }, aggs_interval)
return result if params[:sheet].present?
assets = {}

View file

@ -3,11 +3,12 @@ class Report::TicketMoved < Report::Base
=begin
result = Report::TicketMoved.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # quarter, month, week, day, hour, minute, second
selector: selector, # ticket selector to get only a collection of tickets
params: { type: 'in' }, # in|out
timezone: 'Europe/Berlin',
)
returns
@ -16,7 +17,8 @@ returns
=end
def self.aggs(params)
def self.aggs(params_origin)
params = params_origin.dup
selector = params[:selector]['ticket.group_id']
@ -31,32 +33,27 @@ returns
result = []
if params[:interval] == 'month'
start = Date.parse(params[:range_start])
stop_interval = 12
elsif params[:interval] == 'week'
start = Date.parse(params[:range_start])
stop_interval = 7
elsif params[:interval] == 'day'
start = Date.parse(params[:range_start])
stop_interval = 31
elsif params[:interval] == 'hour'
start = Time.zone.parse(params[:range_start])
stop_interval = 24
elsif params[:interval] == 'minute'
start = Time.zone.parse(params[:range_start])
stop_interval = 60
end
(1..stop_interval).each do |_counter|
if params[:interval] == 'month'
stop = start.next_month
params[:range_end] = params[:range_start].next_month
elsif params[:interval] == 'week'
stop = start.next_day
params[:range_end] = params[:range_start].next_day
elsif params[:interval] == 'day'
stop = start.next_day
params[:range_end] = params[:range_start].next_day
elsif params[:interval] == 'hour'
stop = start + 1.hour
params[:range_end] = params[:range_start] + 1.hour
elsif params[:interval] == 'minute'
stop = start + 1.minute
params[:range_end] = params[:range_start] + 1.minute
end
local_params = group_attributes(selector, params)
local_selector = params[:selector].clone
@ -74,14 +71,14 @@ returns
object: 'Ticket',
type: 'updated',
attribute: 'group',
start: start,
end: stop,
start: params[:range_start],
end: params[:range_end],
selector: local_selector
}
local_params = defaults.merge(local_params)
count = history_count(local_params)
result.push count
start = stop
params[:range_start] = params[:range_end]
end
result
end
@ -89,8 +86,8 @@ returns
=begin
result = Report::TicketMoved.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: selector, # ticket selector to get only a collection of tickets
params: { type: 'in' }, # in|out
)

View file

@ -3,10 +3,11 @@ class Report::TicketReopened < Report::Base
=begin
result = Report::TicketReopened.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # quarter, month, week, day, hour, minute, second
selector: selector, # ticket selector to get only a collection of tickets
timezone: 'Europe/Berlin',
)
returns
@ -15,7 +16,8 @@ returns
=end
def self.aggs(params)
def self.aggs(params_origin)
params = params_origin.dup
ticket_state_ids = ticket_ids
interval = params[:interval]
@ -25,32 +27,27 @@ returns
result = []
if params[:interval] == 'month'
start = Date.parse(params[:range_start])
stop_interval = 12
elsif params[:interval] == 'week'
start = Date.parse(params[:range_start])
stop_interval = 7
elsif params[:interval] == 'day'
start = Date.parse(params[:range_start])
stop_interval = 31
elsif params[:interval] == 'hour'
start = Time.zone.parse(params[:range_start])
stop_interval = 24
elsif params[:interval] == 'minute'
start = Time.zone.parse(params[:range_start])
stop_interval = 60
end
(1..stop_interval).each do |_counter|
if params[:interval] == 'month'
stop = start.next_month
params[:range_end] = params[:range_start].next_month
elsif params[:interval] == 'week'
stop = start.next_day
params[:range_end] = params[:range_start].next_day
elsif params[:interval] == 'day'
stop = start.next_day
params[:range_end] = params[:range_start].next_day
elsif params[:interval] == 'hour'
stop = start + 1.hour
params[:range_end] = params[:range_start] + 1.hour
elsif params[:interval] == 'minute'
stop = start + 1.minute
params[:range_end] = params[:range_start] + 1.minute
end
without_merged_tickets = {
@ -66,12 +63,12 @@ returns
attribute: 'state',
id_from: ticket_state_ids,
id_not_to: ticket_state_ids,
start: start,
end: stop,
start: params[:range_start],
end: params[:range_end],
selector: params[:selector]
)
result.push count
start = stop
params[:range_start] = params[:range_end]
end
result
end
@ -79,9 +76,10 @@ returns
=begin
result = Report::TicketReopened.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: selector, # ticket selector to get only a collection of tickets
timezone: 'Europe/Berlin',
)
returns
@ -119,17 +117,17 @@ returns
def self.ticket_ids
key = 'Report::TicketReopened::StateList'
ticket_state_ids = Cache.get( key )
ticket_state_ids = Cache.get(key)
return ticket_state_ids if ticket_state_ids
ticket_state_types = Ticket::StateType.where( name: %w[closed merged removed] )
ticket_state_types = Ticket::StateType.where(name: %w[closed merged removed])
ticket_state_ids = []
ticket_state_types.each do |ticket_state_type|
ticket_state_type.states.each do |ticket_state|
ticket_state_ids.push ticket_state.id
end
end
Cache.write( key, ticket_state_ids, { expires_in: 2.days } )
Cache.write(key, ticket_state_ids, { expires_in: 2.days })
ticket_state_ids
end
end

View file

@ -442,7 +442,12 @@ get count of tickets and tickets which match on selector
field: 'created_at',
}
result = SearchIndexBackend.selectors(index, params[:condition], limit, current_user, aggs_interval)
options = {
limit: 123,
current_user: User.find(123),
}
result = SearchIndexBackend.selectors(index, selector, options, aggs_interval)
# for aggregations
result = {
@ -470,7 +475,7 @@ get count of tickets and tickets which match on selector
=end
def self.selectors(index = nil, selectors = nil, limit = 10, current_user = nil, aggs_interval = nil)
def self.selectors(index = nil, selectors = nil, options = {}, aggs_interval = nil)
raise 'no selectors given' if !selectors
url = build_url
@ -486,7 +491,7 @@ get count of tickets and tickets which match on selector
'/_search'
end
data = selector2query(selectors, current_user, aggs_interval, limit)
data = selector2query(selectors, options, aggs_interval)
Rails.logger.info "# curl -X POST \"#{url}\" \\"
Rails.logger.debug { " -d'#{data.to_json}'" }
@ -527,7 +532,13 @@ get count of tickets and tickets which match on selector
response.data
end
def self.selector2query(selector, _current_user, aggs_interval, limit)
DEFAULT_SELECTOR_OPTIONS = {
limit: 10
}.freeze
def self.selector2query(selector, options, aggs_interval)
options = DEFAULT_QUERY_OPTIONS.merge(options.deep_symbolize_keys)
query_must = []
query_must_not = []
relative_map = {
@ -622,9 +633,8 @@ get count of tickets and tickets which match on selector
end
data = {
query: {},
size: limit,
size: options[:limit],
}
# add aggs to filter
if aggs_interval.present?
if aggs_interval[:interval].present?
@ -637,6 +647,9 @@ get count of tickets and tickets which match on selector
}
}
}
if aggs_interval[:timezone].present?
data[:aggs][:time_buckets][:date_histogram][:time_zone] = aggs_interval[:timezone]
end
end
r = {}
r[:range] = {}

View file

@ -29,8 +29,8 @@ returns
expect do
described_class.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)

View file

@ -39,7 +39,7 @@ RSpec.describe Ticket, type: :model do
end
it 'returns a list of unique tickets (i.e., no duplicates)' do
expect(Ticket.selectors(condition, 100, nil, 'full'))
expect(Ticket.selectors(condition, limit: 100, access: 'full'))
.to match_array([2, tickets])
end
end

View file

@ -5,12 +5,6 @@ RSpec.describe 'Report', type: :request, searchindex: true do
let!(:admin_user) do
create(:admin_user)
end
let!(:agent_user) do
create(:agent_user)
end
let!(:customer_user) do
create(:customer_user)
end
let!(:year) do
DateTime.now.utc.year
end
@ -23,11 +17,29 @@ RSpec.describe 'Report', type: :request, searchindex: true do
let!(:day) do
DateTime.now.utc.day
end
let!(:ticket) do
create(:ticket, title: 'ticket for report', customer: customer_user)
let!(:today) do
Time.zone.parse('2019-03-15T08:00:00Z')
end
let!(:article) do
create(:ticket_article, ticket_id: ticket.id, type: Ticket::Article::Type.lookup(name: 'note') )
let!(:backends) do
{
'count::created': true,
'count::closed': true,
'count::backlog': true,
'create_channels::phone_in': true,
'create_channels::phone_out': true,
'create_channels::email_in': true,
'create_channels::email_out': true,
'create_channels::web_in': true,
'create_channels::twitter_in': true,
'create_channels::twitter_out': true,
'communication::phone_in': true,
'communication::phone_out': true,
'communication::email_in': true,
'communication::email_out': true,
'communication::web_in': true,
'communication::twitter_in': true,
'communication::twitter_out': true
}
end
before(:each) do
@ -35,6 +47,19 @@ RSpec.describe 'Report', type: :request, searchindex: true do
travel 1.minute
travel_to today.midday
Ticket.destroy_all
create(:ticket, title: 'ticket for report #1', created_at: today.midday)
create(:ticket, title: 'ticket for report #2', created_at: today.midday + 2.hours)
create(:ticket, title: 'ticket for report #3', created_at: today.midday + 2.hours)
create(:ticket, title: 'ticket for report #4', created_at: today.midday + 10.hours, state: Ticket::State.lookup(name: 'closed') )
create(:ticket, title: 'ticket for report #5', created_at: today.midday + 11.hours)
create(:ticket, title: 'ticket for report #6', created_at: today.midday - 11.hours)
create(:ticket, title: 'ticket for report #7', created_at: Time.zone.parse('2019-02-28T23:30:00Z'))
create(:ticket, title: 'ticket for report #8', created_at: Time.zone.parse('2019-03-01T00:30:00Z'))
create(:ticket, title: 'ticket for report #9', created_at: Time.zone.parse('2019-03-31T23:30:00Z'))
create(:ticket, title: 'ticket for report #10', created_at: Time.zone.parse('2019-04-01T00:30:00Z'))
rebuild_searchindex
# execute background jobs
@ -55,5 +80,203 @@ RSpec.describe 'Report', type: :request, searchindex: true do
expect(@response['Content-Disposition']).to eq('attachment; filename="tickets--all--Created.xls"')
expect(@response['Content-Type']).to eq('application/vnd.ms-excel')
end
it 'does report example - deliver result' do
skip('No ES configured') if !SearchIndexBackend.enabled?
authenticated_as(admin_user)
# 2019-03-15 - day interval
params = {
metric: 'count',
year: today.year,
month: today.month,
day: today.day,
timeRange: 'day',
profiles: {
1 => true
},
backends: backends
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1])
Setting.set('timezone_default', 'Europe/Berlin')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1])
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'Australia/Melbourne')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
# 2019-03 - month interval
Setting.set('timezone_default', '')
params = {
metric: 'count',
year: today.year,
month: today.month,
timeRange: 'month',
profiles: {
1 => true
},
backends: backends
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
Setting.set('timezone_default', 'Europe/Berlin')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
Setting.set('timezone_default', 'Australia/Melbourne')
post '/api/v1/reports/generate', params: params, as: :json
expect(json_response['data']['count::created']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
# 2019-02 - month interval
Setting.set('timezone_default', '')
params = {
metric: 'count',
year: today.year,
month: today.month - 1,
timeRange: 'month',
profiles: {
1 => true
},
backends: backends
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
Setting.set('timezone_default', 'Europe/Berlin')
post '/api/v1/reports/generate', params: params, as: :json
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
Setting.set('timezone_default', 'Australia/Melbourne')
post '/api/v1/reports/generate', params: params, as: :json
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
# 2019-04 - month interval
Setting.set('timezone_default', '')
params = {
metric: 'count',
year: today.year,
month: today.month + 1,
timeRange: 'month',
profiles: {
1 => true
},
backends: backends
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'Europe/Berlin')
post '/api/v1/reports/generate', params: params, as: :json
expect(json_response['data']['count::created']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'Australia/Melbourne')
post '/api/v1/reports/generate', params: params, as: :json
expect(json_response['data']['count::created']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
# 2019 - year interval
Setting.set('timezone_default', '')
params = {
metric: 'count',
year: today.year,
timeRange: 'year',
profiles: {
1 => true
},
backends: backends
}
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 1, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 1, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'Europe/Berlin')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 0, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 7, 2, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'America/Chicago')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 2, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 2, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Setting.set('timezone_default', 'Australia/Melbourne')
post '/api/v1/reports/generate', params: params, as: :json
expect(response).to have_http_status(200)
expect(json_response['data']['count::created']).to eq([0, 0, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::closed']).to eq([0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
expect(json_response['data']['count::backlog']).to eq([0, 0, 7, 2, 0, 0, 0, 0, 0, 0, 0, 0])
end
end
end

View file

@ -730,7 +730,7 @@ class ObjectManagerTest < ActiveSupport::TestCase
value: 'some attribute test3',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 1)
assert_equal(tickets[0].id, ticket1.id)
@ -740,7 +740,7 @@ class ObjectManagerTest < ActiveSupport::TestCase
value: 'some attribute text',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 1)
assert_equal(tickets[0].id, ticket1.id)

View file

@ -291,8 +291,8 @@ class ReportTest < ActiveSupport::TestCase
# first solution
result = Report::TicketFirstSolution.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('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
)
@ -312,8 +312,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketFirstSolution.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {}, # ticket selector to get only a collection of tickets
)
assert(result)
@ -324,8 +324,8 @@ class ReportTest < ActiveSupport::TestCase
# month - with selector #1
result = Report::TicketFirstSolution.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket.priority_id' => {
@ -350,8 +350,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketFirstSolution.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket.priority_id' => {
'operator' => 'is',
@ -365,8 +365,8 @@ class ReportTest < ActiveSupport::TestCase
# month - with merged tickets selector
result = Report::TicketFirstSolution.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket_state.name' => {
@ -391,8 +391,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketFirstSolution.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket_state.name' => {
'operator' => 'is not',
@ -406,8 +406,8 @@ class ReportTest < ActiveSupport::TestCase
# month - with selector #2
result = Report::TicketFirstSolution.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket.priority_id' => {
@ -432,8 +432,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketFirstSolution.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket.priority_id' => {
'operator' => 'is not',
@ -448,8 +448,8 @@ class ReportTest < ActiveSupport::TestCase
# week
result = Report::TicketFirstSolution.aggs(
range_start: '2015-10-26T00:00:00Z',
range_end: '2015-10-31T23:59:59Z',
range_start: Time.zone.parse('2015-10-26T00:00:00Z'),
range_end: Time.zone.parse('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
)
@ -464,8 +464,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[7])
result = Report::TicketFirstSolution.items(
range_start: '2015-10-26T00:00:00Z',
range_end: '2015-11-01T23:59:59Z',
range_start: Time.zone.parse('2015-10-26T00:00:00Z'),
range_end: Time.zone.parse('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
)
@ -477,8 +477,8 @@ class ReportTest < ActiveSupport::TestCase
# day
result = Report::TicketFirstSolution.aggs(
range_start: '2015-10-01T00:00:00Z',
range_end: '2015-11-01T23:59:59Z',
range_start: Time.zone.parse('2015-10-01T00:00:00Z'),
range_end: Time.zone.parse('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
)
@ -517,8 +517,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[31])
result = Report::TicketFirstSolution.items(
range_start: '2015-10-01T00:00:00Z',
range_end: '2015-10-31T23:59:59Z',
range_start: Time.zone.parse('2015-10-01T00:00:00Z'),
range_end: Time.zone.parse('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
)
@ -529,8 +529,8 @@ class ReportTest < ActiveSupport::TestCase
# hour
result = Report::TicketFirstSolution.aggs(
range_start: '2015-10-28T00:00:00Z',
range_end: '2015-10-28T23:59:59Z',
range_start: Time.zone.parse('2015-10-28T00:00:00Z'),
range_end: Time.zone.parse('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
)
@ -562,8 +562,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[24])
result = Report::TicketFirstSolution.items(
range_start: '2015-10-28T00:00:00Z',
range_end: '2015-10-28T23:59:59Z',
range_start: Time.zone.parse('2015-10-28T00:00:00Z'),
range_end: Time.zone.parse('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
)
@ -573,8 +573,8 @@ class ReportTest < ActiveSupport::TestCase
# reopen
result = Report::TicketReopened.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('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
)
@ -594,8 +594,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketReopened.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {}, # ticket selector to get only a collection of tickets
)
assert(result)
@ -604,8 +604,8 @@ class ReportTest < ActiveSupport::TestCase
# month - with selector #1
result = Report::TicketReopened.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket.priority_id' => {
@ -630,8 +630,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketReopened.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket.priority_id' => {
'operator' => 'is',
@ -645,8 +645,8 @@ class ReportTest < ActiveSupport::TestCase
# month - with selector #2
result = Report::TicketReopened.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket.priority_id' => {
@ -671,8 +671,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketReopened.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket.priority_id' => {
'operator' => 'is not',
@ -685,8 +685,8 @@ class ReportTest < ActiveSupport::TestCase
# month - reopened with merge selector
result = Report::TicketReopened.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket_state.name' => {
@ -711,8 +711,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketReopened.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket_state.name' => {
'operator' => 'is not',
@ -726,8 +726,8 @@ class ReportTest < ActiveSupport::TestCase
# move in/out without merged status
result = Report::TicketMoved.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket_state.name' => {
@ -755,8 +755,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketMoved.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket.group_id' => {
'operator' => 'is',
@ -773,8 +773,8 @@ class ReportTest < ActiveSupport::TestCase
# move in/out
result = Report::TicketMoved.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket.group_id' => {
@ -802,8 +802,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketMoved.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket.group_id' => {
'operator' => 'is',
@ -820,8 +820,8 @@ class ReportTest < ActiveSupport::TestCase
# out without merged tickets
result = Report::TicketMoved.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket_state.name' => {
@ -849,8 +849,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketMoved.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket_state.name' => {
'operator' => 'is not',
@ -866,8 +866,8 @@ class ReportTest < ActiveSupport::TestCase
# out
result = Report::TicketMoved.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'ticket.group_id' => {
@ -895,8 +895,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketMoved.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'ticket.group_id' => {
'operator' => 'is',
@ -913,8 +913,8 @@ class ReportTest < ActiveSupport::TestCase
# create at
result = Report::TicketGenericTime.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('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' },
@ -935,8 +935,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
@ -952,8 +952,8 @@ class ReportTest < ActiveSupport::TestCase
# create at - selector with merge
result = Report::TicketGenericTime.aggs(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
interval: 'month', # year, quarter, month, week, day, hour, minute, second
selector: {
'state' => {
@ -979,8 +979,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[12])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'state' => {
'operator' => 'is not',
@ -1001,8 +1001,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][7])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'before (absolute)',
@ -1021,8 +1021,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][5])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'after (absolute)',
@ -1038,8 +1038,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][2])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'before (relative)',
@ -1051,8 +1051,8 @@ class ReportTest < ActiveSupport::TestCase
)
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'after (relative)',
@ -1067,8 +1067,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][0])
result = Report::TicketGenericTime.items(
range_start: '2037-01-01T00:00:00Z',
range_end: '2037-12-31T23:59:59Z',
range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'before (relative)',
@ -1083,8 +1083,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][0])
result = Report::TicketGenericTime.items(
range_start: '2037-01-01T00:00:00Z',
range_end: '2037-12-31T23:59:59Z',
range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'after (relative)',
@ -1100,8 +1100,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][1])
result = Report::TicketGenericTime.items(
range_start: '2037-01-01T00:00:00Z',
range_end: '2037-12-31T23:59:59Z',
range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'before (relative)',
@ -1116,8 +1116,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][0])
result = Report::TicketGenericTime.items(
range_start: '2037-01-01T00:00:00Z',
range_end: '2037-12-31T23:59:59Z',
range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'after (relative)',
@ -1133,8 +1133,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][1])
result = Report::TicketGenericTime.items(
range_start: '2037-01-01T00:00:00Z',
range_end: '2037-12-31T23:59:59Z',
range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'before (relative)',
@ -1149,8 +1149,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][0])
result = Report::TicketGenericTime.items(
range_start: '2037-01-01T00:00:00Z',
range_end: '2037-12-31T23:59:59Z',
range_start: Time.zone.parse('2037-01-01T00:00:00Z'),
range_end: Time.zone.parse('2037-12-31T23:59:59Z'),
selector: {
'created_at' => {
'operator' => 'after (relative)',
@ -1166,8 +1166,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][1])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'tags' => {
'operator' => 'contains all',
@ -1182,8 +1182,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][1])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'tags' => {
'operator' => 'contains all not',
@ -1203,8 +1203,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][6])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'tags' => {
'operator' => 'contains all',
@ -1221,8 +1221,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][2])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'tags' => {
'operator' => 'contains all not',
@ -1241,8 +1241,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][5])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'tags' => {
'operator' => 'contains one not',
@ -1262,8 +1262,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][5])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'tags' => {
'operator' => 'contains one not',
@ -1281,8 +1281,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][4])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'tags' => {
'operator' => 'contains one',
@ -1299,8 +1299,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][2])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'tags' => {
'operator' => 'contains one',
@ -1317,8 +1317,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][3])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'title' => {
'operator' => 'contains',
@ -1339,8 +1339,8 @@ class ReportTest < ActiveSupport::TestCase
assert_nil(result[:ticket_ids][7])
result = Report::TicketGenericTime.items(
range_start: '2015-01-01T00:00:00Z',
range_end: '2015-12-31T23:59:59Z',
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'title' => {
'operator' => 'contains not',

View file

@ -133,16 +133,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: [99],
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
# search matching with empty value / missing key
@ -156,19 +156,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_nil(ticket_count)
# search matching with empty value []
@ -183,19 +183,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_nil(ticket_count)
# search matching with empty value ''
@ -209,19 +209,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_nil(ticket_count)
# search matching
@ -236,19 +236,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 1)
condition = {
@ -261,19 +261,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: [Ticket::State.lookup(name: 'open').id],
},
}
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 1)
condition = {
@ -282,19 +282,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: nil,
}
}
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 1)
# search - created_at
@ -308,16 +308,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '2015-02-05T16:00:00.000Z',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
@ -330,16 +330,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '2015-02-05T18:00:00.000Z',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
condition = {
@ -352,16 +352,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '2015-02-05T18:00:00.000Z',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
@ -374,16 +374,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '2015-02-05T16:00:00.000Z',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
condition = {
@ -397,16 +397,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '10',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
@ -420,16 +420,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '10',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
@ -443,16 +443,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '10',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
# search - updated_at
@ -466,16 +466,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: (Time.zone.now + 1.day).iso8601,
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
@ -488,16 +488,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: (Time.zone.now - 1.day).iso8601,
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
condition = {
@ -510,16 +510,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: (Time.zone.now + 1.day).iso8601,
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
condition = {
@ -532,16 +532,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: (Time.zone.now - 1.day).iso8601,
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
@ -555,16 +555,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '10',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
condition = {
@ -578,16 +578,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '10',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
@ -601,21 +601,21 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: '10',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
# invalid conditions
assert_raise RuntimeError do
ticket_count, tickets = Ticket.selectors(nil, 10)
ticket_count, tickets = Ticket.selectors(nil, limit: 10)
end
# search with customers
@ -629,16 +629,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'ticket-selector-customer1',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
condition = {
@ -651,16 +651,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'ticket-selector-customer1-not_existing',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
# search with organizations
@ -674,16 +674,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'selector',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
# search with organizations
@ -701,16 +701,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'ticket-selector-customer1',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
condition = {
@ -727,16 +727,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'ticket-selector-customer1',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
# with owner/customer/org
@ -751,16 +751,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: @agent1.id,
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
condition = {
@ -774,16 +774,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
#value: @agent1.id, # value is not set, no result should be shown
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_nil(ticket_count)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_nil(ticket_count)
condition = {
@ -796,16 +796,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
pre_condition: 'not_set',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
condition = {
@ -818,16 +818,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
pre_condition: 'not_set',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
UserInfo.current_user_id = @agent1.id
@ -841,19 +841,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
pre_condition: 'current_user.id',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
UserInfo.current_user_id = @agent2.id
@ -867,19 +867,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
pre_condition: 'current_user.id',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
UserInfo.current_user_id = @customer1.id
@ -893,19 +893,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
pre_condition: 'current_user.id',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
UserInfo.current_user_id = @customer2.id
@ -919,19 +919,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
pre_condition: 'current_user.id',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 2)
UserInfo.current_user_id = @customer1.id
@ -945,19 +945,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
pre_condition: 'current_user.organization_id',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
UserInfo.current_user_id = @customer2.id
@ -971,19 +971,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
pre_condition: 'current_user.organization_id',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @agent2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, @customer2)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10)
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
assert_equal(ticket_count, 0)
travel_back
end
@ -1055,7 +1055,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'contains_all_1, contains_all_2, contains_all_3',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(1, ticket_count)
condition = {
@ -1064,7 +1064,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'contains_all_1, contains_all_2, contains_all_3, xxx',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(0, ticket_count)
# search all with contains one
@ -1074,7 +1074,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'contains_all_1, contains_all_2, contains_all_3',
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(2, ticket_count)
condition = {
@ -1083,7 +1083,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'contains_all_1, contains_all_2'
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(1, ticket_count)
# search all with contains one not
@ -1093,7 +1093,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'contains_all_1, contains_all_3'
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(2, ticket_count)
condition = {
@ -1102,7 +1102,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
value: 'contains_all_1, contains_all_2, contains_all_3'
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, @agent1)
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
assert_equal(2, ticket_count)
end