Improved tests for out of office feature and related controllers.

This commit is contained in:
Martin Edenhofer 2017-09-11 02:50:05 +02:00
parent d6bae448db
commit 003d60d6b1
21 changed files with 679 additions and 135 deletions

View file

@ -293,6 +293,7 @@ test:integration:es_mysql:
- ruby -I test/ test/controllers/search_controller_test.rb - ruby -I test/ test/controllers/search_controller_test.rb
- ruby -I test/ test/integration/report_test.rb - ruby -I test/ test/integration/report_test.rb
- ruby -I test/ test/controllers/form_controller_test.rb - ruby -I test/ test/controllers/form_controller_test.rb
- ruby -I test/ test/controllers/user_organization_controller_test.rb
- rake db:drop - rake db:drop
test:integration:es_postgresql: test:integration:es_postgresql:
@ -310,6 +311,7 @@ test:integration:es_postgresql:
- ruby -I test/ test/controllers/search_controller_test.rb - ruby -I test/ test/controllers/search_controller_test.rb
- ruby -I test/ test/integration/report_test.rb - ruby -I test/ test/integration/report_test.rb
- ruby -I test/ test/controllers/form_controller_test.rb - ruby -I test/ test/controllers/form_controller_test.rb
- ruby -I test/ test/controllers/user_organization_controller_test.rb
- rake db:drop - rake db:drop
test:integration:zendesk_mysql: test:integration:zendesk_mysql:

View file

