|
@@ -3,92 +3,98 @@ require 'integration_test_helper'
|
|
|
|
|
|
class ElasticsearchTest < ActiveSupport::TestCase
|
|
|
|
|
|
- # set config
|
|
|
- if !ENV['ES_URL']
|
|
|
- fail "ERROR: Need ES_URL - hint ES_URL='http://172.0.0.1:9200'"
|
|
|
- end
|
|
|
- Setting.set('es_url', ENV['ES_URL'])
|
|
|
- if !ENV['ES_INDEX']
|
|
|
- fail "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
|
|
+ setup do
|
|
|
+
|
|
|
+ # set config
|
|
|
+ if !ENV['ES_URL']
|
|
|
+ fail "ERROR: Need ES_URL - hint ES_URL='http://172.0.0.1:9200'"
|
|
|
+ end
|
|
|
+ Setting.set('es_url', ENV['ES_URL'])
|
|
|
+ if !ENV['ES_INDEX'] && !ENV['ES_INDEX_RAND']
|
|
|
+ fail "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
|
|
+ end
|
|
|
+ if ENV['ES_INDEX_RAND']
|
|
|
+ ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
|
|
+ end
|
|
|
+ Setting.set('es_index', ENV['ES_INDEX'])
|
|
|
+
|
|
|
+ # Setting.set('es_url', 'http://172.0.0.1:9200')
|
|
|
+ # Setting.set('es_index', 'estest.local_zammad')
|
|
|
+ # Setting.set('es_user', 'elasticsearch')
|
|
|
+ # Setting.set('es_password', 'zammad')
|
|
|
+
|
|
|
+ # set max attachment size in mb
|
|
|
+ Setting.set('es_attachment_max_size_in_mb', 1 )
|
|
|
+
|
|
|
+ # drop/create indexes
|
|
|
+ #Rake::Task["searchindex:drop"].execute
|
|
|
+ #Rake::Task["searchindex:create"].execute
|
|
|
+ system('rake searchindex:rebuild')
|
|
|
+
|
|
|
+ groups = Group.where( name: 'Users' )
|
|
|
+ roles = Role.where( name: 'Agent' )
|
|
|
+ agent = User.create_or_update(
|
|
|
+ login: 'es-agent@example.com',
|
|
|
+ firstname: 'E',
|
|
|
+ lastname: 'S',
|
|
|
+ email: 'es-agent@example.com',
|
|
|
+ password: 'agentpw',
|
|
|
+ active: true,
|
|
|
+ roles: roles,
|
|
|
+ groups: groups,
|
|
|
+ updated_by_id: 1,
|
|
|
+ created_by_id: 1,
|
|
|
+ )
|
|
|
+ group_without_access = Group.create_if_not_exists(
|
|
|
+ name: 'WithoutAccess',
|
|
|
+ note: 'Test for not access check.',
|
|
|
+ updated_by_id: 1,
|
|
|
+ created_by_id: 1
|
|
|
+ )
|
|
|
+ roles = Role.where( name: 'Customer' )
|
|
|
+ organization1 = Organization.create_if_not_exists(
|
|
|
+ name: 'Customer Organization Update',
|
|
|
+ updated_by_id: 1,
|
|
|
+ created_by_id: 1,
|
|
|
+ )
|
|
|
+ customer1 = User.create_or_update(
|
|
|
+ login: 'es-customer1@example.com',
|
|
|
+ firstname: 'ES',
|
|
|
+ lastname: 'Customer1',
|
|
|
+ email: 'es-customer1@example.com',
|
|
|
+ password: 'customerpw',
|
|
|
+ active: true,
|
|
|
+ organization_id: organization1.id,
|
|
|
+ roles: roles,
|
|
|
+ updated_by_id: 1,
|
|
|
+ created_by_id: 1,
|
|
|
+ )
|
|
|
+ sleep 1
|
|
|
+ customer2 = User.create_or_update(
|
|
|
+ login: 'es-customer2@example.com',
|
|
|
+ firstname: 'ES',
|
|
|
+ lastname: 'Customer2',
|
|
|
+ email: 'es-customer2@example.com',
|
|
|
+ password: 'customerpw',
|
|
|
+ active: true,
|
|
|
+ organization_id: organization1.id,
|
|
|
+ roles: roles,
|
|
|
+ updated_by_id: 1,
|
|
|
+ created_by_id: 1,
|
|
|
+ )
|
|
|
+ sleep 1
|
|
|
+ customer3 = User.create_or_update(
|
|
|
+ login: 'es-customer3@example.com',
|
|
|
+ firstname: 'ES',
|
|
|
+ lastname: 'Customer3',
|
|
|
+ email: 'es-customer3@example.com',
|
|
|
+ password: 'customerpw',
|
|
|
+ active: true,
|
|
|
+ roles: roles,
|
|
|
+ updated_by_id: 1,
|
|
|
+ created_by_id: 1,
|
|
|
+ )
|
|
|
end
|
|
|
- Setting.set('es_index', ENV['ES_INDEX'])
|
|
|
-
|
|
|
- # Setting.set('es_url', 'http://172.0.0.1:9200')
|
|
|
- # Setting.set('es_index', 'estest.local_zammad')
|
|
|
- # Setting.set('es_user', 'elasticsearch')
|
|
|
- # Setting.set('es_password', 'zammad')
|
|
|
-
|
|
|
- # set max attachment size in mb
|
|
|
- Setting.set('es_attachment_max_size_in_mb', 1 )
|
|
|
-
|
|
|
- # drop/create indexes
|
|
|
- #Rake::Task["searchindex:drop"].execute
|
|
|
- #Rake::Task["searchindex:create"].execute
|
|
|
- system('rake searchindex:rebuild')
|
|
|
-
|
|
|
- groups = Group.where( name: 'Users' )
|
|
|
- roles = Role.where( name: 'Agent' )
|
|
|
- agent = User.create_or_update(
|
|
|
- login: 'es-agent@example.com',
|
|
|
- firstname: 'E',
|
|
|
- lastname: 'S',
|
|
|
- email: 'es-agent@example.com',
|
|
|
- password: 'agentpw',
|
|
|
- active: true,
|
|
|
- roles: roles,
|
|
|
- groups: groups,
|
|
|
- updated_by_id: 1,
|
|
|
- created_by_id: 1,
|
|
|
- )
|
|
|
- group_without_access = Group.create_if_not_exists(
|
|
|
- name: 'WithoutAccess',
|
|
|
- note: 'Test for not access check.',
|
|
|
- updated_by_id: 1,
|
|
|
- created_by_id: 1
|
|
|
- )
|
|
|
- roles = Role.where( name: 'Customer' )
|
|
|
- organization1 = Organization.create_if_not_exists(
|
|
|
- name: 'Customer Organization Update',
|
|
|
- updated_by_id: 1,
|
|
|
- created_by_id: 1,
|
|
|
- )
|
|
|
- customer1 = User.create_or_update(
|
|
|
- login: 'es-customer1@example.com',
|
|
|
- firstname: 'ES',
|
|
|
- lastname: 'Customer1',
|
|
|
- email: 'es-customer1@example.com',
|
|
|
- password: 'customerpw',
|
|
|
- active: true,
|
|
|
- organization_id: organization1.id,
|
|
|
- roles: roles,
|
|
|
- updated_by_id: 1,
|
|
|
- created_by_id: 1,
|
|
|
- )
|
|
|
- sleep 1
|
|
|
- customer2 = User.create_or_update(
|
|
|
- login: 'es-customer2@example.com',
|
|
|
- firstname: 'ES',
|
|
|
- lastname: 'Customer2',
|
|
|
- email: 'es-customer2@example.com',
|
|
|
- password: 'customerpw',
|
|
|
- active: true,
|
|
|
- organization_id: organization1.id,
|
|
|
- roles: roles,
|
|
|
- updated_by_id: 1,
|
|
|
- created_by_id: 1,
|
|
|
- )
|
|
|
- sleep 1
|
|
|
- customer3 = User.create_or_update(
|
|
|
- login: 'es-customer3@example.com',
|
|
|
- firstname: 'ES',
|
|
|
- lastname: 'Customer3',
|
|
|
- email: 'es-customer3@example.com',
|
|
|
- password: 'customerpw',
|
|
|
- active: true,
|
|
|
- roles: roles,
|
|
|
- updated_by_id: 1,
|
|
|
- created_by_id: 1,
|
|
|
- )
|
|
|
|
|
|
# check tickets and search it
|
|
|
test 'a - tickets' do
|
|
@@ -349,4 +355,9 @@ class ElasticsearchTest < ActiveSupport::TestCase
|
|
|
assert(!result[0], 'record 1')
|
|
|
|
|
|
end
|
|
|
+
|
|
|
+ teardown do
|
|
|
+ system('rake searchindex:drop')
|
|
|
+ end
|
|
|
+
|
|
|
end
|