2018-07-16 05:39:24 +00:00
|
|
|
require 'test_helper'
|
2015-02-25 23:44:29 +00:00
|
|
|
|
2015-02-26 00:12:12 +00:00
|
|
|
class ElasticsearchTest < ActiveSupport::TestCase
|
2018-06-03 15:24:35 +00:00
|
|
|
include SearchindexHelper
|
2015-02-25 23:44:29 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
setup do
|
|
|
|
|
2018-06-03 15:24:35 +00:00
|
|
|
configure_elasticsearch(required: true)
|
2017-06-14 15:25:45 +00:00
|
|
|
|
2018-06-03 15:24:35 +00:00
|
|
|
rebuild_searchindex
|
2017-06-14 15:25:45 +00:00
|
|
|
|
|
|
|
groups = Group.where(name: 'Users')
|
|
|
|
roles = Role.where(name: 'Agent')
|
2018-07-16 05:39:24 +00:00
|
|
|
@agent = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'es-agent@example.com',
|
|
|
|
firstname: 'E',
|
|
|
|
lastname: 'S',
|
|
|
|
email: 'es-agent@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2019-06-28 11:38:49 +00:00
|
|
|
Group.create_if_not_exists(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'WithoutAccess',
|
|
|
|
note: 'Test for not access check.',
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
|
|
|
)
|
|
|
|
roles = Role.where(name: 'Customer')
|
|
|
|
@organization1 = Organization.create_if_not_exists(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Customer Organization Update',
|
|
|
|
note: 'some note',
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2018-07-16 05:39:24 +00:00
|
|
|
@customer1 = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'es-customer1@example.com',
|
|
|
|
firstname: 'ES',
|
|
|
|
lastname: 'Customer1',
|
|
|
|
email: 'es-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_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2017-06-14 15:25:45 +00:00
|
|
|
)
|
2018-07-16 05:39:24 +00:00
|
|
|
@customer2 = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'es-customer2@example.com',
|
|
|
|
firstname: 'ES',
|
|
|
|
lastname: 'Customer2',
|
|
|
|
email: 'es-customer2@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_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2017-06-14 15:25:45 +00:00
|
|
|
)
|
2018-07-16 05:39:24 +00:00
|
|
|
@customer3 = User.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'es-customer3@example.com',
|
|
|
|
firstname: 'ES',
|
|
|
|
lastname: 'Customer3',
|
|
|
|
email: 'es-customer3@example.com',
|
|
|
|
password: 'customerpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
2017-06-14 15:25:45 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2018-07-16 05:39:24 +00:00
|
|
|
|
|
|
|
# execute background jobs to index created/changed objects
|
|
|
|
Scheduler.worker(true)
|
|
|
|
|
2016-01-26 15:43:36 +00:00
|
|
|
end
|
2015-02-25 23:44:29 +00:00
|
|
|
|
2016-07-06 06:13:44 +00:00
|
|
|
# check search attributes
|
|
|
|
test 'a - objects' do
|
|
|
|
|
|
|
|
# user
|
2017-06-14 15:25:45 +00:00
|
|
|
attributes = @agent.search_index_data
|
2016-07-06 06:13:44 +00:00
|
|
|
assert_equal('E', attributes['firstname'])
|
|
|
|
assert_equal('S', attributes['lastname'])
|
|
|
|
assert_equal('es-agent@example.com', attributes['email'])
|
2017-12-14 20:05:59 +00:00
|
|
|
assert(attributes['preferences'])
|
2016-07-06 06:13:44 +00:00
|
|
|
assert_not(attributes['password'])
|
|
|
|
assert_not(attributes['organization'])
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
attributes = @agent.search_index_attribute_lookup
|
2016-07-06 06:13:44 +00:00
|
|
|
assert_equal('E', attributes['firstname'])
|
|
|
|
assert_equal('S', attributes['lastname'])
|
|
|
|
assert_equal('es-agent@example.com', attributes['email'])
|
2017-12-14 20:05:59 +00:00
|
|
|
assert(attributes['preferences'])
|
2016-07-06 06:13:44 +00:00
|
|
|
assert_not(attributes['password'])
|
|
|
|
assert_not(attributes['organization'])
|
|
|
|
|
2017-09-11 00:50:05 +00:00
|
|
|
attributes = @customer1.search_index_attribute_lookup
|
|
|
|
assert_equal('ES', attributes['firstname'])
|
|
|
|
assert_equal('Customer1', attributes['lastname'])
|
|
|
|
assert_equal('es-customer1@example.com', attributes['email'])
|
2017-12-14 20:05:59 +00:00
|
|
|
assert(attributes['preferences'])
|
2017-09-11 00:50:05 +00:00
|
|
|
assert_not(attributes['password'])
|
|
|
|
assert_equal('Customer Organization Update', attributes['organization'])
|
|
|
|
|
2016-07-06 06:13:44 +00:00
|
|
|
# organization
|
2017-06-14 15:25:45 +00:00
|
|
|
attributes = @organization1.search_index_data
|
2016-07-06 06:13:44 +00:00
|
|
|
assert_equal('Customer Organization Update', attributes['name'])
|
|
|
|
assert_equal('some note', attributes['note'])
|
|
|
|
assert_not(attributes['members'])
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
attributes = @organization1.search_index_attribute_lookup
|
2016-07-06 06:13:44 +00:00
|
|
|
assert_equal('Customer Organization Update', attributes['name'])
|
|
|
|
assert_equal('some note', attributes['note'])
|
|
|
|
assert(attributes['members'])
|
|
|
|
|
|
|
|
# ticket/article
|
2017-06-14 15:25:45 +00:00
|
|
|
ticket1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'some title äöüß',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: @customer1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2016-07-06 06:13:44 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
article1 = Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
2016-07-06 06:13:44 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: File.binread(Rails.root.join('test', 'data', 'elasticsearch', 'es-normal.txt')),
|
|
|
|
filename: 'es-normal.txt',
|
|
|
|
preferences: {},
|
2017-06-14 15:25:45 +00:00
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2016-07-06 06:13:44 +00:00
|
|
|
|
|
|
|
attributes = ticket1.search_index_attribute_lookup
|
|
|
|
assert_equal('Users', attributes['group'])
|
|
|
|
assert_equal('new', attributes['state'])
|
|
|
|
assert_equal('2 normal', attributes['priority'])
|
|
|
|
|
|
|
|
assert_equal('ES', attributes['customer']['firstname'])
|
|
|
|
assert_equal('Customer1', attributes['customer']['lastname'])
|
|
|
|
assert_equal('es-customer1@example.com', attributes['customer']['email'])
|
|
|
|
assert_not(attributes['customer']['password'])
|
|
|
|
assert_equal('Customer Organization Update', attributes['customer']['organization'])
|
|
|
|
|
|
|
|
assert_equal('-', attributes['owner']['login'])
|
|
|
|
assert_equal('-', attributes['owner']['firstname'])
|
|
|
|
assert_not(attributes['owner']['password'])
|
|
|
|
assert_not(attributes['owner']['organization'])
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
assert(attributes['article'][0]['attachment'])
|
|
|
|
assert(attributes['article'][0]['attachment'][0])
|
|
|
|
assert_not(attributes['article'][0]['attachment'][1])
|
|
|
|
assert_equal('es-normal.txt', attributes['article'][0]['attachment'][0]['_name'])
|
2017-12-04 00:24:58 +00:00
|
|
|
assert_equal('c29tZSBub3JtYWwgdGV4dDY2Cg==', attributes['article'][0]['attachment'][0]['_content'])
|
2017-06-14 15:25:45 +00:00
|
|
|
|
2017-12-04 00:24:58 +00:00
|
|
|
ticket1.destroy!
|
2016-07-06 06:13:44 +00:00
|
|
|
|
|
|
|
# execute background jobs
|
|
|
|
Scheduler.worker(true)
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
ticket1 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: "some title\n äöüß",
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: @customer1.id,
|
|
|
|
state: Ticket::State.lookup(name: 'new'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-02-25 23:44:29 +00:00
|
|
|
)
|
2017-06-14 15:25:45 +00:00
|
|
|
article1 = Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket1.id,
|
|
|
|
from: 'some_sender@example.com',
|
|
|
|
to: 'some_recipient@example.com',
|
|
|
|
subject: 'some subject',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some message',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-02-25 23:44:29 +00:00
|
|
|
)
|
2015-04-06 19:00:16 +00:00
|
|
|
|
|
|
|
# add attachments which should get index / .txt
|
2017-06-14 15:25:45 +00:00
|
|
|
# "some normal text66"
|
2015-04-06 19:00:16 +00:00
|
|
|
Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: File.binread(Rails.root.join('test', 'data', 'elasticsearch', 'es-normal.txt')),
|
|
|
|
filename: 'es-normal.txt',
|
|
|
|
preferences: {},
|
2015-04-27 13:42:53 +00:00
|
|
|
created_by_id: 1,
|
2015-04-06 19:00:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# add attachments which should get index / .pdf
|
2015-04-06 23:33:22 +00:00
|
|
|
# "Zammad Test77"
|
2015-04-06 19:00:16 +00:00
|
|
|
Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: File.binread(Rails.root.join('test', 'data', 'elasticsearch', 'es-pdf1.pdf')),
|
|
|
|
filename: 'es-pdf1.pdf',
|
|
|
|
preferences: {},
|
2015-04-27 13:42:53 +00:00
|
|
|
created_by_id: 1,
|
2015-04-06 19:00:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# add attachments which should get index / .box
|
2015-04-06 23:56:53 +00:00
|
|
|
# "Old programmers never die test99"
|
2015-04-06 19:00:16 +00:00
|
|
|
Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: File.binread(Rails.root.join('test', 'data', 'elasticsearch', 'es-box1.box')),
|
|
|
|
filename: 'mail1.box',
|
|
|
|
preferences: {},
|
2015-04-27 13:42:53 +00:00
|
|
|
created_by_id: 1,
|
2015-04-06 19:00:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# add to big attachment which should not get index
|
2015-04-06 23:56:53 +00:00
|
|
|
# "some too big text88"
|
2015-04-06 19:00:16 +00:00
|
|
|
Store.add(
|
2018-12-19 17:31:51 +00:00
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article1.id,
|
|
|
|
data: File.binread(Rails.root.join('test', 'data', 'elasticsearch', 'es-too-big.txt')),
|
|
|
|
filename: 'es-too-big.txt',
|
|
|
|
preferences: {},
|
2015-04-27 13:42:53 +00:00
|
|
|
created_by_id: 1,
|
2015-04-06 19:00:16 +00:00
|
|
|
)
|
2017-04-12 07:34:49 +00:00
|
|
|
ticket1.tag_add('someTagA', 1)
|
2018-07-16 05:39:24 +00:00
|
|
|
travel 1.minute
|
2015-02-25 23:44:29 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
ticket2 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'something else',
|
|
|
|
group: Group.lookup(name: 'Users'),
|
|
|
|
customer_id: @customer2.id,
|
|
|
|
state: Ticket::State.lookup(name: 'open'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-02-25 23:44:29 +00:00
|
|
|
)
|
2019-06-28 11:38:49 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket2.id,
|
|
|
|
from: 'some_sender@example.org',
|
|
|
|
to: 'some_recipient@example.org',
|
|
|
|
subject: 'some subject2 / autobahn what else?',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some other message <b>with s<u>t</u>rong text<b>',
|
|
|
|
content_type: 'text/html',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-02-25 23:44:29 +00:00
|
|
|
)
|
2017-04-12 07:34:49 +00:00
|
|
|
ticket2.tag_add('someTagB', 1)
|
2018-07-16 05:39:24 +00:00
|
|
|
travel 1.minute
|
2015-02-25 23:44:29 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
ticket3 = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: 'something else',
|
|
|
|
group: Group.lookup(name: 'WithoutAccess'),
|
|
|
|
customer_id: @customer3.id,
|
|
|
|
state: Ticket::State.lookup(name: 'open'),
|
|
|
|
priority: Ticket::Priority.lookup(name: '2 normal'),
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-02-25 23:44:29 +00:00
|
|
|
)
|
2019-06-28 11:38:49 +00:00
|
|
|
Ticket::Article.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
ticket_id: ticket3.id,
|
|
|
|
from: 'some_sender@example.org',
|
|
|
|
to: 'some_recipient@example.org',
|
|
|
|
subject: 'some subject3',
|
|
|
|
message_id: 'some@id',
|
|
|
|
body: 'some other message 3 / kindergarden what else?',
|
|
|
|
internal: false,
|
|
|
|
sender: Ticket::Article::Sender.where(name: 'Customer').first,
|
|
|
|
type: Ticket::Article::Type.where(name: 'email').first,
|
2015-04-27 13:42:53 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-02-25 23:44:29 +00:00
|
|
|
)
|
2015-04-06 06:13:05 +00:00
|
|
|
|
|
|
|
# execute background jobs
|
2016-04-26 09:30:46 +00:00
|
|
|
Scheduler.worker(true)
|
2018-07-16 05:39:24 +00:00
|
|
|
sleep 2 # for ES to come ready/indexed
|
2015-04-05 23:05:33 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
# search as @agent
|
2015-02-25 23:44:29 +00:00
|
|
|
|
2015-04-05 23:05:33 +00:00
|
|
|
# search for article data
|
2015-02-25 23:44:29 +00:00
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'autobahn',
|
|
|
|
limit: 15,
|
2015-02-25 23:44:29 +00:00
|
|
|
)
|
2015-02-26 00:12:12 +00:00
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result.present?, 'result exists not')
|
2015-02-26 00:12:12 +00:00
|
|
|
assert(result[0], 'record 1')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2015-02-26 00:12:12 +00:00
|
|
|
assert_equal(result[0].id, ticket2.id)
|
|
|
|
|
2015-04-05 23:05:33 +00:00
|
|
|
# search for html content
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'strong',
|
|
|
|
limit: 15,
|
2015-04-05 23:05:33 +00:00
|
|
|
)
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result.present?, 'result exists not')
|
2015-04-05 23:05:33 +00:00
|
|
|
assert(result[0], 'record 1')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2015-04-05 23:05:33 +00:00
|
|
|
assert_equal(result[0].id, ticket2.id)
|
2015-02-26 00:12:12 +00:00
|
|
|
|
2015-04-05 23:05:33 +00:00
|
|
|
# search for indexed attachment
|
2015-04-06 19:00:16 +00:00
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: '"some normal text66"',
|
|
|
|
limit: 15,
|
2015-04-06 19:00:16 +00:00
|
|
|
)
|
|
|
|
assert(result[0], 'record 1')
|
|
|
|
assert_equal(result[0].id, ticket1.id)
|
|
|
|
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'test77',
|
|
|
|
limit: 15,
|
2015-04-06 19:00:16 +00:00
|
|
|
)
|
|
|
|
assert(result[0], 'record 1')
|
|
|
|
assert_equal(result[0].id, ticket1.id)
|
|
|
|
|
2015-04-05 23:05:33 +00:00
|
|
|
# search for not indexed attachment
|
2015-04-06 19:00:16 +00:00
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'test88',
|
|
|
|
limit: 15,
|
2015-04-06 19:00:16 +00:00
|
|
|
)
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[0], 'record 1')
|
2015-04-05 23:05:33 +00:00
|
|
|
|
2015-04-06 19:00:16 +00:00
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'test99',
|
|
|
|
limit: 15,
|
2015-04-06 19:00:16 +00:00
|
|
|
)
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[0], 'record 1')
|
2015-04-05 23:05:33 +00:00
|
|
|
|
|
|
|
# search for ticket with no permissions
|
2015-02-26 00:12:12 +00:00
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'kindergarden',
|
|
|
|
limit: 15,
|
2015-02-26 00:12:12 +00:00
|
|
|
)
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result.blank?, 'result should be empty')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[0], 'record 1')
|
2015-02-26 00:12:12 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
# search as @customer1
|
2015-04-05 23:05:33 +00:00
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @customer1,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'title OR else',
|
|
|
|
limit: 15,
|
2015-04-05 23:05:33 +00:00
|
|
|
)
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result.present?, 'result exists not')
|
2015-04-05 23:05:33 +00:00
|
|
|
assert(result[0], 'record 1')
|
|
|
|
assert(result[1], 'record 2')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[2], 'record 3')
|
2015-04-05 23:05:33 +00:00
|
|
|
assert_equal(result[0].id, ticket2.id)
|
|
|
|
assert_equal(result[1].id, ticket1.id)
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
# search as @customer2
|
2015-04-05 23:05:33 +00:00
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @customer2,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'title OR else',
|
|
|
|
limit: 15,
|
2015-04-05 23:05:33 +00:00
|
|
|
)
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result.present?, 'result exists not')
|
2015-04-05 23:05:33 +00:00
|
|
|
assert(result[0], 'record 1')
|
|
|
|
assert(result[1], 'record 2')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[2], 'record 3')
|
2015-04-05 23:05:33 +00:00
|
|
|
assert_equal(result[0].id, ticket2.id)
|
|
|
|
assert_equal(result[1].id, ticket1.id)
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
# search as @customer3
|
2015-04-05 23:05:33 +00:00
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @customer3,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'title OR else',
|
|
|
|
limit: 15,
|
2015-04-05 23:05:33 +00:00
|
|
|
)
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result.present?, 'result exists not')
|
2015-04-05 23:05:33 +00:00
|
|
|
assert(result[0], 'record 1')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2015-04-05 23:05:33 +00:00
|
|
|
assert_equal(result[0].id, ticket3.id)
|
2016-06-14 11:27:15 +00:00
|
|
|
|
|
|
|
# search for tags
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'tags:someTagA',
|
|
|
|
limit: 15,
|
2016-06-14 11:27:15 +00:00
|
|
|
)
|
|
|
|
assert(result[0], 'record 1')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 1')
|
2016-06-14 11:27:15 +00:00
|
|
|
assert_equal(result[0].id, ticket1.id)
|
|
|
|
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'tags:someTagB',
|
|
|
|
limit: 15,
|
2016-06-14 11:27:15 +00:00
|
|
|
)
|
|
|
|
assert(result[0], 'record 2')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2016-06-14 11:27:15 +00:00
|
|
|
assert_equal(result[0].id, ticket2.id)
|
|
|
|
|
|
|
|
# rename tag (e. g. via admin interface)
|
|
|
|
tag_item = Tag::Item.lookup(name: 'someTagA')
|
|
|
|
Tag::Item.rename(
|
2018-12-19 17:31:51 +00:00
|
|
|
id: tag_item.id,
|
|
|
|
name: 'someTagC',
|
2016-06-14 11:27:15 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
# execute background jobs
|
|
|
|
Scheduler.worker(true)
|
2018-07-16 05:39:24 +00:00
|
|
|
sleep 2 # for ES to come ready/indexed
|
2016-06-14 11:27:15 +00:00
|
|
|
|
|
|
|
# search for tags
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'tags:someTagA',
|
|
|
|
limit: 15,
|
2016-06-14 11:27:15 +00:00
|
|
|
)
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[0], 'record 1')
|
|
|
|
assert_not(result[1], 'record 1')
|
2016-06-14 11:27:15 +00:00
|
|
|
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'tags:someTagB',
|
|
|
|
limit: 15,
|
2016-06-14 11:27:15 +00:00
|
|
|
)
|
|
|
|
assert(result[0], 'record 2')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2016-06-14 11:27:15 +00:00
|
|
|
assert_equal(result[0].id, ticket2.id)
|
|
|
|
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'tags:someTagC',
|
|
|
|
limit: 15,
|
2016-06-14 11:27:15 +00:00
|
|
|
)
|
|
|
|
assert(result[0], 'record 1')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2016-09-09 21:10:27 +00:00
|
|
|
assert_equal(result[0].id, ticket1.id)
|
|
|
|
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'state:open',
|
|
|
|
limit: 15,
|
2016-09-09 21:10:27 +00:00
|
|
|
)
|
|
|
|
assert(result[0], 'record 1')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2016-09-09 21:10:27 +00:00
|
|
|
assert_equal(result[0].id, ticket2.id)
|
|
|
|
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: '"some_sender@example.com"',
|
|
|
|
limit: 15,
|
2016-09-09 21:10:27 +00:00
|
|
|
)
|
|
|
|
assert(result[0], 'record 1')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2016-09-09 21:10:27 +00:00
|
|
|
assert_equal(result[0].id, ticket1.id)
|
|
|
|
|
|
|
|
result = Ticket.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'article.from:"some_sender@example.com"',
|
|
|
|
limit: 15,
|
2016-09-09 21:10:27 +00:00
|
|
|
)
|
|
|
|
assert(result[0], 'record 1')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2016-06-14 11:27:15 +00:00
|
|
|
assert_equal(result[0].id, ticket1.id)
|
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
# check users and search it
|
|
|
|
# search as @agent
|
2015-04-05 23:05:33 +00:00
|
|
|
result = User.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @agent,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'customer1',
|
|
|
|
limit: 15,
|
2015-04-05 23:05:33 +00:00
|
|
|
)
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result.present?, 'result should not be empty')
|
2015-04-05 23:05:33 +00:00
|
|
|
assert(result[0], 'record 1')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[1], 'record 2')
|
2017-06-14 15:25:45 +00:00
|
|
|
assert_equal(result[0].id, @customer1.id)
|
2015-04-05 23:05:33 +00:00
|
|
|
|
2017-06-14 15:25:45 +00:00
|
|
|
# search as @customer1
|
2015-04-05 23:05:33 +00:00
|
|
|
result = User.search(
|
2017-06-14 15:25:45 +00:00
|
|
|
current_user: @customer1,
|
2018-12-19 17:31:51 +00:00
|
|
|
query: 'customer1',
|
|
|
|
limit: 15,
|
2015-04-05 23:05:33 +00:00
|
|
|
)
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result.blank?, 'result should be empty')
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result[0], 'record 1')
|
2015-04-05 23:05:33 +00:00
|
|
|
|
2016-01-26 15:48:31 +00:00
|
|
|
# cleanup
|
2017-06-14 15:25:45 +00:00
|
|
|
Rake::Task['searchindex:drop'].execute
|
2016-01-26 15:36:40 +00:00
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|