@ -14,7 +14,7 @@ class App.UiElement.autocompletion
# call calback on init # call calback on init
if @callback && attribute.value && @params if @callback && attribute.value && @params
@callback( @params ) @callback(@params)
b = (event, item) => b = (event, item) =>
# set html form attribute # set html form attribute
@ -24,7 +24,7 @@ class App.UiElement.autocompletion
# call calback # call calback
if @callback if @callback
params = App.ControllerForm.params(form) params = App.ControllerForm.params(form)
@callback( params ) @callback(params)
### ###
$(@local_attribute_full).tagsInput( $(@local_attribute_full).tagsInput(
autocomplete_url: '/users/search', autocomplete_url: '/users/search',
@ -33,7 +33,7 @@ class App.UiElement.autocompletion
auto: { auto: {
source: '/users/search', source: '/users/search',
minLength: 2, minLength: 2,
select: ( event, ui ) -> select: (event, ui) ->
#@log 'notice', 'selected', event, ui #@log 'notice', 'selected', event, ui
b(event, ui.item) b(event, ui.item)
} }
@ -45,8 +45,8 @@ class App.UiElement.autocompletion
$(local_attribute_full).autocomplete( $(local_attribute_full).autocomplete(
source: source, source: source,
minLength: attribute.minLengt || 3, minLength: attribute.minLengt || 3,
select: ( event, ui ) -> select: (event, ui) ->
b(event, ui.item) b(event, ui.item)
) )
App.Delay.set( a, 280, undefined, 'form_autocompletion' ) App.Delay.set(a, 280, undefined, 'form_autocompletion')
item item

View file

@ -80,6 +80,17 @@ class App.UiElement.ticket_selector
if config.name && config.name.match(myRegExp) if config.name && config.name.match(myRegExp)
config.operator = operator config.operator = operator
elements["#{groupKey}.#{config.name}"] = config elements["#{groupKey}.#{config.name}"] = config
if attribute.out_of_office
elements['ticket.out_of_office_replacement_id'] =
name: 'out_of_office_replacement_id'
display: 'Out of office replacement'
tag: 'autocompletion_ajax'
relation: 'User'
null: false
translate: true
operator: ['is', 'is not']
[defaults, groups, elements] [defaults, groups, elements]
@rowContainer: (groups, elements, attribute) -> @rowContainer: (groups, elements, attribute) ->

View file

@ -140,7 +140,7 @@ class Index extends App.ControllerSubContent
App.Ajax.request( App.Ajax.request(
id: 'search' id: 'search'
type: 'GET' type: 'GET'
url: @apiPath + '/users/search' url: "#{@apiPath}/users/search"
data: data:
query: @query query: @query
limit: 140 limit: 140
@ -165,7 +165,7 @@ class Index extends App.ControllerSubContent
type: 'GET' type: 'GET'
url: "#{@apiPath}/users/recent" url: "#{@apiPath}/users/recent"
data: data:
limit: 40 limit: 50
role_ids: role_ids role_ids: role_ids
full: 1 full: 1
processData: true processData: true

View file

@ -9,7 +9,7 @@ class App.Overview extends App.Model
{ name: 'user_ids', display: 'Available for User', tag: 'column_select', multiple: true, null: true, relation: 'User', sortBy: 'firstname' }, { name: 'user_ids', display: 'Available for User', tag: 'column_select', multiple: true, null: true, relation: 'User', sortBy: 'firstname' },
{ name: 'organization_shared', display: 'Only available for Users with shared Organization', tag: 'select', options: { true: 'yes', false: 'no' }, default: false, null: true }, { name: 'organization_shared', display: 'Only available for Users with shared Organization', tag: 'select', options: { true: 'yes', false: 'no' }, default: false, null: true },
{ name: 'out_of_office', display: 'Only available for Users which are replacements for other users.', tag: 'select', options: { true: 'yes', false: 'no' }, default: false, null: true }, { name: 'out_of_office', display: 'Only available for Users which are replacements for other users.', tag: 'select', options: { true: 'yes', false: 'no' }, default: false, null: true },
{ name: 'condition', display: 'Conditions for shown Tickets', tag: 'ticket_selector', null: false }, { name: 'condition', display: 'Conditions for shown Tickets', tag: 'ticket_selector', null: false, out_of_office: true },
{ name: 'prio', display: 'Prio', readonly: 1 }, { name: 'prio', display: 'Prio', readonly: 1 },
{ {
name: 'view::s' name: 'view::s'

View file

@ -5,7 +5,7 @@ class App.Trigger extends App.Model
@configure_attributes = [ @configure_attributes = [
{ name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false }, { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false },
{ name: 'condition', display: 'Conditions for effected objects', tag: 'ticket_selector', null: false, preview: false, action: true, hasChanged: true }, { name: 'condition', display: 'Conditions for effected objects', tag: 'ticket_selector', null: false, preview: false, action: true, hasChanged: true },
{ name: 'perform', display: 'Execute changes on objects', tag: 'ticket_perform_action', null: true, notification: true }, { name: 'perform', display: 'Execute changes on objects', tag: 'ticket_perform_action', null: true, notification: true, trigger: true },
{ name: 'active', display: 'Active', tag: 'active', default: true }, { name: 'active', display: 'Active', tag: 'active', default: true },
{ name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 }, { name: 'updated_at', display: 'Updated', tag: 'datetime', readonly: 1 },
] ]

View file

@ -57,7 +57,7 @@ class SearchController < ApplicationController
} }
# do only one query to index search backend # do only one query to index search backend
if !objects_with_direct_search_index.empty? if objects_with_direct_search_index.present?
items = SearchIndexBackend.search(query, limit, objects_with_direct_search_index) items = SearchIndexBackend.search(query, limit, objects_with_direct_search_index)
items.each { |item| items.each { |item|
require item[:type].to_filename require item[:type].to_filename
@ -71,7 +71,7 @@ class SearchController < ApplicationController
# e. g. do ticket query by Ticket class to handle ticket permissions # e. g. do ticket query by Ticket class to handle ticket permissions
objects_without_direct_search_index.each { |object| objects_without_direct_search_index.each { |object|
object_result = search_generic_backend(object, query, limit, current_user, assets) object_result = search_generic_backend(object, query, limit, current_user, assets)
if !object_result.empty? if object_result.present?
result = result.concat(object_result) result = result.concat(object_result)
end end
} }
@ -92,7 +92,7 @@ class SearchController < ApplicationController
# do query # do query
objects_in_order.each { |object| objects_in_order.each { |object|
object_result = search_generic_backend(object, query, limit, current_user, assets) object_result = search_generic_backend(object, query, limit, current_user, assets)
if !object_result.empty? if object_result.present?
result = result.concat(object_result) result = result.concat(object_result)
end end
} }

View file

@ -368,8 +368,9 @@ class UsersController < ApplicationController
limit: params[:limit], limit: params[:limit],
current_user: current_user, current_user: current_user,
} }
if params[:role_ids].present? [:role_ids, :permissions].each do |key|
query_params[:role_ids] = params[:role_ids] next if params[key].blank?
query_params[key] = params[key]
end end
# do query # do query

View file

@ -19,10 +19,10 @@ update search index, if configured - will be executed automatically
=end =end
def search_index_update def search_index_update
return if ignore_search_indexing?(:update) return true if ignore_search_indexing?(:update)
# start background job to transfer data to search index # start background job to transfer data to search index
return if !SearchIndexBackend.enabled? return true if !SearchIndexBackend.enabled?
Delayed::Job.enqueue(BackgroundJobSearchIndex.new(self.class.to_s, id)) Delayed::Job.enqueue(BackgroundJobSearchIndex.new(self.class.to_s, id))
true true
end end
@ -37,7 +37,7 @@ delete search index object, will be executed automatically
=end =end
def search_index_destroy def search_index_destroy
return if ignore_search_indexing?(:destroy) return true if ignore_search_indexing?(:destroy)
SearchIndexBackend.remove(self.class.to_s, id) SearchIndexBackend.remove(self.class.to_s, id)
true true
end end
@ -58,7 +58,7 @@ returns
def search_index_update_backend def search_index_update_backend
# fill up with search data # fill up with search data
attributes = search_index_attribute_lookup attributes = search_index_attribute_lookup
return if !attributes return true if !attributes
# update backend # update backend
SearchIndexBackend.add(self.class.to_s, attributes) SearchIndexBackend.add(self.class.to_s, attributes)
@ -86,10 +86,10 @@ returns
attributes = {} attributes = {}
%w(name note).each { |key| %w(name note).each { |key|
next if !self[key] next if !self[key]
next if self[key].respond_to?('empty?') && self[key].empty? next if self[key].respond_to?('blank?') && self[key].blank?
attributes[key] = self[key] attributes[key] = self[key]
} }
return if attributes.empty? return true if attributes.blank?
attributes attributes
end end

View file

@ -549,6 +549,12 @@ condition example
# get attributes # get attributes
attributes = attribute.split(/\./) attributes = attribute.split(/\./)
attribute = "#{attributes[0]}s.#{attributes[1]}" attribute = "#{attributes[0]}s.#{attributes[1]}"
# magic selectors
if attributes[0] == 'ticket' && attributes[1] == 'out_of_office_replacement_id'
attribute = "#{attributes[0]}s.owner_id"
end
if attributes[0] == 'ticket' && attributes[1] == 'tags' if attributes[0] == 'ticket' && attributes[1] == 'tags'
selector['value'] = selector['value'].split(/,/).collect(&:strip) selector['value'] = selector['value'].split(/,/).collect(&:strip)
end end
@ -567,8 +573,13 @@ condition example
end end
elsif selector['pre_condition'] == 'current_user.id' elsif selector['pre_condition'] == 'current_user.id'
raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id
query += "#{attribute} IN (?)" if attributes[1] == 'out_of_office_replacement_id'
bind_params.push current_user_id query += "#{attribute} IN (?)"
bind_params.push User.find(current_user_id).out_of_office_agent_of.pluck(:id)
else
query += "#{attribute} IN (?)"
bind_params.push current_user_id
end
elsif selector['pre_condition'] == 'current_user.organization_id' elsif selector['pre_condition'] == 'current_user.organization_id'
raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id raise "Use current_user.id in selector, but no current_user is set #{selector.inspect}" if !current_user_id
query += "#{attribute} IN (?)" query += "#{attribute} IN (?)"
@ -579,8 +590,13 @@ condition example
if selector['value'].nil? if selector['value'].nil?
query += "#{attribute} IS NULL" query += "#{attribute} IS NULL"
else else
query += "#{attribute} IN (?)" if attributes[1] == 'out_of_office_replacement_id'
bind_params.push selector['value'] query += "#{attribute} IN (?)"
bind_params.push User.find(selector['value']).out_of_office_agent_of.pluck(:id)
else
query += "#{attribute} IN (?)"
bind_params.push selector['value']
end
end end
# rubocop:enable Style/IfInsideElse # rubocop:enable Style/IfInsideElse
end end
@ -593,8 +609,13 @@ condition example
query += "#{attribute} IS NOT NULL" query += "#{attribute} IS NOT NULL"
end end
elsif selector['pre_condition'] == 'current_user.id' elsif selector['pre_condition'] == 'current_user.id'
query += "#{attribute} NOT IN (?)" if attributes[1] == 'out_of_office_replacement_id'
bind_params.push current_user_id query += "#{attribute} NOT IN (?)"
bind_params.push User.find(current_user_id).out_of_office_agent_of.pluck(:id)
else
query += "#{attribute} NOT IN (?)"
bind_params.push current_user_id
end
elsif selector['pre_condition'] == 'current_user.organization_id' elsif selector['pre_condition'] == 'current_user.organization_id'
query += "#{attribute} NOT IN (?)" query += "#{attribute} NOT IN (?)"
user = User.lookup(id: current_user_id) user = User.lookup(id: current_user_id)
@ -604,8 +625,13 @@ condition example
if selector['value'].nil? if selector['value'].nil?
query += "#{attribute} IS NOT NULL" query += "#{attribute} IS NOT NULL"
else else
query += "#{attribute} NOT IN (?)" if attributes[1] == 'out_of_office_replacement_id'
bind_params.push selector['value'] query += "#{attribute} NOT IN (?)"
bind_params.push User.find(selector['value']).out_of_office_agent_of.pluck(:id)
else
query += "#{attribute} NOT IN (?)"
bind_params.push selector['value']
end
end end
# rubocop:enable Style/IfInsideElse # rubocop:enable Style/IfInsideElse
end end

View file

@ -199,6 +199,23 @@ returns
=begin =begin
gets users where user is replacement
user = User.find(123)
result = user.out_of_office_agent_of
returns
result = [user_model1, user_model2]
=end
def out_of_office_agent_of
User.where(active: true, out_of_office: true, out_of_office_replacement_id: id).where('out_of_office_start_at <= ? AND out_of_office_end_at >= ?', Time.zone.today, Time.zone.today)
end
=begin
get users activity stream get users activity stream
user = User.find(123) user = User.find(123)

View file

@ -40,6 +40,16 @@ search user
current_user: user_model, current_user: user_model,
) )
or with certain role_ids | permissions
result = User.search(
query: 'some search term',
limit: 15,
current_user: user_model,
role_ids: [1,2,3],
permissions: ['ticket.agent']
)
returns returns
result = [user_model1, user_model2, ...] result = [user_model1, user_model2, ...]
@ -56,9 +66,28 @@ returns
# enable search only for agents and admins # enable search only for agents and admins
return [] if !search_preferences(current_user) return [] if !search_preferences(current_user)
# lookup for roles of permission
if params[:permissions].present?
params[:role_ids] ||= []
role_ids = Role.with_permissions(params[:permissions]).pluck(:id)
params[:role_ids].concat(role_ids)
end
# try search index backend # try search index backend
if SearchIndexBackend.enabled? if SearchIndexBackend.enabled?
items = SearchIndexBackend.search(query, limit, 'User') query_extention = {}
if params[:role_ids].present?
query_extention['bool'] = {}
query_extention['bool']['must'] = []
if !params[:role_ids].is_a?(Array)
params[:role_ids] = [params[:role_ids]]
end
access_condition = {
'query_string' => { 'default_field' => 'role_ids', 'query' => "\"#{params[:role_ids].join('" OR "')}\"" }
}
query_extention['bool']['must'].push access_condition
end
items = SearchIndexBackend.search(query, limit, 'User', query_extention)
users = [] users = []
items.each { |item| items.each { |item|
user = User.lookup(id: item[:id]) user = User.lookup(id: item[:id])

View file

@ -5,6 +5,33 @@ class User
=begin =begin
lookup name of ref. objects
user = User.find(123)
attributes = user.search_index_attribute_lookup
returns
attributes # object with lookup data
=end
def search_index_attribute_lookup
attributes = super
attributes['permissions'] = []
permissions_with_child_ids.each do |permission_id|
permission = Permission.lookup(id: permission_id)
next if !permission
attributes['permissions'].push permission.name
end
attributes['role_ids'] = role_ids
attributes
end
=begin
get data to store in search index get data to store in search index
user = User.find(2) user = User.find(2)
@ -30,12 +57,12 @@ returns
next if key == 'preferences' next if key == 'preferences'
next if key == 'password' next if key == 'password'
next if !value next if !value
next if value.respond_to?('empty?') && value.empty? next if value.respond_to?('blank?') && value.blank?
attributes[key] = value attributes[key] = value
} }
return if attributes.empty? return if attributes.blank?
if attributes['organization_id'] if attributes['organization_id'].present?
organization = Organization.lookup(id: attributes['organization_id']) organization = Organization.lookup(id: attributes['organization_id'])
if organization if organization
attributes['organization'] = organization.name attributes['organization'] = organization.name

View file

@ -1,53 +0,0 @@
class OutOfOffice < ActiveRecord::Migration[4.2]
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
add_column :overviews, :out_of_office, :boolean, null: false, default: false
Overview.reset_column_information
role_ids = Role.with_permissions(['ticket.agent']).map(&:id)
overview_role = Role.find_by(name: 'Agent')
Overview.create_if_not_exists(
name: 'My replacement Tickets',
link: 'my_replacement_tickets',
prio: 1080,
role_ids: role_ids,
out_of_office: true,
condition: {
'ticket.state_id' => {
operator: 'is',
value: Ticket::State.by_category(:open).pluck(:id),
},
#'ticket.out_of_office_replacement_id' => {
# operator: 'is',
# pre_condition: 'current_user.organization_id',
#},
},
order: {
by: 'created_at',
direction: 'DESC',
},
view: {
d: %w(title customer group owner escalation_at),
s: %w(title customer group owner escalation_at),
m: %w(number title customer group owner escalation_at),
view_mode_default: 's',
},
updated_by_id: 1,
created_by_id: 1,
)
add_column :users, :out_of_office, :boolean, null: false, default: false
add_column :users, :out_of_office_start_at, :date, null: true
add_column :users, :out_of_office_end_at, :date, null: true
add_column :users, :out_of_office_replacement_id, :integer, null: true
add_index :users, [:out_of_office, :out_of_office_start_at, :out_of_office_end_at], name: 'index_out_of_office'
add_index :users, [:out_of_office_replacement_id]
add_foreign_key :users, :users, column: :out_of_office_replacement_id
Cache.clear
end
end

View file

@ -0,0 +1,58 @@
class OutOfOffice < ActiveRecord::Migration[4.2]
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
if !ActiveRecord::Base.connection.column_exists?(:overviews, :out_of_office)
add_column :overviews, :out_of_office, :boolean, null: false, default: false
Overview.reset_column_information
end
role_ids = Role.with_permissions(['ticket.agent']).map(&:id)
overview_role = Role.find_by(name: 'Agent')
Overview.create_or_update(
name: 'My replacement Tickets',
link: 'my_replacement_tickets',
prio: 1080,
role_ids: role_ids,
out_of_office: true,
condition: {
'ticket.state_id' => {
operator: 'is',
value: Ticket::State.by_category(:open).pluck(:id),
},
'ticket.out_of_office_replacement_id' => {
operator: 'is',
pre_condition: 'current_user.id',
},
},
order: {
by: 'created_at',
direction: 'DESC',
},
view: {
d: %w(title customer group owner escalation_at),
s: %w(title customer group owner escalation_at),
m: %w(number title customer group owner escalation_at),
view_mode_default: 's',
},
updated_by_id: 1,
created_by_id: 1,
)
if !ActiveRecord::Base.connection.column_exists?(:users, :out_of_office)
add_column :users, :out_of_office, :boolean, null: false, default: false
add_column :users, :out_of_office_start_at, :date, null: true
add_column :users, :out_of_office_end_at, :date, null: true
add_column :users, :out_of_office_replacement_id, :integer, null: true
add_index :users, [:out_of_office, :out_of_office_start_at, :out_of_office_end_at], name: 'index_out_of_office'
add_index :users, [:out_of_office_replacement_id]
add_foreign_key :users, :users, column: :out_of_office_replacement_id
User.reset_column_information
end
Cache.clear
end
end

View file

@ -171,10 +171,10 @@ Overview.create_if_not_exists(
operator: 'is', operator: 'is',
value: Ticket::State.by_category(:open).pluck(:id), value: Ticket::State.by_category(:open).pluck(:id),
}, },
#'ticket.out_of_office_replacement_id' => { 'ticket.out_of_office_replacement_id' => {
# operator: 'is', operator: 'is',
# pre_condition: 'current_user.organization_id', pre_condition: 'current_user.id',
#}, },
}, },
order: { order: {
by: 'created_at', by: 'created_at',

View file

@ -1,5 +1,6 @@
# encoding: utf-8 # encoding: utf-8
require 'test_helper' require 'test_helper'
require 'rake'
class UserOrganizationControllerTest < ActionDispatch::IntegrationTest class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
setup do setup do
@ -83,6 +84,39 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
organization_id: @organization.id, organization_id: @organization.id,
) )
# configure es
if ENV['ES_URL'].present?
#fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
Setting.set('es_url', ENV['ES_URL'])
# Setting.set('es_url', 'http://127.0.0.1:9200')
# Setting.set('es_index', 'estest.local_zammad')
# Setting.set('es_user', 'elasticsearch')
# Setting.set('es_password', 'zammad')
if ENV['ES_INDEX_RAND'].present?
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
end
if ENV['ES_INDEX'].blank?
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
end
Setting.set('es_index', ENV['ES_INDEX'])
travel 1.minute
# drop/create indexes
Rake::Task.clear
Zammad::Application.load_tasks
#Rake::Task["searchindex:drop"].execute
#Rake::Task["searchindex:create"].execute
Rake::Task['searchindex:rebuild'].execute
# execute background jobs
Scheduler.worker(true)
sleep 6
end
end end
test 'user create tests - no user' do test 'user create tests - no user' do
@ -460,10 +494,12 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
# search as agent # search as agent
Scheduler.worker(true) Scheduler.worker(true)
sleep 2 # let es time to come ready
get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}", params: {}, headers: @headers.merge('Authorization' => credentials) get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}", params: {}, headers: @headers.merge('Authorization' => credentials)
assert_response(200) assert_response(200)
result = JSON.parse(@response.body) result = JSON.parse(@response.body)
assert_equal(Array, result.class) assert_equal(Array, result.class)
assert_equal(result_user1['id'], result[0]['id']) assert_equal(result_user1['id'], result[0]['id'])
assert_equal("Customer#{firstname}", result[0]['firstname']) assert_equal("Customer#{firstname}", result[0]['firstname'])
assert_equal('Customer Last', result[0]['lastname']) assert_equal('Customer Last', result[0]['lastname'])
@ -489,6 +525,42 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['value']) assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['value'])
assert_not(result[0]['role_ids']) assert_not(result[0]['role_ids'])
assert_not(result[0]['roles']) assert_not(result[0]['roles'])
role = Role.find_by(name: 'Agent')
get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&role_ids=#{role.id}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials)
assert_response(200)
result = JSON.parse(@response.body)
assert_equal(Array, result.class)
assert_equal(0, result.count)
role = Role.find_by(name: 'Customer')
get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&role_ids=#{role.id}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials)
assert_response(200)
result = JSON.parse(@response.body)
assert_equal(Array, result.class)
assert_equal(result_user1['id'], result[0]['id'])
assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['label'])
assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['value'])
assert_not(result[0]['role_ids'])
assert_not(result[0]['roles'])
permission = Permission.find_by(name: 'ticket.agent')
get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&permissions=#{permission.name}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials)
assert_response(200)
result = JSON.parse(@response.body)
assert_equal(Array, result.class)
assert_equal(0, result.count)
permission = Permission.find_by(name: 'ticket.customer')
get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&permissions=#{permission.name}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials)
assert_response(200)
result = JSON.parse(@response.body)
assert_equal(Array, result.class)
assert_equal(result_user1['id'], result[0]['id'])
assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['label'])
assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['value'])
assert_not(result[0]['role_ids'])
assert_not(result[0]['roles'])
end end
test 'user index and create with customer1' do test 'user index and create with customer1' do

