Fixed issue#448 - New overview with article conditions not working.

This commit is contained in:
Martin Edenhofer 2016-11-21 15:59:31 +01:00
parent 25eaae05e3
commit 31b4138ab5
2 changed files with 569 additions and 12 deletions

View file

@ -90,13 +90,36 @@ returns
# get only tickets with permissions # get only tickets with permissions
access_condition = Ticket.access_condition(user) access_condition = Ticket.access_condition(user)
ticket_attributes = Ticket.new.attributes
list = [] list = []
overviews.each { |overview| overviews.each { |overview|
query_condition, bind_condition, tables = Ticket.selector2sql(overview.condition, user) query_condition, bind_condition, tables = Ticket.selector2sql(overview.condition, user)
order_by = "#{overview.order[:by]} #{overview.order[:direction]}" # validate direction
raise "Invalid order direction '#{overview.order[:direction]}'" if overview.order[:direction] && overview.order[:direction] !~ /^(ASC|DESC)$/i
# check if order by exists
order_by = overview.order[:by]
if !ticket_attributes.key?(order_by)
order_by = if ticket_attributes.key?("#{order_by}_id")
"#{order_by}_id"
else
'created_at'
end
end
order_by = "tickets.#{order_by} #{overview.order[:direction]}"
# check if group by exists
if overview.group_by && !overview.group_by.empty? if overview.group_by && !overview.group_by.empty?
order_by = "#{overview.group_by}_id, #{order_by}" group_by = overview.group_by
if !ticket_attributes.key?(group_by)
group_by = if ticket_attributes.key?("#{group_by}_id")
"#{group_by}_id"
end
end
if group_by
order_by = "tickets.#{group_by}, #{order_by}"
end
end end
ticket_result = Ticket.select('id, updated_at') ticket_result = Ticket.select('id, updated_at')
@ -115,9 +138,10 @@ returns
} }
tickets.push ticket_item tickets.push ticket_item
} }
count = Ticket.where(access_condition).where(query_condition, *bind_condition).count() count = Ticket.where(access_condition).where(query_condition, *bind_condition).joins(tables).count()
item = { item = {
overview: { overview: {
name: overview.name,
id: overview.id, id: overview.id,
view: overview.link, view: overview.link,
updated_at: overview.updated_at, updated_at: overview.updated_at,

View file

@ -8,6 +8,14 @@ class TicketOverviewTest < ActiveSupport::TestCase
customer1 = nil customer1 = nil
customer2 = nil customer2 = nil
customer3 = nil customer3 = nil
overview1 = nil
overview2 = nil
overview3 = nil
overview4 = nil
overview5 = nil
overview6 = nil
overview7 = nil
overview8 = nil
test 'aaa - setup' do test 'aaa - setup' do
# create base # create base
@ -93,7 +101,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
Overview.destroy_all Overview.destroy_all
UserInfo.current_user_id = 1 UserInfo.current_user_id = 1
overview_role = Role.find_by(name: 'Agent') overview_role = Role.find_by(name: 'Agent')
Overview.create_or_update( overview1 = Overview.create_or_update(
name: 'My assigned Tickets', name: 'My assigned Tickets',
link: 'my_assigned', link: 'my_assigned',
prio: 1000, prio: 1000,
@ -120,7 +128,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
}, },
) )
Overview.create_or_update( overview2 = Overview.create_or_update(
name: 'Unassigned & Open', name: 'Unassigned & Open',
link: 'all_unassigned', link: 'all_unassigned',
prio: 1010, prio: 1010,
@ -146,7 +154,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
view_mode_default: 's', view_mode_default: 's',
}, },
) )
Overview.create_or_update( overview3 = Overview.create_or_update(
name: 'My Tickets 2', name: 'My Tickets 2',
link: 'my_tickets_2', link: 'my_tickets_2',
prio: 1020, prio: 1020,
@ -173,9 +181,36 @@ class TicketOverviewTest < ActiveSupport::TestCase
view_mode_default: 's', view_mode_default: 's',
}, },
) )
overview4 = Overview.create_or_update(
name: 'My Tickets only with Note',
link: 'my_tickets_onyl_with_note',
prio: 1030,
role_id: overview_role.id,
user_ids: [agent1.id],
condition: {
'article.type_id' => {
operator: 'is',
value: Ticket::Article::Type.find_by(name: 'note').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') overview_role = Role.find_by(name: 'Customer')
Overview.create_or_update( overview5 = Overview.create_or_update(
name: 'My Tickets', name: 'My Tickets',
link: 'my_tickets', link: 'my_tickets',
prio: 1100, prio: 1100,
@ -201,7 +236,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
view_mode_default: 's', view_mode_default: 's',
}, },
) )
Overview.create_or_update( overview6 = Overview.create_or_update(
name: 'My Organization Tickets', name: 'My Organization Tickets',
link: 'my_organization_tickets', link: 'my_organization_tickets',
prio: 1200, prio: 1200,
@ -228,7 +263,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
view_mode_default: 's', view_mode_default: 's',
}, },
) )
Overview.create_or_update( overview7 = Overview.create_or_update(
name: 'My Organization Tickets (open)', name: 'My Organization Tickets (open)',
link: 'my_organization_tickets_open', link: 'my_organization_tickets_open',
prio: 1200, prio: 1200,
@ -258,7 +293,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
) )
overview_role = Role.find_by(name: 'Admin') overview_role = Role.find_by(name: 'Admin')
Overview.create_or_update( overview8 = Overview.create_or_update(
name: 'Not Shown Admin', name: 'Not Shown Admin',
link: 'not_shown_admin', link: 'not_shown_admin',
prio: 9900, prio: 9900,
@ -282,14 +317,15 @@ class TicketOverviewTest < ActiveSupport::TestCase
) )
end end
test 'ticket create' do test 'bbb overiview index' do
result = Ticket::Overviews.all( result = Ticket::Overviews.all(
current_user: agent1, current_user: agent1,
) )
assert_equal(2, result.count) assert_equal(3, result.count)
assert_equal('My assigned Tickets', result[0].name) assert_equal('My assigned Tickets', result[0].name)
assert_equal('Unassigned & Open', result[1].name) assert_equal('Unassigned & Open', result[1].name)
assert_equal('My Tickets only with Note', result[2].name)
result = Ticket::Overviews.all( result = Ticket::Overviews.all(
current_user: agent2, current_user: agent2,
@ -322,4 +358,501 @@ class TicketOverviewTest < ActiveSupport::TestCase
end end
test 'ccc overiview content' do
Ticket.destroy_all
result = Ticket::Overviews.index(agent1)
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].empty?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
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][:tickets].class, Array)
assert(result[2][:tickets].empty?)
assert_equal(result[2][:count], 0)
result = Ticket::Overviews.index(agent2)
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].empty?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
ticket1 = Ticket.create(
title: 'overview test 1',
group: Group.lookup(name: 'OverviewTest'),
customer_id: 2,
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_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].empty?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?)
assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:count], 1)
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][:tickets].class, Array)
assert(result[2][:tickets].empty?)
assert_equal(result[2][:count], 0)
result = Ticket::Overviews.index(agent2)
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].empty?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
ticket2 = Ticket.create(
title: 'overview test 2',
group: Group.lookup(name: 'OverviewTest'),
customer_id: 2,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '3 high'),
updated_by_id: 1,
created_by_id: 1,
)
article2 = Ticket::Article.create(
ticket_id: ticket2.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: 'some message... 123',
internal: false,
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
type: Ticket::Article::Type.find_by(name: 'note'),
updated_by_id: 1,
created_by_id: 1,
)
result = Ticket::Overviews.index(agent1)
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].empty?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?)
assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:tickets][1][:id], ticket2.id)
assert_equal(result[1][:count], 2)
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][:tickets].class, Array)
assert(result[2][:tickets].empty?)
assert_equal(result[2][:count], 0)
result = Ticket::Overviews.index(agent2)
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].empty?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
ticket2.owner_id = agent1.id
ticket2.save!
result = Ticket::Overviews.index(agent1)
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[0][:tickets][0][:id], ticket2.id)
assert_equal(result[0][:count], 1)
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?)
assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:count], 1)
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][:tickets].class, Array)
assert_equal(result[2][:tickets][0][:id], ticket2.id)
assert_equal(result[2][:count], 1)
result = Ticket::Overviews.index(agent2)
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].empty?)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
ticket3 = Ticket.create(
title: 'overview test 3',
group: Group.lookup(name: 'OverviewTest'),
customer_id: 2,
state: Ticket::State.lookup(name: 'new'),
priority: Ticket::Priority.lookup(name: '1 low'),
updated_by_id: 1,
created_by_id: 1,
)
article3 = Ticket::Article.create(
ticket_id: ticket3.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
message_id: 'some@id',
body: 'some message... 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_equal(result[0][:overview][:id], overview1.id)
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[0][:tickets][0][:id], ticket2.id)
assert_equal(result[0][:count], 1)
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?)
assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:tickets][1][:id], ticket3.id)
assert_equal(result[1][:count], 2)
assert_equal(result[2][:overview][:id], overview4.id)
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][:tickets].class, Array)
assert_equal(result[2][:tickets][0][:id], ticket2.id)
assert_equal(result[2][:count], 1)
result = Ticket::Overviews.index(agent2)
assert_equal(result[0][:overview][:id], overview1.id)
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].empty?)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
overview2.order = {
by: 'created_at',
direction: 'DESC',
}
overview2.save!
result = Ticket::Overviews.index(agent1)
assert_equal(result[0][:overview][:id], overview1.id)
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[0][:tickets][0][:id], ticket2.id)
assert_equal(result[0][:count], 1)
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?)
assert_equal(result[1][:tickets][0][:id], ticket3.id)
assert_equal(result[1][:tickets][1][:id], ticket1.id)
assert_equal(result[1][:count], 2)
assert_equal(result[2][:overview][:id], overview4.id)
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][:tickets].class, Array)
assert_equal(result[2][:tickets][0][:id], ticket2.id)
assert_equal(result[2][:count], 1)
result = Ticket::Overviews.index(agent2)
assert_equal(result[0][:overview][:id], overview1.id)
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].empty?)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
overview2.order = {
by: 'priority_id',
direction: 'DESC',
}
overview2.save!
result = Ticket::Overviews.index(agent1)
assert_equal(result[0][:overview][:id], overview1.id)
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[0][:tickets][0][:id], ticket2.id)
assert_equal(result[0][:count], 1)
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?)
assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:tickets][1][:id], ticket3.id)
assert_equal(result[1][:count], 2)
assert_equal(result[2][:overview][:id], overview4.id)
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][:tickets].class, Array)
assert_equal(result[2][:tickets][0][:id], ticket2.id)
assert_equal(result[2][:count], 1)
result = Ticket::Overviews.index(agent2)
assert_equal(result[0][:overview][:id], overview1.id)
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].empty?)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
overview2.order = {
by: 'priority_id',
direction: 'ASC',
}
overview2.save!
result = Ticket::Overviews.index(agent1)
assert_equal(result[0][:overview][:id], overview1.id)
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[0][:tickets][0][:id], ticket2.id)
assert_equal(result[0][:count], 1)
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?)
assert_equal(result[1][:tickets][0][:id], ticket3.id)
assert_equal(result[1][:tickets][1][:id], ticket1.id)
assert_equal(result[1][:count], 2)
assert_equal(result[2][:overview][:id], overview4.id)
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][:tickets].class, Array)
assert_equal(result[2][:tickets][0][:id], ticket2.id)
assert_equal(result[2][:count], 1)
result = Ticket::Overviews.index(agent2)
assert_equal(result[0][:overview][:id], overview1.id)
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].empty?)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
overview2.order = {
by: 'priority',
direction: 'DESC',
}
overview2.save!
result = Ticket::Overviews.index(agent1)
assert_equal(result[0][:overview][:id], overview1.id)
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[0][:tickets][0][:id], ticket2.id)
assert_equal(result[0][:count], 1)
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?)
assert_equal(result[1][:tickets][0][:id], ticket1.id)
assert_equal(result[1][:tickets][1][:id], ticket3.id)
assert_equal(result[1][:count], 2)
assert_equal(result[2][:overview][:id], overview4.id)
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][:tickets].class, Array)
assert_equal(result[2][:tickets][0][:id], ticket2.id)
assert_equal(result[2][:count], 1)
result = Ticket::Overviews.index(agent2)
assert_equal(result[0][:overview][:id], overview1.id)
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].empty?)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
overview2.order = {
by: 'priority',
direction: 'ASC',
}
overview2.save!
result = Ticket::Overviews.index(agent1)
assert_equal(result[0][:overview][:id], overview1.id)
assert_equal(result[0][:overview][:name], 'My assigned Tickets')
assert_equal(result[0][:overview][:view], 'my_assigned')
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[0][:tickets][0][:id], ticket2.id)
assert_equal(result[0][:count], 1)
assert_equal(result[0][:tickets].class, Array)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert_not(result[1][:tickets].empty?)
assert_equal(result[1][:tickets][0][:id], ticket3.id)
assert_equal(result[1][:tickets][1][:id], ticket1.id)
assert_equal(result[1][:count], 2)
assert_equal(result[2][:overview][:id], overview4.id)
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][:tickets].class, Array)
assert_equal(result[2][:tickets][0][:id], ticket2.id)
assert_equal(result[2][:count], 1)
result = Ticket::Overviews.index(agent2)
assert_equal(result[0][:overview][:id], overview1.id)
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].empty?)
assert_equal(result[1][:overview][:id], overview2.id)
assert_equal(result[1][:overview][:name], 'Unassigned & Open')
assert_equal(result[1][:overview][:view], 'all_unassigned')
assert_equal(result[1][:tickets].class, Array)
assert(result[1][:tickets].empty?)
assert_equal(result[1][:count], 0)
assert_equal(result[2][:overview][:id], overview3.id)
assert_equal(result[2][:overview][:name], 'My Tickets 2')
assert_equal(result[2][:overview][:view], 'my_tickets_2')
assert_equal(result[2][:tickets].class, Array)
assert(result[2][:tickets].empty?)
end
end end