2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2015-10-12 13:44:34 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class TicketSelectorTest < ActiveSupport::TestCase
|
2017-04-12 13:41:54 +00:00
|
|
|
|
2021-07-09 13:05:05 +00:00
|
|
|
setup do
|
2017-06-14 15:25:45 +00:00
|
|
|
@group = Group.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'SelectorTest',
|
|
|
|
updated_at: '2015-02-05 16:37:00',
|
2016-06-20 08:55:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
roles = Role.where(name: 'Agent')
|
|
|
|
@agent1 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'ticket-selector-agent1@example.com',
|
|
|
|
firstname: 'Notification',
|
|
|
|
lastname: 'Agent1',
|
|
|
|
email: 'ticket-selector-agent1@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: [@group],
|
|
|
|
updated_at: '2015-02-05 16:37:00',
|
2016-06-20 08:55:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
@agent2 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'ticket-selector-agent2@example.com',
|
|
|
|
firstname: 'Notification',
|
|
|
|
lastname: 'Agent2',
|
|
|
|
email: 'ticket-selector-agent2@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
updated_at: '2015-02-05 16:38:00',
|
2016-06-20 08:55:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
roles = Role.where(name: 'Customer')
|
2017-06-14 15:25:45 +00:00
|
|
|
@organization1 = Organization.create_if_not_exists(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Selector Org',
|
|
|
|
updated_at: '2015-02-05 16:37:00',
|
2016-06-20 08:55:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
@customer1 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'ticket-selector-customer1@example.com',
|
|
|
|
firstname: 'Notification',
|
|
|
|
lastname: 'Customer1',
|
|
|
|
email: 'ticket-selector-customer1@example.com',
|
|
|
|
password: 'customerpw',
|
|
|
|
active: true,
|
2017-06-14 15:25:45 +00:00
|
|
|
organization_id: @organization1.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
roles: roles,
|
|
|
|
updated_at: '2015-02-05 16:37:00',
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2016-06-20 08:55:45 +00:00
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
@customer2 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'ticket-selector-customer2@example.com',
|
|
|
|
firstname: 'Notification',
|
|
|
|
lastname: 'Customer2',
|
|
|
|
email: 'ticket-selector-customer2@example.com',
|
|
|
|
password: 'customerpw',
|
|
|
|
active: true,
|
2016-06-20 08:55:45 +00:00
|
|
|
organization_id: nil,
|
2018-12-19 17:31:51 +00:00
|
|
|
roles: roles,
|
|
|
|
updated_at: '2015-02-05 16:37:00',
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2016-06-20 08:55:45 +00:00
|
|
|
)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
Ticket.where(group_id: @group.id).destroy_all
|
2016-06-20 08:55:45 +00:00
|
|
|
end
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
test 'ticket create' do
|
|
|
|
|
2016-02-26 12:19:57 +00:00
|
|
|
Ticket.destroy_all
|
|
|
|
|
2016-09-02 10:54:13 +00:00
|
|
|
ticket1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
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'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
2021-07-16 13:44:10 +00:00
|
|
|
# updated_at: '2015-02-05 17:37:00',
|
2015-10-12 13:44:34 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert(ticket1, 'ticket created')
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket1.customer.id, @customer1.id)
|
|
|
|
assert_equal(ticket1.organization.id, @organization1.id)
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 1.second
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2016-09-02 10:54:13 +00:00
|
|
|
ticket2 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'some title2',
|
|
|
|
group: @group,
|
|
|
|
customer_id: @customer2.id,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
2021-07-16 13:44:10 +00:00
|
|
|
# updated_at: '2015-02-05 17:37:00',
|
2016-02-26 12:19:57 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
assert(ticket2, 'ticket created')
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket2.customer.id, @customer2.id)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket2.organization_id)
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 1.second
|
2016-02-26 12:19:57 +00:00
|
|
|
|
2016-09-02 10:54:13 +00:00
|
|
|
ticket3 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'some title3',
|
|
|
|
group: @group,
|
|
|
|
customer_id: @customer2.id,
|
|
|
|
state: Ticket::State.lookup(name: 'open'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
2021-07-16 13:44:10 +00:00
|
|
|
# updated_at: '2015-02-05 17:37:00',
|
2015-10-12 13:44:34 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2016-09-14 07:15:30 +00:00
|
|
|
ticket3.update_columns(escalation_at: '2015-02-06 10:00:00')
|
2016-02-26 12:19:57 +00:00
|
|
|
assert(ticket3, 'ticket created')
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(ticket3.customer.id, @customer2.id)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket3.organization_id)
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 1.second
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
# search not matching
|
|
|
|
condition = {
|
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: [99],
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2016-03-18 02:04:49 +00:00
|
|
|
# search matching with empty value / missing key
|
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2016-03-18 02:04:49 +00:00
|
|
|
},
|
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
|
|
|
# search matching with empty value []
|
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2016-03-18 02:04:49 +00:00
|
|
|
},
|
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: [],
|
2016-03-18 02:04:49 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
|
|
|
# search matching with empty value ''
|
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2016-03-18 02:04:49 +00:00
|
|
|
},
|
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-03-18 02:04:49 +00:00
|
|
|
|
2015-10-12 13:44:34 +00:00
|
|
|
# search matching
|
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: [Ticket::State.lookup(name: 'new').id],
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is not',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: [Ticket::State.lookup(name: 'open').id],
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
|
|
|
|
|
|
|
condition = {
|
2016-09-14 07:15:30 +00:00
|
|
|
'ticket.escalation_at' => {
|
2016-02-26 12:19:57 +00:00
|
|
|
operator: 'is not',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: nil,
|
2016-02-26 12:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
# search - created_at
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.created_at' => {
|
|
|
|
operator: 'after (absolute)', # before (absolute)
|
2018-12-19 17:31:51 +00:00
|
|
|
value: '2015-02-05T16:00:00.000Z',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 3)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.created_at' => {
|
|
|
|
operator: 'after (absolute)', # before (absolute)
|
2018-12-19 17:31:51 +00:00
|
|
|
value: '2015-02-05T18:00:00.000Z',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.created_at' => {
|
|
|
|
operator: 'before (absolute)',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: '2015-02-05T18:00:00.000Z',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 3)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.created_at' => {
|
|
|
|
operator: 'before (absolute)',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: '2015-02-05T16:00:00.000Z',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.created_at' => {
|
|
|
|
operator: 'before (relative)',
|
2018-12-19 17:31:51 +00:00
|
|
|
range: 'day', # minute|hour|day|month|
|
|
|
|
value: '10',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 3)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2021-04-29 15:34:27 +00:00
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
|
|
|
value: @group.id,
|
|
|
|
},
|
|
|
|
'ticket.created_at' => {
|
|
|
|
operator: 'till (relative)',
|
|
|
|
range: 'year', # minute|hour|day|month|
|
|
|
|
value: '10',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
|
|
|
assert_equal(ticket_count, 3)
|
|
|
|
|
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
|
|
|
assert_equal(ticket_count, 0)
|
|
|
|
|
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
|
|
|
assert_equal(ticket_count, 1)
|
|
|
|
|
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
|
|
|
assert_equal(ticket_count, 2)
|
|
|
|
|
2015-10-12 13:44:34 +00:00
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.created_at' => {
|
|
|
|
operator: 'within last (relative)',
|
2018-12-19 17:31:51 +00:00
|
|
|
range: 'year', # minute|hour|day|month|
|
|
|
|
value: '10',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 3)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
# search - updated_at
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.updated_at' => {
|
|
|
|
operator: 'before (absolute)',
|
2022-01-03 09:47:32 +00:00
|
|
|
value: 1.day.from_now.iso8601,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 3)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.updated_at' => {
|
|
|
|
operator: 'before (absolute)',
|
2022-01-03 09:47:32 +00:00
|
|
|
value: 1.day.ago.iso8601,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.updated_at' => {
|
|
|
|
operator: 'after (absolute)',
|
2022-01-03 09:47:32 +00:00
|
|
|
value: 1.day.from_now.iso8601,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.updated_at' => {
|
|
|
|
operator: 'after (absolute)',
|
2022-01-03 09:47:32 +00:00
|
|
|
value: 1.day.ago.iso8601,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 3)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.updated_at' => {
|
|
|
|
operator: 'before (relative)',
|
2018-12-19 17:31:51 +00:00
|
|
|
range: 'day', # minute|hour|day|month|
|
|
|
|
value: '10',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2021-04-29 15:34:27 +00:00
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
|
|
|
value: @group.id,
|
|
|
|
},
|
|
|
|
'ticket.updated_at' => {
|
|
|
|
operator: 'till (relative)',
|
|
|
|
range: 'year', # minute|hour|day|month|
|
|
|
|
value: '10',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
|
|
|
assert_equal(ticket_count, 3)
|
|
|
|
|
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
|
|
|
assert_equal(ticket_count, 0)
|
|
|
|
|
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
|
|
|
assert_equal(ticket_count, 1)
|
|
|
|
|
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
|
|
|
assert_equal(ticket_count, 2)
|
|
|
|
|
2015-10-12 13:44:34 +00:00
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'ticket.updated_at' => {
|
|
|
|
operator: 'within last (relative)',
|
2018-12-19 17:31:51 +00:00
|
|
|
range: 'year', # minute|hour|day|month|
|
|
|
|
value: '10',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 3)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
# invalid conditions
|
|
|
|
assert_raise RuntimeError do
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(nil, limit: 10)
|
2015-10-12 13:44:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# search with customers
|
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
'customer.email' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'contains',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'ticket-selector-customer1',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
'customer.email' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'contains not',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'ticket-selector-customer1-not_existing',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 3)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
# search with organizations
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'organization.name' => {
|
|
|
|
operator: 'contains',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'selector',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
# search with organizations
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'organization.name' => {
|
|
|
|
operator: 'contains',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'selector',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
'customer.email' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'contains',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'ticket-selector-customer1',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
'organization.name' => {
|
|
|
|
operator: 'contains',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'selector',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
'customer.email' => {
|
2015-10-12 13:44:34 +00:00
|
|
|
operator: 'contains not',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'ticket-selector-customer1',
|
2015-10-12 13:44:34 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-12 13:44:34 +00:00
|
|
|
|
2015-10-14 14:33:26 +00:00
|
|
|
# with owner/customer/org
|
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
'ticket.owner_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is',
|
2015-10-14 14:33:26 +00:00
|
|
|
pre_condition: 'specific',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @agent1.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2016-11-10 15:30:36 +00:00
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2016-11-10 15:30:36 +00:00
|
|
|
},
|
|
|
|
'ticket.owner_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is',
|
2016-11-10 15:30:36 +00:00
|
|
|
pre_condition: 'specific',
|
2021-07-16 13:44:10 +00:00
|
|
|
# value: @agent1.id, # value is not set, no result should be shown
|
2016-11-10 15:30:36 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-11-10 15:30:36 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-11-10 15:30:36 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-11-10 15:30:36 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(ticket_count)
|
2016-11-10 15:30:36 +00:00
|
|
|
|
2015-10-14 14:33:26 +00:00
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
'ticket.owner_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is',
|
2016-04-14 08:08:08 +00:00
|
|
|
pre_condition: 'not_set',
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-04-14 09:39:54 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-04-14 09:39:54 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-04-14 09:39:54 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
'ticket.owner_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is not',
|
2016-04-14 08:08:08 +00:00
|
|
|
pre_condition: 'not_set',
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-04-14 09:39:54 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-04-14 09:39:54 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-04-14 09:39:54 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
UserInfo.current_user_id = @agent1.id
|
2015-10-14 14:33:26 +00:00
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
'ticket.owner_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is',
|
2015-10-14 14:33:26 +00:00
|
|
|
pre_condition: 'current_user.id',
|
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
UserInfo.current_user_id = @agent2.id
|
2015-10-14 14:33:26 +00:00
|
|
|
condition = {
|
|
|
|
'ticket.group_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
'ticket.owner_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is',
|
2015-10-14 14:33:26 +00:00
|
|
|
pre_condition: 'current_user.id',
|
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
UserInfo.current_user_id = @customer1.id
|
2015-10-14 14:33:26 +00:00
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-14 14:33:26 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
'ticket.customer_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is',
|
2015-10-14 14:33:26 +00:00
|
|
|
pre_condition: 'current_user.id',
|
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
UserInfo.current_user_id = @customer2.id
|
2015-10-14 14:33:26 +00:00
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-14 14:33:26 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
'ticket.customer_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is',
|
2015-10-14 14:33:26 +00:00
|
|
|
pre_condition: 'current_user.id',
|
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 2)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
UserInfo.current_user_id = @customer1.id
|
2015-10-14 14:33:26 +00:00
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-14 14:33:26 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
'ticket.organization_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is',
|
2015-10-14 14:33:26 +00:00
|
|
|
pre_condition: 'current_user.organization_id',
|
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
UserInfo.current_user_id = @customer2.id
|
2015-10-14 14:33:26 +00:00
|
|
|
condition = {
|
2018-12-19 17:31:51 +00:00
|
|
|
'ticket.group_id' => {
|
2015-10-14 14:33:26 +00:00
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: @group.id,
|
2015-10-14 14:33:26 +00:00
|
|
|
},
|
|
|
|
'ticket.organization_id' => {
|
2018-12-19 17:31:51 +00:00
|
|
|
operator: 'is',
|
2015-10-14 14:33:26 +00:00
|
|
|
pre_condition: 'current_user.organization_id',
|
|
|
|
},
|
|
|
|
}
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer1)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 1)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10, current_user: @customer2)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2015-10-14 14:33:26 +00:00
|
|
|
|
2019-03-26 00:17:17 +00:00
|
|
|
ticket_count, tickets = Ticket.selectors(condition, limit: 10)
|
2016-02-26 12:19:57 +00:00
|
|
|
assert_equal(ticket_count, 0)
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2015-10-12 13:44:34 +00:00
|
|
|
end
|
|
|
|
|
2017-04-12 13:41:54 +00:00
|
|
|
test 'ticket tags filter' do
|
|
|
|
ticket_tags_1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
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'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
2017-04-12 13:41:54 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
ticket_tags_2 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
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'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
2017-04-12 13:41:54 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2019-06-28 11:38:49 +00:00
|
|
|
Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
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'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
2017-04-12 13:41:54 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
Tag.tag_add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
o_id: ticket_tags_1.id,
|
|
|
|
item: 'contains_all_1',
|
2017-04-12 13:41:54 +00:00
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
Tag.tag_add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
o_id: ticket_tags_1.id,
|
|
|
|
item: 'contains_all_2',
|
2017-04-12 13:41:54 +00:00
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
Tag.tag_add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
o_id: ticket_tags_1.id,
|
|
|
|
item: 'contains_all_3',
|
2017-04-12 13:41:54 +00:00
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
Tag.tag_add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket',
|
|
|
|
o_id: ticket_tags_2.id,
|
|
|
|
item: 'contains_all_3',
|
2017-04-12 13:41:54 +00:00
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
# search all with contains all
|
|
|
|
condition = {
|
|
|
|
'ticket.tags' => {
|
|
|
|
operator: 'contains all',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'contains_all_1, contains_all_2, contains_all_3',
|
2017-04-12 13:41:54 +00:00
|
|
|
},
|
|
|
|
}
|
2019-06-28 11:38:49 +00:00
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-04-12 13:41:54 +00:00
|
|
|
assert_equal(1, ticket_count)
|
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.tags' => {
|
|
|
|
operator: 'contains all',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'contains_all_1, contains_all_2, contains_all_3, xxx',
|
2017-04-12 13:41:54 +00:00
|
|
|
},
|
|
|
|
}
|
2019-06-28 11:38:49 +00:00
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-04-12 13:41:54 +00:00
|
|
|
assert_equal(0, ticket_count)
|
|
|
|
|
|
|
|
# search all with contains one
|
|
|
|
condition = {
|
|
|
|
'ticket.tags' => {
|
|
|
|
operator: 'contains one',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'contains_all_1, contains_all_2, contains_all_3',
|
2017-04-12 13:41:54 +00:00
|
|
|
},
|
|
|
|
}
|
2019-06-28 11:38:49 +00:00
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-04-12 13:41:54 +00:00
|
|
|
assert_equal(2, ticket_count)
|
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.tags' => {
|
|
|
|
operator: 'contains one',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'contains_all_1, contains_all_2'
|
2017-04-12 13:41:54 +00:00
|
|
|
},
|
|
|
|
}
|
2019-06-28 11:38:49 +00:00
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-04-12 13:41:54 +00:00
|
|
|
assert_equal(1, ticket_count)
|
|
|
|
|
|
|
|
# search all with contains one not
|
|
|
|
condition = {
|
|
|
|
'ticket.tags' => {
|
|
|
|
operator: 'contains one',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'contains_all_1, contains_all_3'
|
2017-04-12 13:41:54 +00:00
|
|
|
},
|
|
|
|
}
|
2019-06-28 11:38:49 +00:00
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-04-12 13:41:54 +00:00
|
|
|
assert_equal(2, ticket_count)
|
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.tags' => {
|
|
|
|
operator: 'contains one',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: 'contains_all_1, contains_all_2, contains_all_3'
|
2017-04-12 13:41:54 +00:00
|
|
|
},
|
|
|
|
}
|
2019-06-28 11:38:49 +00:00
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
2017-04-12 13:41:54 +00:00
|
|
|
assert_equal(2, ticket_count)
|
|
|
|
end
|
|
|
|
|
2019-10-30 07:45:31 +00:00
|
|
|
test 'ticket title with certain content' do
|
|
|
|
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'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
Ticket.create!(
|
|
|
|
title: 'some::title2',
|
|
|
|
group: @group,
|
|
|
|
customer_id: @customer1.id,
|
|
|
|
owner_id: @agent1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
Ticket.create!(
|
|
|
|
title: 'some-title3',
|
|
|
|
group: @group,
|
|
|
|
customer_id: @customer1.id,
|
|
|
|
owner_id: @agent1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
# search all with contains
|
|
|
|
condition = {
|
|
|
|
'ticket.title' => {
|
|
|
|
operator: 'contains',
|
|
|
|
value: 'some_title1',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
|
|
|
assert_equal(1, ticket_count)
|
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.title' => {
|
|
|
|
operator: 'contains',
|
|
|
|
value: 'some::title2',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
|
|
|
assert_equal(1, ticket_count)
|
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.title' => {
|
|
|
|
operator: 'contains',
|
|
|
|
value: 'some-title3',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
|
|
|
assert_equal(1, ticket_count)
|
|
|
|
|
|
|
|
# search all with is
|
|
|
|
condition = {
|
|
|
|
'ticket.title' => {
|
|
|
|
operator: 'is',
|
|
|
|
value: 'some_title1',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
|
|
|
assert_equal(1, ticket_count)
|
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.title' => {
|
|
|
|
operator: 'is',
|
|
|
|
value: 'some::title2',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
|
|
|
assert_equal(1, ticket_count)
|
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.title' => {
|
|
|
|
operator: 'is',
|
|
|
|
value: 'some-title3',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
|
|
|
assert_equal(1, ticket_count)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2020-03-24 15:40:53 +00:00
|
|
|
test 'access: "ignore"' do
|
|
|
|
Ticket.destroy_all
|
|
|
|
|
|
|
|
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'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
Ticket.create!(
|
|
|
|
title: 'some title2',
|
|
|
|
group: @group,
|
|
|
|
customer_id: @customer1.id,
|
|
|
|
owner_id: @agent1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
|
|
|
created_at: '2015-02-05 16:37:00',
|
|
|
|
updated_by_id: @agent2.id,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
condition = {
|
|
|
|
'ticket.title' => {
|
|
|
|
operator: 'contains',
|
|
|
|
value: 'some',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
# visible by owner
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent1)
|
|
|
|
assert_equal(2, ticket_count)
|
|
|
|
|
|
|
|
# not visible by another agent
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2)
|
|
|
|
assert_equal(0, ticket_count)
|
|
|
|
|
|
|
|
# visible by another user when access: "ignore". For example, when tickets are performed after action of another user
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition, limit: 10, current_user: @agent2, access: 'ignore')
|
|
|
|
assert_equal(2, ticket_count)
|
|
|
|
|
|
|
|
condition2 = {
|
|
|
|
'ticket.updated_by_id' => {
|
|
|
|
operator: 'is',
|
|
|
|
pre_condition: 'current_user.id',
|
|
|
|
value: '',
|
|
|
|
value_completion: ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# not visible by another agent even if matches current user precondition
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition2, limit: 10, current_user: @agent2)
|
|
|
|
assert_equal(0, ticket_count)
|
|
|
|
|
|
|
|
# visible by another user when access: "ignore" if matches current user precondition
|
|
|
|
ticket_count, _tickets = Ticket.selectors(condition2, limit: 10, current_user: @agent2, access: 'ignore')
|
|
|
|
assert_equal(1, ticket_count)
|
|
|
|
end
|
2015-10-12 13:44:34 +00:00
|
|
|
end
|