View file

@ -124,6 +124,13 @@ class ElasticsearchTest < ActiveSupport::TestCase
assert_not(attributes['password']) assert_not(attributes['password'])
assert_not(attributes['organization']) assert_not(attributes['organization'])
attributes = @customer1.search_index_attribute_lookup
assert_equal('ES', attributes['firstname'])
assert_equal('Customer1', attributes['lastname'])
assert_equal('es-customer1@example.com', attributes['email'])
assert_not(attributes['password'])
assert_equal('Customer Organization Update', attributes['organization'])
# organization # organization
attributes = @organization1.search_index_data attributes = @organization1.search_index_data
assert_equal('Customer Organization Update', attributes['name']) assert_equal('Customer Organization Update', attributes['name'])

View file

@ -0,0 +1,321 @@
# encoding: utf-8
require 'test_helper'
class TicketOverviewOutOfOfficeTest < ActiveSupport::TestCase
setup do
group = Group.create_or_update(
name: 'OverviewReplacementTest',
updated_at: '2015-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where(name: 'Agent')
@agent1 = User.create_or_update(
login: 'ticket-overview-agent1@example.com',
firstname: 'Overview',
lastname: 'Agent1',
email: 'ticket-overview-agent1@example.com',
password: 'agentpw',
active: true,
roles: roles,
groups: [group],
out_of_office: false,
updated_at: '2015-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
@agent2 = User.create_or_update(
login: 'ticket-overview-agent2@example.com',
firstname: 'Overview',
lastname: 'Agent2',
email: 'ticket-overview-agent2@example.com',
password: 'agentpw',
active: true,
roles: roles,
groups: [group],
out_of_office: false,
updated_at: '2015-02-05 16:38:00',
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where(name: 'Customer')
organization1 = Organization.create_or_update(
name: 'Overview Org',
updated_at: '2015-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
@customer1 = User.create_or_update(
login: 'ticket-overview-customer1@example.com',
firstname: 'Overview',
lastname: 'Customer1',
email: 'ticket-overview-customer1@example.com',
password: 'customerpw',
active: true,
organization_id: organization1.id,
roles: roles,
out_of_office: false,
updated_at: '2015-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
Overview.destroy_all
UserInfo.current_user_id = 1
overview_role = Role.find_by(name: 'Agent')
@overview1 = Overview.create_or_update(
name: 'My replacement Tickets',
link: 'my_replacement',
prio: 1000,
role_ids: [overview_role.id],
out_of_office: true,
condition: {
'ticket.state_id' => {
operator: 'is',
value: Ticket::State.by_category(:open).pluck(:id),
},
'ticket.out_of_office_replacement_id' => {
operator: 'is',
pre_condition: 'current_user.id',
},
},
order: {
by: 'created_at',
direction: 'ASC',
},
view: {
d: %w(title customer group created_at),
s: %w(title customer group created_at),
m: %w(number title customer group created_at),
view_mode_default: 's',
},
)
@overview2 = Overview.create_if_not_exists(
name: 'My assigned Tickets',
link: 'my_assigned',
prio: 900,
role_ids: [overview_role.id],
condition: {
'ticket.state_id' => {
operator: 'is',
value: Ticket::State.by_category(:open).pluck(:id),
},
'ticket.owner_id' => {
operator: 'is',
pre_condition: 'current_user.id',
},
},
order: {
by: 'created_at',
direction: 'ASC',
},
view: {
d: %w(title customer group created_at),
s: %w(title customer group created_at),
m: %w(number title customer group created_at),
view_mode_default: 's',
},
)
overview_role = Role.find_by(name: 'Customer')
@overview3 = Overview.create_or_update(
name: 'My Tickets',
link: 'my_tickets',
prio: 1100,
role_ids: [overview_role.id],
out_of_office: true,
condition: {
'ticket.state_id' => {
operator: 'is',
value: [1, 2, 3, 4, 6, 7],
},
'ticket.out_of_office_replacement_id' => {
operator: 'is',
pre_condition: 'current_user.organization_id',
},
},
order: {
by: 'created_at',
direction: 'DESC',
},
view: {
d: %w(title customer state created_at),
s: %w(number title state created_at),
m: %w(number title state created_at),
view_mode_default: 's',
},
)
end
test 'overview index' do
result = Ticket::Overviews.all(
current_user: @agent1,
)
assert_equal(1, result.count)
assert_equal('My assigned Tickets', result[0].name)
result = Ticket::Overviews.all(
current_user: @agent2,
)
assert_equal(1, result.count)
assert_equal('My assigned Tickets', result[0].name)
result = Ticket::Overviews.all(
current_user: @customer1,
)
assert_equal(1, result.count)
assert_equal('My Tickets', result[0].name)
@agent1.out_of_office = true
@agent1.out_of_office_start_at = Time.zone.now - 2.days
@agent1.out_of_office_end_at = Time.zone.now + 2.days
@agent1.out_of_office_replacement_id = @agent2.id
@agent1.save!
result = Ticket::Overviews.all(
current_user: @agent1,
)
assert_equal(1, result.count)
assert_equal('My assigned Tickets', result[0].name)
result = Ticket::Overviews.all(
current_user: @agent2,
)
assert_equal(2, result.count)
assert_equal('My assigned Tickets', result[0].name)
assert_equal('My replacement Tickets', result[1].name)
result = Ticket::Overviews.all(
current_user: @customer1,
)
assert_equal(1, result.count)
assert_equal('My Tickets', result[0].name)
end
test 'overview shown' do
result = Ticket::Overviews.index(@agent1)
assert(result[0])
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].blank?)
result = Ticket::Overviews.index(@agent2)
assert(result[0])
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].blank?)
result = Ticket::Overviews.index(@customer1)
assert(result[0])
assert_equal(result[0][:overview][:name], 'My Tickets')
assert_equal(result[0][:overview][:view], 'my_tickets')
assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].blank?)
@agent1.out_of_office = true
@agent1.out_of_office_start_at = Time.zone.now - 2.days
@agent1.out_of_office_end_at = Time.zone.now + 2.days
@agent1.out_of_office_replacement_id = @agent2.id
@agent1.save!
p User.where(active: true, out_of_office: true, out_of_office_replacement_id: @agent2.id)
p User.where(active: true, out_of_office: true, out_of_office_replacement_id: @agent2.id).where('out_of_office_start_at <= ? AND out_of_office_end_at >= ?', Time.zone.today, Time.zone.today)
assert_equal(@agent2.out_of_office_agent_of.count, 1)
assert(@agent2.out_of_office_agent_of[0])
assert_equal(@agent2.out_of_office_agent_of[0].id, @agent1.id)
result = Ticket::Overviews.index(@agent1)
assert(result[0])
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].blank?)
result = Ticket::Overviews.index(@agent2)
assert(result[0])
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].blank?)
assert(result[1])
assert_equal(result[1][:overview][:name], 'My replacement Tickets')
assert_equal(result[1][:overview][:view], 'my_replacement')
assert_equal(result[1][:count], 0)
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].blank?)
result = Ticket::Overviews.index(@customer1)
assert(result[0])
assert_equal(result[0][:overview][:name], 'My Tickets')
assert_equal(result[0][:overview][:view], 'my_tickets')
assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].blank?)
ticket1 = Ticket.create!(
title: 'overview test 1',
group: Group.lookup(name: 'OverviewReplacementTest'),
customer_id: 2,
owner_id: @agent1.id,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: 1,
created_by_id: 1,
)
article1 = Ticket::Article.create!(
ticket_id: ticket1.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: 'some message... 123',
internal: false,
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
type: Ticket::Article::Type.find_by(name: 'email'),
updated_by_id: 1,
created_by_id: 1,
)
result = Ticket::Overviews.index(@agent1)
assert(result[0])
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 1)
assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets])
assert_equal(result[0][:tickets][0][:id], ticket1.id)
result = Ticket::Overviews.index(@agent2)
assert(result[0])
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].blank?)
assert(result[1])
assert_equal(result[1][:overview][:name], 'My replacement Tickets')
assert_equal(result[1][:overview][:view], 'my_replacement')
assert_equal(result[1][:count], 1)
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets])
assert_equal(result[1][:tickets][0][:id], ticket1.id)
result = Ticket::Overviews.index(@customer1)
assert(result[0])
assert_equal(result[0][:overview][:name], 'My Tickets')
assert_equal(result[0][:overview][:view], 'my_tickets')
assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].blank?)
end
end

