Added calendar subscription tests.

This commit is contained in:
Martin Edenhofer 2016-02-26 13:19:57 +01:00
parent d4def003ba
commit 9084c99d4b
5 changed files with 611 additions and 159 deletions

View file

@ -414,6 +414,10 @@ condition example
pre_condition: 'specific',
value: 4711,
},
'ticket.escalation_time' => {
operator: 'is not', # not
value: nil,
}
}
=end
@ -463,8 +467,8 @@ condition example
selector = selector_raw.stringify_keys
fail "Invalid selector, operator missing #{selector.inspect}" if !selector['operator']
# validate value / allow empty but only if pre_condition eyists
if selector['value'].nil? || (selector['value'].respond_to?(:empty?) && selector['value'].empty?)
# validate value / allow empty but only if pre_condition exists
if (selector['value'].class == String || selector['value'].class == Array) && (selector['value'].respond_to?(:empty?) && selector['value'].empty?)
return nil if selector['pre_condition'].nil? || (selector['pre_condition'].respond_to?(:empty?) && selector['pre_condition'].empty?)
end
@ -497,8 +501,14 @@ condition example
user = User.lookup(id: current_user_id)
bind_params.push user.organization_id
else
query += "#{attribute} IN (?)"
bind_params.push selector['value']
# rubocop:disable Style/IfInsideElse
if selector['value'].nil?
query += "#{attribute} NOT NULL"
else
query += "#{attribute} IN (?)"
bind_params.push selector['value']
end
# rubocop:enable Style/IfInsideElse
end
elsif selector['operator'] == 'is not'
if selector['pre_condition'] == 'set'
@ -516,8 +526,14 @@ condition example
user = User.lookup(id: current_user_id)
bind_params.push user.organization_id
else
query += "#{attribute} NOT IN (?)"
bind_params.push selector['value']
# rubocop:disable Style/IfInsideElse
if selector['value'].nil?
query += "#{attribute} IS NOT NULL"
else
query += "#{attribute} NOT IN (?)"
bind_params.push selector['value']
end
# rubocop:enable Style/IfInsideElse
end
elsif selector['operator'] == 'contains'
query += "#{attribute} #{like} (?)"

View file

