diff --git a/test/integration/elasticsearch_test.rb b/test/integration/elasticsearch_test.rb index 7f974d84f..ac03714f7 100644 --- a/test/integration/elasticsearch_test.rb +++ b/test/integration/elasticsearch_test.rb @@ -8,6 +8,9 @@ class ElasticsearchTest < ActiveSupport::TestCase Setting.set('es_index', 'estest.local_zammad') #Setting.set('es_user', 'elasticsearch') #Setting.set('es_password', 'zammad') + # set max attachment size + + # set attachment types # drop/create indexes #Rake::Task["searchindex:drop"].execute @@ -34,15 +37,55 @@ class ElasticsearchTest < ActiveSupport::TestCase :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, + ) + customer2 = 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, + ) + 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 'tickets' do + test 'a - tickets' do ticket1 = Ticket.create( :title => "some title\n äöüß", :group => Group.lookup( :name => 'Users'), - :customer_id => 2, + :customer_id => customer1.id, :state => Ticket::State.lookup( :name => 'new' ), :priority => Ticket::Priority.lookup( :name => '2 normal' ), :updated_by_id => 1, @@ -66,7 +109,7 @@ class ElasticsearchTest < ActiveSupport::TestCase ticket2 = Ticket.create( :title => "something else", :group => Group.lookup( :name => 'Users'), - :customer_id => 2, + :customer_id => customer2.id, :state => Ticket::State.lookup( :name => 'open' ), :priority => Ticket::Priority.lookup( :name => '2 normal' ), :updated_by_id => 1, @@ -78,19 +121,29 @@ class ElasticsearchTest < ActiveSupport::TestCase :to => 'some_recipient@example.org', :subject => 'some subject2 / autobahn what else?', :message_id => 'some@id', - :body => 'some other message', + :body => 'some other message with strong text', + :content_type => 'text/html', :internal => false, :sender => Ticket::Article::Sender.where(:name => 'Customer').first, :type => Ticket::Article::Type.where(:name => 'email').first, :updated_by_id => 1, :created_by_id => 1, ) + + # add attachments which should get index + + # add attachments which should not get index + + # add to big attachment which should not get index + + + ticket2.search_index_update_backend ticket3 = Ticket.create( :title => "something else", :group => Group.lookup( :name => 'WithoutAccess'), - :customer_id => 2, + :customer_id => customer3.id, :state => Ticket::State.lookup( :name => 'open' ), :priority => Ticket::Priority.lookup( :name => '2 normal' ), :updated_by_id => 1, @@ -111,19 +164,41 @@ class ElasticsearchTest < ActiveSupport::TestCase ) ticket3.search_index_update_backend + sleep 4 + # search as agent + + # search for article data result = Ticket.search( :current_user => agent, :query => 'autobahn', :limit => 15, ) - assert(!result.empty?, 'result exists') + assert(!result.empty?, 'result exists not') assert(result[0], 'record 1') assert(!result[1], 'record 2') assert_equal(result[0].id, ticket2.id) + # search for html content + result = Ticket.search( + :current_user => agent, + :query => 'strong', + :limit => 15, + ) + assert(!result.empty?, 'result exists not') + assert(result[0], 'record 1') + assert(!result[1], 'record 2') + assert_equal(result[0].id, ticket2.id) + + # search for indexed attachment + + # search for not indexed attachment + + + + # search for ticket with no permissions result = Ticket.search( :current_user => agent, :query => 'kindergarden', @@ -133,5 +208,69 @@ class ElasticsearchTest < ActiveSupport::TestCase assert(!result[0], 'record 1') + # search as customer1 + result = Ticket.search( + :current_user => customer1, + :query => 'title OR else', + :limit => 15, + ) + + assert(!result.empty?, 'result exists not') + assert(result[0], 'record 1') + assert(result[1], 'record 2') + assert(!result[2], 'record 3') + assert_equal(result[0].id, ticket2.id) + assert_equal(result[1].id, ticket1.id) + + # search as customer2 + result = Ticket.search( + :current_user => customer2, + :query => 'title OR else', + :limit => 15, + ) + + assert(!result.empty?, 'result exists not') + assert(result[0], 'record 1') + assert(result[1], 'record 2') + assert(!result[2], 'record 3') + assert_equal(result[0].id, ticket2.id) + assert_equal(result[1].id, ticket1.id) + + # search as customer3 + result = Ticket.search( + :current_user => customer3, + :query => 'title OR else', + :limit => 15, + ) + + assert(!result.empty?, 'result exists not') + assert(result[0], 'record 1') + assert(!result[1], 'record 2') + assert_equal(result[0].id, ticket3.id) + end + + # check users and search it + test 'b - users' do + + # search as agent + result = User.search( + :current_user => agent, + :query => 'customer1', + :limit => 15, + ) + assert(!result.empty?, 'result should not be empty') + assert(result[0], 'record 1') + assert(!result[0], 'record 2') + assert_equal(result[0].id, customer1.id) + + # search as customer1 + result = User.search( + :current_user => customer1, + :query => 'customer1', + :limit => 15, + ) + assert(result.empty?, 'result should be empty') + assert(!result[0], 'record 1') + end end \ No newline at end of file