View file

@ -352,16 +352,16 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note') assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
assert_equal(result[2][:count], 0) assert_equal(result[2][:count], 0)
result = Ticket::Overviews.index(@agent2) result = Ticket::Overviews.index(@agent2)
@ -369,16 +369,16 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
ticket1 = Ticket.create!( ticket1 = Ticket.create!(
title: 'overview test 1', title: 'overview test 1',
@ -408,17 +408,17 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?) assert_not(result[1][:tickets].blank?)
assert_equal(result[1][:tickets][0][:id], ticket1.id) assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:count], 1) assert_equal(result[1][:count], 1)
assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note') assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
assert_equal(result[2][:count], 0) assert_equal(result[2][:count], 0)
result = Ticket::Overviews.index(@agent2) result = Ticket::Overviews.index(@agent2)
@ -426,16 +426,16 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
travel 1.second # because of mysql millitime issues travel 1.second # because of mysql millitime issues
ticket2 = Ticket.create!( ticket2 = Ticket.create!(
@ -466,18 +466,18 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?) assert_not(result[1][:tickets].blank?)
assert_equal(result[1][:tickets][0][:id], ticket1.id) assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:tickets][1][:id], ticket2.id) assert_equal(result[1][:tickets][1][:id], ticket2.id)
assert_equal(result[1][:count], 2) assert_equal(result[1][:count], 2)
assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note') assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
assert_equal(result[2][:count], 0) assert_equal(result[2][:count], 0)
result = Ticket::Overviews.index(@agent2) result = Ticket::Overviews.index(@agent2)
@ -485,16 +485,16 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
ticket2.owner_id = @agent1.id ticket2.owner_id = @agent1.id
ticket2.save! ticket2.save!
@ -509,7 +509,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?) assert_not(result[1][:tickets].blank?)
assert_equal(result[1][:tickets][0][:id], ticket1.id) assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:count], 1) assert_equal(result[1][:count], 1)
assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:name], 'My Tickets only with Note')
@ -523,16 +523,16 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
travel 1.second # because of mysql millitime issues travel 1.second # because of mysql millitime issues
ticket3 = Ticket.create!( ticket3 = Ticket.create!(
@ -571,7 +571,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?) assert_not(result[1][:tickets].blank?)
assert_equal(result[1][:tickets][0][:id], ticket1.id) assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:tickets][1][:id], ticket3.id) assert_equal(result[1][:tickets][1][:id], ticket3.id)
assert_equal(result[1][:count], 2) assert_equal(result[1][:count], 2)
@ -588,18 +588,18 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:id], @overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:id], @overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
@overview2.order = { @overview2.order = {
by: 'created_at', by: 'created_at',
@ -619,7 +619,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?) assert_not(result[1][:tickets].blank?)
assert_equal(result[1][:tickets][0][:id], ticket3.id) assert_equal(result[1][:tickets][0][:id], ticket3.id)
assert_equal(result[1][:tickets][1][:id], ticket1.id) assert_equal(result[1][:tickets][1][:id], ticket1.id)
assert_equal(result[1][:count], 2) assert_equal(result[1][:count], 2)
@ -636,18 +636,18 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:id], @overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:id], @overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
@overview2.order = { @overview2.order = {
by: 'priority_id', by: 'priority_id',
@ -667,7 +667,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?) assert_not(result[1][:tickets].blank?)
assert_equal(result[1][:tickets][0][:id], ticket1.id) assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:tickets][1][:id], ticket3.id) assert_equal(result[1][:tickets][1][:id], ticket3.id)
assert_equal(result[1][:count], 2) assert_equal(result[1][:count], 2)
@ -684,18 +684,18 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:id], @overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:id], @overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
@overview2.order = { @overview2.order = {
by: 'priority_id', by: 'priority_id',
@ -715,7 +715,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?) assert_not(result[1][:tickets].blank?)
assert_equal(result[1][:tickets][0][:id], ticket3.id) assert_equal(result[1][:tickets][0][:id], ticket3.id)
assert_equal(result[1][:tickets][1][:id], ticket1.id) assert_equal(result[1][:tickets][1][:id], ticket1.id)
assert_equal(result[1][:count], 2) assert_equal(result[1][:count], 2)
@ -732,18 +732,18 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:id], @overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:id], @overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
@overview2.order = { @overview2.order = {
by: 'priority', by: 'priority',
@ -763,7 +763,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?) assert_not(result[1][:tickets].blank?)
assert_equal(result[1][:tickets][0][:id], ticket1.id) assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:tickets][1][:id], ticket3.id) assert_equal(result[1][:tickets][1][:id], ticket3.id)
assert_equal(result[1][:count], 2) assert_equal(result[1][:count], 2)
@ -780,18 +780,18 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:id], @overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:id], @overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
@overview2.order = { @overview2.order = {
by: 'priority', by: 'priority',
@ -811,7 +811,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?) assert_not(result[1][:tickets].blank?)
assert_equal(result[1][:tickets][0][:id], ticket3.id) assert_equal(result[1][:tickets][0][:id], ticket3.id)
assert_equal(result[1][:tickets][1][:id], ticket1.id) assert_equal(result[1][:tickets][1][:id], ticket1.id)
assert_equal(result[1][:count], 2) assert_equal(result[1][:count], 2)
@ -828,18 +828,18 @@ class TicketOverviewTest < ActiveSupport::TestCase
assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:count], 0) assert_equal(result[0][:count], 0)
assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets].class, Array)
assert(result[0][:tickets].empty?) assert(result[0][:tickets].blank?)
assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:id], @overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array) assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?) assert(result[1][:tickets].blank?)
assert_equal(result[1][:count], 0) assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:id], @overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?) assert(result[2][:tickets].blank?)
end end