@ -6,7 +6,7 @@ class CalendarSubscriptions
@user = user
@preferences = {}
default_preferences = Setting.where( area: 'Defaults::CalendarSubscriptions' )
default_preferences = Setting.where(area: 'Defaults::CalendarSubscriptions')
default_preferences.each { |calendar_subscription|
next if calendar_subscription.name !~ /\Adefaults_calendar_subscriptions_(.*)\z/
@ -17,16 +17,16 @@ class CalendarSubscriptions
return if !@user.preferences[:calendar_subscriptions]
return if @user.preferences[:calendar_subscriptions].empty?
@preferences = @preferences.merge( @user.preferences[:calendar_subscriptions] )
@preferences = @preferences.merge(@user.preferences[:calendar_subscriptions])
end
def all
events_data = []
@preferences.each { |object_name, _sub_structure|
result = generic_call( object_name )
result = generic_call(object_name)
events_data = events_data + result
}
to_ical( events_data )
to_ical(events_data)
end
def generic(object_name, method_name = 'all')
@ -42,8 +42,8 @@ class CalendarSubscriptions
if @preferences[ object_name ] && !@preferences[ object_name ].empty?
sub_class_name = object_name.to_s.capitalize
object = Object.const_get("CalendarSubscriptions::#{sub_class_name}")
instance = object.new( @user, @preferences[ object_name ] )
method = instance.method( method_name )
instance = object.new(@user, @preferences[ object_name ])
method = instance.method(method_name)
events_data += method.call
end
events_data

View file

@ -188,7 +188,7 @@ class CalendarSubscriptions::Tickets
event_data[:dtstart] = Icalendar::Values::DateTime.new(escalation_time, 'tzid' => @tzid)
event_data[:dtend] = Icalendar::Values::DateTime.new(escalation_time, 'tzid' => @tzid)
event_data[:summary] = "#{translated_ticket_escalation}: '#{ticket.title}' #{customer}: #{ticket.customer.longname} "
event_data[:summary] = "#{translated_ticket_escalation}: '#{ticket.title}' #{customer}: #{ticket.customer.longname}"
event_data[:description] = "T##{ticket.number}"
event_data[:alarm] = {
summary: event_data[:summary],

View file

@ -0,0 +1,396 @@
# encoding: utf-8
require 'test_helper'
class CalendarSubscriptionTest < ActiveSupport::TestCase
test 'default test' do
# create base
group_default = Group.lookup(name: 'Users')
group_calendar = Group.create_or_update(
name: 'CalendarSubscription',
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where(name: 'Agent')
agent1 = User.create_or_update(
login: 'ticket-calendar-subscription-agent1@example.com',
firstname: 'Notification',
lastname: 'Agent1',
email: 'ticket-calendar-subscription-agent1@example.com',
password: 'agentpw',
active: true,
roles: roles,
groups: [group_calendar],
preferences: {},
updated_by_id: 1,
created_by_id: 1,
)
agent2 = User.create_or_update(
login: 'ticket-calendar-subscription-agent2@example.com',
firstname: 'Notification',
lastname: 'Agent2',
email: 'ticket-calendar-subscription-agent2@example.com',
password: 'agentpw',
active: true,
roles: roles,
groups: [group_default],
preferences: {},
updated_at: '2016-02-05 16:38:00',
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where(name: 'Customer')
organization1 = Organization.create_if_not_exists(
name: 'Selector Org',
updated_at: '2016-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
customer1 = User.create_or_update(
login: 'ticket-calendar-subscription-customer1@example.com',
firstname: 'Notification',
lastname: 'Customer1',
email: 'ticket-calendar-subscription-customer1@example.com',
password: 'customerpw',
active: true,
organization_id: organization1.id,
roles: roles,
preferences: {},
updated_at: '2016-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
customer2 = User.create_or_update(
login: 'ticket-calendar-subscription-customer2@example.com',
firstname: 'Notification',
lastname: 'Customer2',
email: 'ticket-calendar-subscription-customer2@example.com',
password: 'customerpw',
active: true,
organization_id: nil,
roles: roles,
preferences: {},
updated_at: '2016-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
Ticket.destroy_all
ticket1 = Ticket.create(
title: 'some title1 - new - group_calendar',
group: group_calendar,
customer_id: customer1.id,
owner_id: agent1.id,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket2 = Ticket.create(
title: 'some title1 - new - group_default',
group: group_default,
customer_id: customer1.id,
owner_id: agent2.id,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket3 = Ticket.create(
title: 'some title1 - pending - group_calendar',
group: group_calendar,
customer_id: customer1.id,
owner_id: agent1.id,
state: Ticket::State.lookup(name: 'pending reminder'),
pending_time: '2016-02-07 16:37:00',
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket4 = Ticket.create(
title: 'some title1 - pending - group_default',
group: group_default,
customer_id: customer1.id,
owner_id: agent2.id,
state: Ticket::State.lookup(name: 'pending reminder'),
pending_time: '2016-02-07 16:37:00',
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket5 = Ticket.create(
title: 'some title1 - escalation - group_calendar',
group: group_calendar,
customer_id: customer1.id,
owner_id: agent1.id,
state: Ticket::State.lookup(name: 'new'),
escalation_time: '2016-02-07 17:37:00',
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket6 = Ticket.create(
title: 'some title1 - escalation - group_default',
group: group_default,
customer_id: customer1.id,
owner_id: agent2.id,
state: Ticket::State.lookup(name: 'new'),
escalation_time: '2016-02-07 16:37:00',
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 16:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket7 = Ticket.create(
title: 'some title2 - new - group_calendar',
group: group_calendar,
customer_id: customer1.id,
owner_id: 1,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 17:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket8 = Ticket.create(
title: 'some title2 - new - group_default',
group: group_default,
customer_id: customer1.id,
owner_id: 1,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 17:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket9 = Ticket.create(
title: 'some title2 - pending - group_calendar',
group: group_calendar,
customer_id: customer1.id,
owner_id: 1,
state: Ticket::State.lookup(name: 'pending reminder'),
pending_time: '2016-02-08 16:37:00',
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 17:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket10 = Ticket.create(
title: 'some title2 - pending - group_default',
group: group_default,
customer_id: customer1.id,
owner_id: 1,
state: Ticket::State.lookup(name: 'pending reminder'),
pending_time: '2016-02-08 16:37:00',
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 17:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket11 = Ticket.create(
title: 'some title2 - escalation - group_calendar',
group: group_calendar,
customer_id: customer1.id,
owner_id: 1,
state: Ticket::State.lookup(name: 'new'),
escalation_time: '2016-02-08 17:37:00',
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 17:37:00',
updated_by_id: 1,
created_by_id: 1,
)
ticket12 = Ticket.create(
title: 'some title2 - escalation - group_default',
group: group_default,
customer_id: customer1.id,
owner_id: 1,
state: Ticket::State.lookup(name: 'new'),
escalation_time: '2016-02-08 16:37:00',
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2016-02-05 17:37:00',
updated_by_id: 1,
created_by_id: 1,
)
# check agent 1
calendar_subscriptions = CalendarSubscriptions.new(agent1)
ical_file = calendar_subscriptions.all
cals = Icalendar.parse(ical_file)
assert_equal(cals.count, 1)
cal = cals.first
assert_equal(cals.count, 1)
assert_equal(cal.events.count, 4)
assert_equal(cal.events[0].dtstart, Time.zone.today)
assert_equal(cal.events[0].summary, 'new ticket: \'some title1 - new - group_calendar\'')
assert_equal(cal.events[0].description, "T##{ticket1.number}")
assert_equal(cal.events[1].dtstart, Time.zone.today)
assert_equal(cal.events[1].summary, 'new ticket: \'some title1 - escalation - group_calendar\'')
assert_equal(cal.events[1].description, "T##{ticket5.number}")
assert_equal(cal.events[2].dtstart, Time.zone.today)
assert_equal(cal.events[2].summary, 'pending reminder ticket: \'some title1 - pending - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[2].description, "T##{ticket3.number}")
assert_equal(cal.events[3].dtstart, Time.zone.today)
assert_equal(cal.events[3].summary, 'ticket escalation: \'some title1 - escalation - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[3].description, "T##{ticket5.number}")
if !agent1.preferences[:calendar_subscriptions]
agent1.preferences[:calendar_subscriptions] = {}
end
agent1.preferences[:calendar_subscriptions][:tickets] = {
escalation: {
own: true,
not_assigned: true,
},
new_open: {
own: true,
not_assigned: true,
},
pending: {
own: true,
not_assigned: true,
}
}
agent1.save!
calendar_subscriptions = CalendarSubscriptions.new(agent1)
ical_file = calendar_subscriptions.all
cals = Icalendar.parse(ical_file)
assert_equal(cals.count, 1)
cal = cals.first
assert_equal(cals.count, 1)
assert_equal(cal.events.count, 8)
assert_equal(cal.events[0].dtstart, Time.zone.today)
assert_equal(cal.events[0].summary, 'new ticket: \'some title2 - new - group_calendar\'')
assert_equal(cal.events[0].description, "T##{ticket7.number}")
assert_equal(cal.events[1].dtstart, Time.zone.today)
assert_equal(cal.events[1].summary, 'new ticket: \'some title2 - escalation - group_calendar\'')
assert_equal(cal.events[1].description, "T##{ticket11.number}")
assert_equal(cal.events[2].dtstart, Time.zone.today)
assert_equal(cal.events[2].summary, 'new ticket: \'some title1 - new - group_calendar\'')
assert_equal(cal.events[2].description, "T##{ticket1.number}")
assert_equal(cal.events[3].dtstart, Time.zone.today)
assert_equal(cal.events[3].summary, 'new ticket: \'some title1 - escalation - group_calendar\'')
assert_equal(cal.events[3].description, "T##{ticket5.number}")
assert_equal(cal.events[4].dtstart, Time.zone.today)
assert_equal(cal.events[4].summary, 'pending reminder ticket: \'some title2 - pending - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[4].description, "T##{ticket9.number}")
assert_equal(cal.events[5].dtstart, Time.zone.today)
assert_equal(cal.events[5].summary, 'pending reminder ticket: \'some title1 - pending - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[5].description, "T##{ticket3.number}")
assert_equal(cal.events[6].dtstart, Time.zone.today)
assert_equal(cal.events[6].summary, 'ticket escalation: \'some title2 - escalation - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[6].description, "T##{ticket11.number}")
assert_equal(cal.events[7].dtstart, Time.zone.today)
assert_equal(cal.events[7].summary, 'ticket escalation: \'some title1 - escalation - group_calendar\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[7].description, "T##{ticket5.number}")
# check agent 2
calendar_subscriptions = CalendarSubscriptions.new(agent2)
ical_file = calendar_subscriptions.all
cals = Icalendar.parse(ical_file)
assert_equal(cals.count, 1)
cal = cals.first
assert_equal(cals.count, 1)
assert_equal(cal.events.count, 4)
assert_equal(cal.events[0].dtstart, Time.zone.today)
assert_equal(cal.events[0].summary, 'new ticket: \'some title1 - new - group_default\'')
assert_equal(cal.events[0].description, "T##{ticket2.number}")
assert_equal(cal.events[1].dtstart, Time.zone.today)
assert_equal(cal.events[1].summary, 'new ticket: \'some title1 - escalation - group_default\'')
assert_equal(cal.events[1].description, "T##{ticket6.number}")
assert_equal(cal.events[2].dtstart, Time.zone.today)
assert_equal(cal.events[2].summary, 'pending reminder ticket: \'some title1 - pending - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[2].description, "T##{ticket4.number}")
assert_equal(cal.events[3].dtstart, Time.zone.today)
assert_equal(cal.events[3].summary, 'ticket escalation: \'some title1 - escalation - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[3].description, "T##{ticket6.number}")
if !agent2.preferences[:calendar_subscriptions]
agent2.preferences[:calendar_subscriptions] = {}
end
agent2.preferences[:calendar_subscriptions][:tickets] = {
escalation: {
own: true,
not_assigned: true,
},
new_open: {
own: true,
not_assigned: true,
},
pending: {
own: true,
not_assigned: true,
}
}
agent2.save!
calendar_subscriptions = CalendarSubscriptions.new(agent2)
ical_file = calendar_subscriptions.all
cals = Icalendar.parse(ical_file)
assert_equal(cals.count, 1)
cal = cals.first
assert_equal(cals.count, 1)
assert_equal(cal.events.count, 8)
assert_equal(cal.events[0].dtstart, Time.zone.today)
assert_equal(cal.events[0].summary, 'new ticket: \'some title2 - new - group_default\'')
assert_equal(cal.events[0].description, "T##{ticket8.number}")
assert_equal(cal.events[1].dtstart, Time.zone.today)
assert_equal(cal.events[1].summary, 'new ticket: \'some title2 - escalation - group_default\'')
assert_equal(cal.events[1].description, "T##{ticket12.number}")
assert_equal(cal.events[2].dtstart, Time.zone.today)
assert_equal(cal.events[2].summary, 'new ticket: \'some title1 - new - group_default\'')
assert_equal(cal.events[2].description, "T##{ticket2.number}")
assert_equal(cal.events[3].dtstart, Time.zone.today)
assert_equal(cal.events[3].summary, 'new ticket: \'some title1 - escalation - group_default\'')
assert_equal(cal.events[3].description, "T##{ticket6.number}")
assert_equal(cal.events[4].dtstart, Time.zone.today)
assert_equal(cal.events[4].summary, 'pending reminder ticket: \'some title2 - pending - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[4].description, "T##{ticket10.number}")
assert_equal(cal.events[5].dtstart, Time.zone.today)
assert_equal(cal.events[5].summary, 'pending reminder ticket: \'some title1 - pending - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[5].description, "T##{ticket4.number}")
assert_equal(cal.events[6].dtstart, Time.zone.today)
assert_equal(cal.events[6].summary, 'ticket escalation: \'some title2 - escalation - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[6].description, "T##{ticket12.number}")
assert_equal(cal.events[7].dtstart, Time.zone.today)
assert_equal(cal.events[7].summary, 'ticket escalation: \'some title1 - escalation - group_default\' customer: Notification Customer1 (Selector Org)')
assert_equal(cal.events[7].description, "T##{ticket6.number}")
end
end

View file

@ -10,7 +10,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where( name: 'Agent' )
roles = Role.where(name: 'Agent')
agent1 = User.create_or_update(
login: 'ticket-selector-agent1@example.com',
firstname: 'Notification',
@ -37,7 +37,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
roles = Role.where( name: 'Customer' )
roles = Role.where(name: 'Customer')
organization1 = Organization.create_if_not_exists(
name: 'Selector Org',
updated_at: '2015-02-05 16:37:00',
@ -75,37 +75,56 @@ class TicketSelectorTest < ActiveSupport::TestCase
test 'ticket create' do
Ticket.destroy_all
ticket1 = Ticket.create(
title: 'some title1',
group: group,
customer_id: customer1.id,
owner_id: agent1.id,
state: Ticket::State.lookup( name: 'new' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2015-02-05 16:37:00',
#updated_at: '2015-02-05 17:37:00',
updated_by_id: 1,
created_by_id: 1,
)
assert( ticket1, 'ticket created' )
assert_equal( ticket1.customer.id, customer1.id )
assert_equal( ticket1.organization.id, organization1.id )
assert(ticket1, 'ticket created')
assert_equal(ticket1.customer.id, customer1.id)
assert_equal(ticket1.organization.id, organization1.id)
sleep 1
ticket2 = Ticket.create(
title: 'some title2',
group: group,
customer_id: customer2.id,
state: Ticket::State.lookup( name: 'new' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2015-02-05 16:37:00',
#updated_at: '2015-02-05 17:37:00',
updated_by_id: 1,
created_by_id: 1,
)
assert( ticket2, 'ticket created' )
assert_equal( ticket2.customer.id, customer2.id )
assert_equal( ticket2.organization_id, nil )
assert(ticket2, 'ticket created')
assert_equal(ticket2.customer.id, customer2.id)
assert_equal(ticket2.organization_id, nil)
sleep 1
ticket3 = Ticket.create(
title: 'some title3',
group: group,
customer_id: customer2.id,
state: Ticket::State.lookup(name: 'open'),
priority: Ticket::Priority.lookup(name: '2 normal'),
escalation_time: '2015-02-06 10:00:00',
created_at: '2015-02-05 16:37:00',
#updated_at: '2015-02-05 17:37:00',
updated_by_id: 1,
created_by_id: 1,
)
assert(ticket3, 'ticket created')
assert_equal(ticket3.customer.id, customer2.id)
assert_equal(ticket3.organization_id, nil)
sleep 1
# search not matching
@ -116,16 +135,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
# search matching
condition = {
@ -135,24 +154,24 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
'ticket.state_id' => {
operator: 'is',
value: [Ticket::State.lookup( name: 'new' ).id],
value: [Ticket::State.lookup(name: 'new').id],
},
}
ticket_count, tickets = Ticket.selectors(condition, 10)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
condition = {
'ticket.group_id' => {
@ -161,23 +180,44 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
'ticket.state_id' => {
operator: 'is not',
value: [Ticket::State.lookup( name: 'open' ).id],
value: [Ticket::State.lookup(name: 'open').id],
},
}
ticket_count, tickets = Ticket.selectors(condition, 10)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
condition = {
'ticket.escalation_time' => {
operator: 'is not',
value: nil,
}
}
ticket_count, tickets = Ticket.selectors(condition, 10)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal(ticket_count, 1)
# search - created_at
condition = {
@ -191,16 +231,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
@ -213,16 +253,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
@ -235,16 +275,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
@ -257,16 +297,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
@ -280,16 +320,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
@ -303,16 +343,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
@ -326,16 +366,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
# search - updated_at
condition = {
@ -349,16 +389,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
@ -371,16 +411,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
@ -393,16 +433,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
@ -415,16 +455,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
@ -438,16 +478,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
@ -461,16 +501,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
condition = {
'ticket.group_id' => {
@ -484,16 +524,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
# invalid conditions
assert_raise RuntimeError do
@ -512,16 +552,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
@ -534,16 +574,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 2 )
assert_equal(ticket_count, 3)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
# search with organizations
condition = {
@ -557,16 +597,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
# search with organizations
condition = {
@ -584,16 +624,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
@ -610,16 +650,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
# with owner/customer/org
condition = {
@ -634,16 +674,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
@ -656,16 +696,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
condition = {
'ticket.group_id' => {
@ -678,16 +718,16 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
UserInfo.current_user_id = agent1.id
condition = {
@ -701,19 +741,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
UserInfo.current_user_id = agent2.id
condition = {
@ -727,19 +767,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
UserInfo.current_user_id = customer1.id
condition = {
@ -753,19 +793,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
UserInfo.current_user_id = customer2.id
condition = {
@ -779,19 +819,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
ticket_count, tickets = Ticket.selectors(condition, 10)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 2)
UserInfo.current_user_id = customer1.id
condition = {
@ -805,19 +845,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
UserInfo.current_user_id = customer2.id
condition = {
@ -831,19 +871,19 @@ class TicketSelectorTest < ActiveSupport::TestCase
},
}
ticket_count, tickets = Ticket.selectors(condition, 10, agent1)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, agent2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10, customer1)
assert_equal( ticket_count, 1 )
assert_equal(ticket_count, 1)
ticket_count, tickets = Ticket.selectors(condition, 10, customer2)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
ticket_count, tickets = Ticket.selectors(condition, 10)
assert_equal( ticket_count, 0 )
assert_equal(ticket_count, 0)
end