View file

@ -14,6 +14,7 @@ class UserOutOfOfficeTest < ActiveSupport::TestCase
email: 'user-out_of_office-agent1@example.com', email: 'user-out_of_office-agent1@example.com',
password: 'agentpw', password: 'agentpw',
active: true, active: true,
out_of_office: false,
roles: roles, roles: roles,
groups: groups, groups: groups,
) )
@ -24,6 +25,7 @@ class UserOutOfOfficeTest < ActiveSupport::TestCase
email: 'user-out_of_office-agent2@example.com', email: 'user-out_of_office-agent2@example.com',
password: 'agentpw', password: 'agentpw',
active: true, active: true,
out_of_office: false,
roles: roles, roles: roles,
groups: groups, groups: groups,
) )
@ -34,6 +36,7 @@ class UserOutOfOfficeTest < ActiveSupport::TestCase
email: 'user-out_of_office-agent3@example.com', email: 'user-out_of_office-agent3@example.com',
password: 'agentpw', password: 'agentpw',
active: true, active: true,
out_of_office: false,
roles: roles, roles: roles,
groups: groups, groups: groups,
) )
@ -99,6 +102,9 @@ class UserOutOfOfficeTest < ActiveSupport::TestCase
travel 2.days travel 2.days
assert(@agent1.out_of_office?) assert(@agent1.out_of_office?)
assert(@agent1.out_of_office_agent_of.blank?)
assert_equal(1, @agent2.out_of_office_agent_of.count)
assert_equal(@agent1.id, @agent2.out_of_office_agent_of[0].id)
travel 1.day travel 1.day
@ -116,6 +122,9 @@ class UserOutOfOfficeTest < ActiveSupport::TestCase
assert_not(@agent2.out_of_office_agent) assert_not(@agent2.out_of_office_agent)
assert_equal(0, @agent1.out_of_office_agent_of.count)
assert_equal(0, @agent2.out_of_office_agent_of.count)
@agent2.out_of_office = true @agent2.out_of_office = true
@agent2.out_of_office_start_at = Time.zone.now @agent2.out_of_office_start_at = Time.zone.now
@agent2.out_of_office_end_at = Time.zone.now + 4.days @agent2.out_of_office_end_at = Time.zone.now + 4.days
@ -126,6 +135,23 @@ class UserOutOfOfficeTest < ActiveSupport::TestCase
assert_equal(@agent2.out_of_office_agent.id, @agent3.id) assert_equal(@agent2.out_of_office_agent.id, @agent3.id)
assert_equal(0, @agent1.out_of_office_agent_of.count)
assert_equal(0, @agent2.out_of_office_agent_of.count)
assert_equal(1, @agent3.out_of_office_agent_of.count)
assert_equal(@agent2.id, @agent3.out_of_office_agent_of[0].id)
travel 4.days
assert_equal(0, @agent1.out_of_office_agent_of.count)
assert_equal(0, @agent2.out_of_office_agent_of.count)
assert_equal(1, @agent3.out_of_office_agent_of.count)
assert_equal(@agent2.id, @agent3.out_of_office_agent_of[0].id)
travel 1.day
assert_equal(0, @agent1.out_of_office_agent_of.count)
assert_equal(0, @agent2.out_of_office_agent_of.count)
assert_equal(0, @agent3.out_of_office_agent_of.count)
end end
end end