From 1a43d9bd5c0bdd66db5327c185e330576a64e89a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 14 Jun 2017 17:25:45 +0200 Subject: [PATCH] Improved tests. --- app/models/setting.rb | 5 +- app/models/user.rb | 14 +- db/seeds/community_user_resources.rb | 4 +- test/controllers/search_controller_test.rb | 57 +- test/integration/elasticsearch_test.rb | 302 ++++---- test/integration/report_test.rb | 613 ++++++++-------- test/integration_test_helper.rb | 9 + test/test_helper.rb | 20 +- test/unit/activity_stream_test.rb | 70 +- test/unit/cache_test.rb | 2 +- test/unit/chat_test.rb | 74 +- test/unit/online_notifiaction_test.rb | 295 ++++---- test/unit/session_basic_test.rb | 4 +- test/unit/session_collections_test.rb | 8 +- test/unit/session_enhanced_test.rb | 60 +- ...icket_customer_organization_update_test.rb | 36 +- test/unit/ticket_notification_test.rb | 673 +++++++++--------- test/unit/ticket_overview_test.rb | 219 +++--- test/unit/ticket_ref_object_touch_test.rb | 63 +- test/unit/ticket_selector_test.rb | 455 ++++++------ 20 files changed, 1481 insertions(+), 1502 deletions(-) diff --git a/app/models/setting.rb b/app/models/setting.rb index 1997c6ebb..17ff09e71 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -60,13 +60,16 @@ reset config setting to default Setting.reset('some_config_name') + Setting.reset('some_config_name', force) # true|false - force it false per default + =end - def self.reset(name) + def self.reset(name, force = false) setting = Setting.find_by(name: name) if !setting raise "Can't find config setting '#{name}'" end + return true if !force && setting.state_current == setting.state_initial setting.state_current = setting.state_initial setting.save! logger.info "Setting.reset(#{name}, #{setting.state_current.inspect})" diff --git a/app/models/user.rb b/app/models/user.rb index 8b01e0afa..6941fb1b4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -746,7 +746,7 @@ returns true end - def check_notifications(o) + def check_notifications(o, shouldSave = true) default = Rails.configuration.preferences_default_by_permission return if !default default.deep_stringify_keys! @@ -762,7 +762,7 @@ returns return true if !has_changed - if id + if id && shouldSave save! return true end @@ -772,8 +772,14 @@ returns end def check_preferences_default + if @preferences_default.blank? + if id + roles.each { |role| + check_notifications(role, false) + } + end + end return if @preferences_default.blank? - preferences_tmp = @preferences_default.merge(preferences) self.preferences = preferences_tmp @preferences_default = nil @@ -945,7 +951,7 @@ raise 'Minimum one user need to have admin permissions' # set the user's locale to the one of the "executing" user return if !UserInfo.current_user_id - user = User.find_by( id: UserInfo.current_user_id ) + user = User.find_by(id: UserInfo.current_user_id) return if !user return if !user.preferences[:locale] diff --git a/db/seeds/community_user_resources.rb b/db/seeds/community_user_resources.rb index e57a7c4a6..a8c4aff12 100644 --- a/db/seeds/community_user_resources.rb +++ b/db/seeds/community_user_resources.rb @@ -16,12 +16,12 @@ user_community = User.create_or_update( UserInfo.current_user_id = user_community.id -ticket = Ticket.create( +ticket = Ticket.create!( group_id: Group.find_by(name: 'Users').id, customer_id: User.find_by(login: 'nicole.braun@zammad.org').id, title: 'Welcome to Zammad!', ) -Ticket::Article.create( +Ticket::Article.create!( ticket_id: ticket.id, type_id: Ticket::Article::Type.find_by(name: 'phone').id, sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id, diff --git a/test/controllers/search_controller_test.rb b/test/controllers/search_controller_test.rb index 5ba3aa1de..dffe4e693 100644 --- a/test/controllers/search_controller_test.rb +++ b/test/controllers/search_controller_test.rb @@ -1,14 +1,9 @@ # encoding: utf-8 require 'test_helper' +require 'rake' class SearchControllerTest < ActionDispatch::IntegrationTest - def base_data - - # clear cache - Cache.clear - - # remove background jobs - Delayed::Job.destroy_all + setup do # set current user UserInfo.current_user_id = 1 @@ -92,16 +87,14 @@ class SearchControllerTest < ActionDispatch::IntegrationTest Ticket.all.destroy_all - @ticket1 = Ticket.create( + @ticket1 = Ticket.create!( title: 'test 1234-1', group: Group.lookup(name: 'Users'), customer_id: @customer_without_org.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: 1, - created_by_id: 1, ) - @article1 = Ticket::Article.create( + @article1 = Ticket::Article.create!( ticket_id: @ticket1.id, from: 'some_sender1@example.com', to: 'some_recipient1@example.com', @@ -111,20 +104,16 @@ class SearchControllerTest < ActionDispatch::IntegrationTest 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, ) sleep 1 - @ticket2 = Ticket.create( + @ticket2 = Ticket.create!( title: 'test 1234-2', group: Group.lookup(name: 'Users'), customer_id: @customer_with_org2.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: 1, - created_by_id: 1, ) - @article2 = Ticket::Article.create( + @article2 = Ticket::Article.create!( ticket_id: @ticket2.id, from: 'some_sender2@example.com', to: 'some_recipient2@example.com', @@ -134,20 +123,16 @@ class SearchControllerTest < ActionDispatch::IntegrationTest 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, ) sleep 1 - @ticket3 = Ticket.create( + @ticket3 = Ticket.create!( title: 'test 1234-2', group: Group.lookup(name: 'Users'), customer_id: @customer_with_org3.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: 1, - created_by_id: 1, ) - @article3 = Ticket::Article.create( + @article3 = Ticket::Article.create!( ticket_id: @ticket3.id, from: 'some_sender3@example.com', to: 'some_recipient3@example.com', @@ -157,12 +142,10 @@ class SearchControllerTest < ActionDispatch::IntegrationTest 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, ) # configure es - if ENV['ES_URL'] + if ENV['ES_URL'].present? #fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'" Setting.set('es_url', ENV['ES_URL']) @@ -174,15 +157,17 @@ class SearchControllerTest < ActionDispatch::IntegrationTest # set max attachment size in mb Setting.set('es_attachment_max_size_in_mb', 1) - if ENV['ES_INDEX'] + if ENV['ES_INDEX'].present? #fail "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'" Setting.set('es_index', ENV['ES_INDEX']) end # drop/create indexes + Rake::Task.clear + Zammad::Application.load_tasks #Rake::Task["searchindex:drop"].execute #Rake::Task["searchindex:create"].execute - system('rake searchindex:rebuild') + Rake::Task['searchindex:rebuild'].execute # execute background jobs Scheduler.worker(true) @@ -192,8 +177,6 @@ class SearchControllerTest < ActionDispatch::IntegrationTest end test 'settings index with nobody' do - base_data - params = { query: 'test 1234', limit: 2, @@ -219,19 +202,15 @@ class SearchControllerTest < ActionDispatch::IntegrationTest assert_equal(Hash, result.class) assert_not(result.empty?) assert_equal('authentication failed', result['error']) - end test 'settings index with admin' do - base_data - credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-admin@example.com', 'adminpw') params = { query: '1234*', limit: 1, } - post '/api/v1/search', params.to_json, @headers.merge('Authorization' => credentials) assert_response(200) result = JSON.parse(@response.body) @@ -293,12 +272,9 @@ class SearchControllerTest < ActionDispatch::IntegrationTest assert_equal('User', result['result'][0]['type']) assert_equal(@agent.id, result['result'][0]['id']) assert_not(result['result'][1]) - end test 'settings index with agent' do - base_data - credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-agent@example.com', 'agentpw') params = { @@ -367,12 +343,9 @@ class SearchControllerTest < ActionDispatch::IntegrationTest assert_equal('User', result['result'][0]['type']) assert_equal(@agent.id, result['result'][0]['id']) assert_not(result['result'][1]) - end test 'settings index with customer 1' do - base_data - credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-customer1@example.com', 'customer1pw') params = { @@ -413,12 +386,9 @@ class SearchControllerTest < ActionDispatch::IntegrationTest result = JSON.parse(@response.body) assert_equal(Hash, result.class) assert_not(result['result'][0]) - end test 'settings index with customer 2' do - base_data - credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-customer2@example.com', 'customer2pw') params = { @@ -463,7 +433,6 @@ class SearchControllerTest < ActionDispatch::IntegrationTest result = JSON.parse(@response.body) assert_equal(Hash, result.class) assert_not(result['result'][0]) - end end diff --git a/test/integration/elasticsearch_test.rb b/test/integration/elasticsearch_test.rb index d58771423..1df367b88 100644 --- a/test/integration/elasticsearch_test.rb +++ b/test/integration/elasticsearch_test.rb @@ -1,111 +1,117 @@ # encoding: utf-8 require 'integration_test_helper' +require 'rake' class ElasticsearchTest < ActiveSupport::TestCase - # set config - if !ENV['ES_URL'] - raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'" + setup do + + # set config + if ENV['ES_URL'].blank? + raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'" + end + Setting.set('es_url', ENV['ES_URL']) + if ENV['ES_INDEX_RAND'].present? + ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}" + end + if ENV['ES_INDEX'].blank? + raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'" + end + Setting.set('es_index', ENV['ES_INDEX']) + + # Setting.set('es_url', 'http://127.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.clear + Zammad::Application.load_tasks + #Rake::Task["searchindex:drop"].execute + #Rake::Task["searchindex:create"].execute + Rake::Task['searchindex:rebuild'].execute + + 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', + note: 'some note', + 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_url', ENV['ES_URL']) - if !ENV['ES_INDEX'] && !ENV['ES_INDEX_RAND'] - raise "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://127.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', - note: 'some note', - 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 search attributes test 'a - objects' do # user - attributes = agent.search_index_data + attributes = @agent.search_index_data assert_equal('E', attributes['firstname']) assert_equal('S', attributes['lastname']) assert_equal('es-agent@example.com', attributes['email']) assert_not(attributes['password']) assert_not(attributes['organization']) - attributes = agent.search_index_attribute_lookup + attributes = @agent.search_index_attribute_lookup assert_equal('E', attributes['firstname']) assert_equal('S', attributes['lastname']) assert_equal('es-agent@example.com', attributes['email']) @@ -113,27 +119,27 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_not(attributes['organization']) # organization - attributes = organization1.search_index_data + attributes = @organization1.search_index_data assert_equal('Customer Organization Update', attributes['name']) assert_equal('some note', attributes['note']) assert_not(attributes['members']) - attributes = organization1.search_index_attribute_lookup + attributes = @organization1.search_index_attribute_lookup assert_equal('Customer Organization Update', attributes['name']) assert_equal('some note', attributes['note']) assert(attributes['members']) # ticket/article - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: 'some title äöüß', group: Group.lookup(name: 'Users'), - customer_id: customer1.id, + customer_id: @customer1.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) - article1 = Ticket::Article.create( + article1 = Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -146,6 +152,14 @@ class ElasticsearchTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) + Store.add( + object: 'Ticket::Article', + o_id: article1.id, + data: IO.binread("#{Rails.root}/test/fixtures/es-normal.txt"), + filename: 'es-normal.txt', + preferences: {}, + created_by_id: 1, + ) attributes = ticket1.search_index_attribute_lookup assert_equal('Users', attributes['group']) @@ -163,28 +177,27 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_not(attributes['owner']['password']) assert_not(attributes['owner']['organization']) + 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']) + assert_equal("c29tZSBub3JtYWwgdGV4dDY2Cg==\n", attributes['article'][0]['attachment'][0]['_content']) + ticket1.destroy # execute background jobs Scheduler.worker(true) - end - - # check tickets and search it - test 'b - tickets' do - - system('rake searchindex:rebuild') - - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: "some title\n äöüß", group: Group.lookup(name: 'Users'), - customer_id: customer1.id, + customer_id: @customer1.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) - article1 = Ticket::Article.create( + article1 = Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -199,7 +212,7 @@ class ElasticsearchTest < ActiveSupport::TestCase ) # add attachments which should get index / .txt - # "some normal text" + # "some normal text66" Store.add( object: 'Ticket::Article', o_id: article1.id, @@ -244,16 +257,16 @@ class ElasticsearchTest < ActiveSupport::TestCase ticket1.tag_add('someTagA', 1) sleep 1 - ticket2 = Ticket.create( + ticket2 = Ticket.create!( title: 'something else', group: Group.lookup(name: 'Users'), - customer_id: customer2.id, + customer_id: @customer2.id, state: Ticket::State.lookup(name: 'open'), priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) - article2 = Ticket::Article.create( + article2 = Ticket::Article.create!( ticket_id: ticket2.id, from: 'some_sender@example.org', to: 'some_recipient@example.org', @@ -270,16 +283,16 @@ class ElasticsearchTest < ActiveSupport::TestCase ticket2.tag_add('someTagB', 1) sleep 1 - ticket3 = Ticket.create( + ticket3 = Ticket.create!( title: 'something else', group: Group.lookup(name: 'WithoutAccess'), - customer_id: customer3.id, + customer_id: @customer3.id, state: Ticket::State.lookup(name: 'open'), priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) - article3 = Ticket::Article.create( + article3 = Ticket::Article.create!( ticket_id: ticket3.id, from: 'some_sender@example.org', to: 'some_recipient@example.org', @@ -295,14 +308,13 @@ class ElasticsearchTest < ActiveSupport::TestCase # execute background jobs Scheduler.worker(true) - sleep 4 - # search as agent + # search as @agent # search for article data result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'autobahn', limit: 15, ) @@ -314,7 +326,7 @@ class ElasticsearchTest < ActiveSupport::TestCase # search for html content result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'strong', limit: 15, ) @@ -326,7 +338,7 @@ class ElasticsearchTest < ActiveSupport::TestCase # search for indexed attachment result = Ticket.search( - current_user: agent, + current_user: @agent, query: '"some normal text66"', limit: 15, ) @@ -334,7 +346,7 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_equal(result[0].id, ticket1.id) result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'test77', limit: 15, ) @@ -343,14 +355,14 @@ class ElasticsearchTest < ActiveSupport::TestCase # search for not indexed attachment result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'test88', limit: 15, ) assert(!result[0], 'record 1') result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'test99', limit: 15, ) @@ -358,16 +370,16 @@ class ElasticsearchTest < ActiveSupport::TestCase # search for ticket with no permissions result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'kindergarden', limit: 15, ) assert(result.empty?, 'result should be empty') assert(!result[0], 'record 1') - # search as customer1 + # search as @customer1 result = Ticket.search( - current_user: customer1, + current_user: @customer1, query: 'title OR else', limit: 15, ) @@ -379,9 +391,9 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_equal(result[0].id, ticket2.id) assert_equal(result[1].id, ticket1.id) - # search as customer2 + # search as @customer2 result = Ticket.search( - current_user: customer2, + current_user: @customer2, query: 'title OR else', limit: 15, ) @@ -393,9 +405,9 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_equal(result[0].id, ticket2.id) assert_equal(result[1].id, ticket1.id) - # search as customer3 + # search as @customer3 result = Ticket.search( - current_user: customer3, + current_user: @customer3, query: 'title OR else', limit: 15, ) @@ -407,7 +419,7 @@ class ElasticsearchTest < ActiveSupport::TestCase # search for tags result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'tag:someTagA', limit: 15, ) @@ -416,7 +428,7 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_equal(result[0].id, ticket1.id) result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'tag:someTagB', limit: 15, ) @@ -439,7 +451,7 @@ class ElasticsearchTest < ActiveSupport::TestCase # search for tags result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'tag:someTagA', limit: 15, ) @@ -447,7 +459,7 @@ class ElasticsearchTest < ActiveSupport::TestCase assert(!result[1], 'record 1') result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'tag:someTagB', limit: 15, ) @@ -456,7 +468,7 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_equal(result[0].id, ticket2.id) result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'tag:someTagC', limit: 15, ) @@ -465,7 +477,7 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_equal(result[0].id, ticket1.id) result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'state:open', limit: 15, ) @@ -474,7 +486,7 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_equal(result[0].id, ticket2.id) result = Ticket.search( - current_user: agent, + current_user: @agent, query: '"some_sender@example.com"', limit: 15, ) @@ -483,7 +495,7 @@ class ElasticsearchTest < ActiveSupport::TestCase assert_equal(result[0].id, ticket1.id) result = Ticket.search( - current_user: agent, + current_user: @agent, query: 'article.from:"some_sender@example.com"', limit: 15, ) @@ -491,25 +503,21 @@ class ElasticsearchTest < ActiveSupport::TestCase assert(!result[1], 'record 2') assert_equal(result[0].id, ticket1.id) - end - - # check users and search it - test 'c - users' do - - # search as agent + # check users and search it + # search as @agent result = User.search( - current_user: agent, + current_user: @agent, query: 'customer1', limit: 15, ) assert(!result.empty?, 'result should not be empty') assert(result[0], 'record 1') assert(!result[1], 'record 2') - assert_equal(result[0].id, customer1.id) + assert_equal(result[0].id, @customer1.id) - # search as customer1 + # search as @customer1 result = User.search( - current_user: customer1, + current_user: @customer1, query: 'customer1', limit: 15, ) @@ -517,7 +525,7 @@ class ElasticsearchTest < ActiveSupport::TestCase assert(!result[0], 'record 1') # cleanup - system('rake searchindex:drop') + Rake::Task['searchindex:drop'].execute end end diff --git a/test/integration/report_test.rb b/test/integration/report_test.rb index adc5db302..c90f7a561 100644 --- a/test/integration/report_test.rb +++ b/test/integration/report_test.rb @@ -1,262 +1,258 @@ # encoding: utf-8 require 'integration_test_helper' +require 'rake' class ReportTest < ActiveSupport::TestCase - # set config - if !ENV['ES_URL'] - raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'" + setup do + + # set config + if !ENV['ES_URL'] + raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'" + end + Setting.set('es_url', ENV['ES_URL']) + if ENV['ES_INDEX_RAND'].present? + ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}" + end + if ENV['ES_INDEX'].blank? + raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'" + end + + # Setting.set('es_url', 'http://127.0.0.1:9200') + # Setting.set('es_index', 'estest.local_zammad') + # Setting.set('es_user', 'elasticsearch') + # Setting.set('es_password', 'zammad') + # Setting.set('es_attachment_max_size_in_mb', 1) + + Ticket.destroy_all + + # drop/create indexes + Rake::Task.clear + Zammad::Application.load_tasks + #Rake::Task["searchindex:drop"].execute + #Rake::Task["searchindex:create"].execute + Rake::Task['searchindex:rebuild'].execute + + group1 = Group.lookup(name: 'Users') + group2 = Group.create_if_not_exists( + name: 'Report Test', + updated_by_id: 1, + created_by_id: 1 + ) + + @ticket1 = Ticket.create!( + title: 'test 1', + group: group2, + customer_id: 2, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + created_at: '2015-10-28 09:30:00 UTC', + updated_at: '2015-10-28 09:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + Ticket::Article.create!( + ticket_id: @ticket1.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + body: 'some message article_inbound', + internal: false, + sender: Ticket::Article::Sender.where(name: 'Customer').first, + type: Ticket::Article::Type.where(name: 'email').first, + created_at: '2015-10-28 09:30:00 UTC', + updated_at: '2015-10-28 09:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + @ticket1.update_attributes( + group: Group.lookup(name: 'Users'), + updated_at: '2015-10-28 14:30:00 UTC', + ) + + @ticket2 = Ticket.create!( + title: 'test 2', + group: group1, + customer_id: 2, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + created_at: '2015-10-28 09:30:01 UTC', + updated_at: '2015-10-28 09:30:01 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + Ticket::Article.create!( + ticket_id: @ticket2.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + body: 'some message article_inbound', + internal: false, + sender: Ticket::Article::Sender.where(name: 'Customer').first, + type: Ticket::Article::Type.where(name: 'email').first, + created_at: '2015-10-28 09:30:01 UTC', + updated_at: '2015-10-28 09:30:01 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + @ticket2.update_attributes( + group_id: group2.id, + updated_at: '2015-10-28 14:30:00 UTC', + ) + + @ticket3 = Ticket.create!( + title: 'test 3', + group: group1, + customer_id: 2, + state: Ticket::State.lookup(name: 'open'), + priority: Ticket::Priority.lookup(name: '3 high'), + created_at: '2015-10-28 10:30:00 UTC', + updated_at: '2015-10-28 10:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + Ticket::Article.create!( + ticket_id: @ticket3.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + body: 'some message article_inbound', + internal: false, + sender: Ticket::Article::Sender.where(name: 'Customer').first, + type: Ticket::Article::Type.where(name: 'email').first, + created_at: '2015-10-28 10:30:00 UTC', + updated_at: '2015-10-28 10:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + + @ticket4 = Ticket.create!( + title: 'test 4', + group: group1, + customer_id: 2, + state: Ticket::State.lookup(name: 'closed'), + priority: Ticket::Priority.lookup(name: '2 normal'), + close_at: '2015-10-28 11:30:00 UTC', + created_at: '2015-10-28 10:30:00 UTC', + updated_at: '2015-10-28 10:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + Ticket::Article.create!( + ticket_id: @ticket4.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + body: 'some message article_inbound', + internal: false, + sender: Ticket::Article::Sender.where(name: 'Customer').first, + type: Ticket::Article::Type.where(name: 'email').first, + created_at: '2015-10-28 10:30:00 UTC', + updated_at: '2015-10-28 10:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + + @ticket5 = Ticket.create!( + title: 'test 5', + group: group1, + customer_id: 2, + state: Ticket::State.lookup(name: 'closed'), + priority: Ticket::Priority.lookup(name: '3 high'), + close_at: '2015-10-28 11:40:00 UTC', + created_at: '2015-10-28 11:30:00 UTC', + updated_at: '2015-10-28 11:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + Ticket::Article.create!( + ticket_id: @ticket5.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + body: 'some message article_outbound', + internal: false, + sender: Ticket::Article::Sender.where(name: 'Agent').first, + type: Ticket::Article::Type.where(name: 'email').first, + created_at: '2015-10-28 11:30:00 UTC', + updated_at: '2015-10-28 11:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + @ticket5.update_attributes( + state: Ticket::State.lookup(name: 'open'), + updated_at: '2015-10-28 14:30:00 UTC', + ) + + @ticket6 = Ticket.create!( + title: 'test 6', + group: group1, + customer_id: 2, + state: Ticket::State.lookup(name: 'closed'), + priority: Ticket::Priority.lookup(name: '2 normal'), + close_at: '2015-10-31 12:35:00 UTC', + created_at: '2015-10-31 12:30:00 UTC', + updated_at: '2015-10-31 12:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + Ticket::Article.create!( + ticket_id: @ticket6.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + body: 'some message article_outbound', + internal: false, + sender: Ticket::Article::Sender.where(name: 'Agent').first, + type: Ticket::Article::Type.where(name: 'email').first, + created_at: '2015-10-31 12:30:00 UTC', + updated_at: '2015-10-31 12:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + + @ticket7 = Ticket.create!( + title: 'test 7', + group: group1, + customer_id: 2, + state: Ticket::State.lookup(name: 'closed'), + priority: Ticket::Priority.lookup(name: '2 normal'), + close_at: '2015-11-01 12:30:00 UTC', + created_at: '2015-11-01 12:30:00 UTC', + updated_at: '2015-11-01 12:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + Ticket::Article.create!( + ticket_id: @ticket7.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + body: 'some message article_outbound', + internal: false, + sender: Ticket::Article::Sender.where(name: 'Agent').first, + type: Ticket::Article::Type.where(name: 'email').first, + created_at: '2015-11-01 12:30:00 UTC', + updated_at: '2015-11-01 12:30:00 UTC', + updated_by_id: 1, + created_by_id: 1, + ) + + # execute background jobs + Scheduler.worker(true) + end - Setting.set('es_url', ENV['ES_URL']) - if !ENV['ES_INDEX'] && !ENV['ES_INDEX_RAND'] - raise "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://127.0.0.1:9200') - # Setting.set('es_index', 'estest.local_zammad') - # Setting.set('es_user', 'elasticsearch') - # Setting.set('es_password', 'zammad') - # Setting.set('es_attachment_max_size_in_mb', 1) + test 'compare' do - # clear cache - Cache.clear - - # remove background jobs - Delayed::Job.destroy_all - - Ticket.destroy_all - - # drop/create indexes - #Rake::Task["searchindex:drop"].execute - #Rake::Task["searchindex:create"].execute - system('rake searchindex:rebuild') - - group1 = Group.lookup(name: 'Users') - group2 = Group.create_if_not_exists( - name: 'Report Test', - updated_by_id: 1, - created_by_id: 1 - ) - - load "#{Rails.root}/test/fixtures/seeds.rb" - - ticket1 = Ticket.create( - title: 'test 1', - group: group2, - customer_id: 2, - state: Ticket::State.lookup(name: 'new'), - priority: Ticket::Priority.lookup(name: '2 normal'), - created_at: '2015-10-28 09:30:00 UTC', - updated_at: '2015-10-28 09:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - article1 = Ticket::Article.create( - ticket_id: ticket1.id, - from: 'some_sender@example.com', - to: 'some_recipient@example.com', - subject: 'some subject', - message_id: 'some@id', - body: 'some message article_inbound', - internal: false, - sender: Ticket::Article::Sender.where(name: 'Customer').first, - type: Ticket::Article::Type.where(name: 'email').first, - created_at: '2015-10-28 09:30:00 UTC', - updated_at: '2015-10-28 09:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - ticket1.update_attributes( - group: Group.lookup(name: 'Users'), - updated_at: '2015-10-28 14:30:00 UTC', - ) - - ticket2 = Ticket.create( - title: 'test 2', - group: group1, - customer_id: 2, - state: Ticket::State.lookup(name: 'new'), - priority: Ticket::Priority.lookup(name: '2 normal'), - created_at: '2015-10-28 09:30:01 UTC', - updated_at: '2015-10-28 09:30:01 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - article2 = Ticket::Article.create( - ticket_id: ticket2.id, - from: 'some_sender@example.com', - to: 'some_recipient@example.com', - subject: 'some subject', - message_id: 'some@id', - body: 'some message article_inbound', - internal: false, - sender: Ticket::Article::Sender.where(name: 'Customer').first, - type: Ticket::Article::Type.where(name: 'email').first, - created_at: '2015-10-28 09:30:01 UTC', - updated_at: '2015-10-28 09:30:01 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - ticket2.update_attributes( - group_id: group2.id, - updated_at: '2015-10-28 14:30:00 UTC', - ) - - ticket3 = Ticket.create( - title: 'test 3', - group: group1, - customer_id: 2, - state: Ticket::State.lookup(name: 'open'), - priority: Ticket::Priority.lookup(name: '3 high'), - created_at: '2015-10-28 10:30:00 UTC', - updated_at: '2015-10-28 10:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - article3 = Ticket::Article.create( - ticket_id: ticket3.id, - from: 'some_sender@example.com', - to: 'some_recipient@example.com', - subject: 'some subject', - message_id: 'some@id', - body: 'some message article_inbound', - internal: false, - sender: Ticket::Article::Sender.where(name: 'Customer').first, - type: Ticket::Article::Type.where(name: 'email').first, - created_at: '2015-10-28 10:30:00 UTC', - updated_at: '2015-10-28 10:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - - ticket4 = Ticket.create( - title: 'test 4', - group: group1, - customer_id: 2, - state: Ticket::State.lookup(name: 'closed'), - priority: Ticket::Priority.lookup(name: '2 normal'), - close_at: '2015-10-28 11:30:00 UTC', - created_at: '2015-10-28 10:30:00 UTC', - updated_at: '2015-10-28 10:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - article4 = Ticket::Article.create( - ticket_id: ticket4.id, - from: 'some_sender@example.com', - to: 'some_recipient@example.com', - subject: 'some subject', - message_id: 'some@id', - body: 'some message article_inbound', - internal: false, - sender: Ticket::Article::Sender.where(name: 'Customer').first, - type: Ticket::Article::Type.where(name: 'email').first, - created_at: '2015-10-28 10:30:00 UTC', - updated_at: '2015-10-28 10:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - - ticket5 = Ticket.create( - title: 'test 5', - group: group1, - customer_id: 2, - state: Ticket::State.lookup(name: 'closed'), - priority: Ticket::Priority.lookup(name: '3 high'), - close_at: '2015-10-28 11:40:00 UTC', - created_at: '2015-10-28 11:30:00 UTC', - updated_at: '2015-10-28 11:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - article5 = Ticket::Article.create( - ticket_id: ticket5.id, - from: 'some_sender@example.com', - to: 'some_recipient@example.com', - subject: 'some subject', - message_id: 'some@id', - body: 'some message article_outbound', - internal: false, - sender: Ticket::Article::Sender.where(name: 'Agent').first, - type: Ticket::Article::Type.where(name: 'email').first, - created_at: '2015-10-28 11:30:00 UTC', - updated_at: '2015-10-28 11:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - ticket5.update_attributes( - state: Ticket::State.lookup(name: 'open'), - updated_at: '2015-10-28 14:30:00 UTC', - ) - - ticket6 = Ticket.create( - title: 'test 6', - group: group1, - customer_id: 2, - state: Ticket::State.lookup(name: 'closed'), - priority: Ticket::Priority.lookup(name: '2 normal'), - close_at: '2015-10-31 12:35:00 UTC', - created_at: '2015-10-31 12:30:00 UTC', - updated_at: '2015-10-31 12:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - article6 = Ticket::Article.create( - ticket_id: ticket6.id, - from: 'some_sender@example.com', - to: 'some_recipient@example.com', - subject: 'some subject', - message_id: 'some@id', - body: 'some message article_outbound', - internal: false, - sender: Ticket::Article::Sender.where(name: 'Agent').first, - type: Ticket::Article::Type.where(name: 'email').first, - created_at: '2015-10-31 12:30:00 UTC', - updated_at: '2015-10-31 12:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - - ticket7 = Ticket.create( - title: 'test 7', - group: group1, - customer_id: 2, - state: Ticket::State.lookup(name: 'closed'), - priority: Ticket::Priority.lookup(name: '2 normal'), - close_at: '2015-11-01 12:30:00 UTC', - created_at: '2015-11-01 12:30:00 UTC', - updated_at: '2015-11-01 12:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - article7 = Ticket::Article.create( - ticket_id: ticket7.id, - from: 'some_sender@example.com', - to: 'some_recipient@example.com', - subject: 'some subject', - message_id: 'some@id', - body: 'some message article_outbound', - internal: false, - sender: Ticket::Article::Sender.where(name: 'Agent').first, - type: Ticket::Article::Type.where(name: 'email').first, - created_at: '2015-11-01 12:30:00 UTC', - updated_at: '2015-11-01 12:30:00 UTC', - updated_by_id: 1, - created_by_id: 1, - ) - - # execute background jobs - Scheduler.worker(true) - - sleep 6 - - test 'a - first solution' do - - # month + # first solution result = Report::TicketFirstSolution.aggs( range_start: '2015-01-01T00:00:00Z', range_end: '2015-12-31T23:59:59Z', @@ -276,7 +272,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(2, result[9]) assert_equal(1, result[10]) assert_equal(0, result[11]) - assert_equal(nil, result[12]) + assert_nil(result[12]) result = Report::TicketFirstSolution.items( range_start: '2015-01-01T00:00:00Z', @@ -284,10 +280,10 @@ class ReportTest < ActiveSupport::TestCase selector: {}, # ticket selector to get only a collection of tickets ) assert(result) - assert_equal(ticket5.id, result[:ticket_ids][0]) - assert_equal(ticket6.id, result[:ticket_ids][1]) - assert_equal(ticket7.id, result[:ticket_ids][2]) - assert_equal(nil, result[:ticket_ids][3]) + assert_equal(@ticket5.id, result[:ticket_ids][0]) + assert_equal(@ticket6.id, result[:ticket_ids][1]) + assert_equal(@ticket7.id, result[:ticket_ids][2]) + assert_nil(result[:ticket_ids][3]) # month - with selector #1 result = Report::TicketFirstSolution.aggs( @@ -314,7 +310,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(1, result[9]) assert_equal(0, result[10]) assert_equal(0, result[11]) - assert_equal(nil, result[12]) + assert_nil(result[12]) result = Report::TicketFirstSolution.items( range_start: '2015-01-01T00:00:00Z', @@ -327,8 +323,8 @@ class ReportTest < ActiveSupport::TestCase }, # ticket selector to get only a collection of tickets ) assert(result) - assert_equal(ticket5.id, result[:ticket_ids][0]) - assert_equal(nil, result[:ticket_ids][1]) + assert_equal(@ticket5.id, result[:ticket_ids][0]) + assert_nil(result[:ticket_ids][1]) # month - with selector #2 result = Report::TicketFirstSolution.aggs( @@ -355,7 +351,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(1, result[9]) assert_equal(1, result[10]) assert_equal(0, result[11]) - assert_equal(nil, result[12]) + assert_nil(result[12]) result = Report::TicketFirstSolution.items( range_start: '2015-01-01T00:00:00Z', @@ -368,9 +364,9 @@ class ReportTest < ActiveSupport::TestCase }, # ticket selector to get only a collection of tickets ) assert(result) - assert_equal(ticket6.id, result[:ticket_ids][0]) - assert_equal(ticket7.id, result[:ticket_ids][1]) - assert_equal(nil, result[:ticket_ids][2]) + assert_equal(@ticket6.id, result[:ticket_ids][0]) + assert_equal(@ticket7.id, result[:ticket_ids][1]) + assert_nil(result[:ticket_ids][2]) # week result = Report::TicketFirstSolution.aggs( @@ -387,7 +383,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(0, result[4]) assert_equal(1, result[5]) assert_equal(1, result[6]) - assert_equal(nil, result[7]) + assert_nil(result[7]) result = Report::TicketFirstSolution.items( range_start: '2015-10-26T00:00:00Z', @@ -396,10 +392,10 @@ class ReportTest < ActiveSupport::TestCase selector: {}, # ticket selector to get only a collection of tickets ) assert(result) - assert_equal(ticket5.id, result[:ticket_ids][0]) - assert_equal(ticket6.id, result[:ticket_ids][1]) - assert_equal(ticket7.id, result[:ticket_ids][2]) - assert_equal(nil, result[:ticket_ids][3]) + assert_equal(@ticket5.id, result[:ticket_ids][0]) + assert_equal(@ticket6.id, result[:ticket_ids][1]) + assert_equal(@ticket7.id, result[:ticket_ids][2]) + assert_nil(result[:ticket_ids][3]) # day result = Report::TicketFirstSolution.aggs( @@ -440,7 +436,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(0, result[28]) assert_equal(0, result[29]) assert_equal(1, result[30]) - assert_equal(nil, result[31]) + assert_nil(result[31]) result = Report::TicketFirstSolution.items( range_start: '2015-10-01T00:00:00Z', @@ -449,9 +445,9 @@ class ReportTest < ActiveSupport::TestCase selector: {}, # ticket selector to get only a collection of tickets ) assert(result) - assert_equal(ticket5.id, result[:ticket_ids][0]) - assert_equal(ticket6.id, result[:ticket_ids][1]) - assert_equal(nil, result[:ticket_ids][2]) + assert_equal(@ticket5.id, result[:ticket_ids][0]) + assert_equal(@ticket6.id, result[:ticket_ids][1]) + assert_nil(result[:ticket_ids][2]) # hour result = Report::TicketFirstSolution.aggs( @@ -485,7 +481,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(0, result[21]) assert_equal(0, result[22]) assert_equal(0, result[23]) - assert_equal(nil, result[24]) + assert_nil(result[24]) result = Report::TicketFirstSolution.items( range_start: '2015-10-28T00:00:00Z', @@ -494,15 +490,10 @@ class ReportTest < ActiveSupport::TestCase selector: {}, # ticket selector to get only a collection of tickets ) assert(result) - assert_equal(ticket5.id, result[:ticket_ids][0]) - assert_equal(nil, result[:ticket_ids][1]) + assert_equal(@ticket5.id, result[:ticket_ids][0]) + assert_nil(result[:ticket_ids][1]) - # created by channel and direction - end - - test 'b - reopen' do - - # month + # reopen result = Report::TicketReopened.aggs( range_start: '2015-01-01T00:00:00Z', range_end: '2015-12-31T23:59:59Z', @@ -522,7 +513,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(1, result[9]) assert_equal(0, result[10]) assert_equal(0, result[11]) - assert_equal(nil, result[12]) + assert_nil(result[12]) result = Report::TicketReopened.items( range_start: '2015-01-01T00:00:00Z', @@ -530,8 +521,8 @@ class ReportTest < ActiveSupport::TestCase selector: {}, # ticket selector to get only a collection of tickets ) assert(result) - assert_equal(ticket5.id, result[:ticket_ids][0]) - assert_equal(nil, result[:ticket_ids][1]) + assert_equal(@ticket5.id, result[:ticket_ids][0]) + assert_nil(result[:ticket_ids][1]) # month - with selector #1 result = Report::TicketReopened.aggs( @@ -558,7 +549,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(1, result[9]) assert_equal(0, result[10]) assert_equal(0, result[11]) - assert_equal(nil, result[12]) + assert_nil(result[12]) result = Report::TicketReopened.items( range_start: '2015-01-01T00:00:00Z', @@ -571,8 +562,8 @@ class ReportTest < ActiveSupport::TestCase }, # ticket selector to get only a collection of tickets ) assert(result) - assert_equal(ticket5.id, result[:ticket_ids][0]) - assert_equal(nil, result[:ticket_ids][1]) + assert_equal(@ticket5.id, result[:ticket_ids][0]) + assert_nil(result[:ticket_ids][1]) # month - with selector #2 result = Report::TicketReopened.aggs( @@ -599,7 +590,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(0, result[9]) assert_equal(0, result[10]) assert_equal(0, result[11]) - assert_equal(nil, result[12]) + assert_nil(result[12]) result = Report::TicketReopened.items( range_start: '2015-01-01T00:00:00Z', @@ -612,13 +603,9 @@ class ReportTest < ActiveSupport::TestCase }, # ticket selector to get only a collection of tickets ) assert(result) - assert_equal(nil, result[:ticket_ids][0]) + assert_nil(result[:ticket_ids][0]) - end - - test 'c - move in/out' do - - # month + # move in/out result = Report::TicketMoved.aggs( range_start: '2015-01-01T00:00:00Z', range_end: '2015-12-31T23:59:59Z', @@ -646,7 +633,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(1, result[9]) assert_equal(0, result[10]) assert_equal(0, result[11]) - assert_equal(nil, result[12]) + assert_nil(result[12]) result = Report::TicketMoved.items( range_start: '2015-01-01T00:00:00Z', @@ -662,8 +649,8 @@ class ReportTest < ActiveSupport::TestCase }, ) assert(result) - assert_equal(ticket1.id, result[:ticket_ids][0]) - assert_equal(nil, result[:ticket_ids][1]) + assert_equal(@ticket1.id, result[:ticket_ids][0]) + assert_nil(result[:ticket_ids][1]) # out result = Report::TicketMoved.aggs( @@ -693,7 +680,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(1, result[9]) assert_equal(0, result[10]) assert_equal(0, result[11]) - assert_equal(nil, result[12]) + assert_nil(result[12]) result = Report::TicketMoved.items( range_start: '2015-01-01T00:00:00Z', @@ -709,14 +696,10 @@ class ReportTest < ActiveSupport::TestCase }, ) assert(result) - assert_equal(ticket2.id, result[:ticket_ids][0]) - assert_equal(nil, result[:ticket_ids][1]) + assert_equal(@ticket2.id, result[:ticket_ids][0]) + assert_nil(result[:ticket_ids][1]) - end - - test 'd - created at' do - - # month + # create at result = Report::TicketGenericTime.aggs( range_start: '2015-01-01T00:00:00Z', range_end: '2015-12-31T23:59:59Z', @@ -737,7 +720,7 @@ class ReportTest < ActiveSupport::TestCase assert_equal(6, result[9]) assert_equal(1, result[10]) assert_equal(0, result[11]) - assert_equal(nil, result[12]) + assert_nil(result[12]) result = Report::TicketGenericTime.items( range_start: '2015-01-01T00:00:00Z', @@ -747,17 +730,17 @@ class ReportTest < ActiveSupport::TestCase ) assert(result) - assert_equal(ticket7.id, result[:ticket_ids][0].to_i) - assert_equal(ticket6.id, result[:ticket_ids][1].to_i) - assert_equal(ticket5.id, result[:ticket_ids][2].to_i) - assert_equal(ticket3.id, result[:ticket_ids][3].to_i) - assert_equal(ticket4.id, result[:ticket_ids][4].to_i) - assert_equal(ticket2.id, result[:ticket_ids][5].to_i) - assert_equal(ticket1.id, result[:ticket_ids][6].to_i) - assert_equal(nil, result[:ticket_ids][7]) + assert_equal(@ticket7.id, result[:ticket_ids][0].to_i) + assert_equal(@ticket6.id, result[:ticket_ids][1].to_i) + assert_equal(@ticket5.id, result[:ticket_ids][2].to_i) + assert_equal(@ticket3.id, result[:ticket_ids][3].to_i) + assert_equal(@ticket4.id, result[:ticket_ids][4].to_i) + assert_equal(@ticket2.id, result[:ticket_ids][5].to_i) + assert_equal(@ticket1.id, result[:ticket_ids][6].to_i) + assert_nil(result[:ticket_ids][7]) # cleanup - system('rake searchindex:drop') + Rake::Task['searchindex:drop'].execute end end diff --git a/test/integration_test_helper.rb b/test/integration_test_helper.rb index d04873d37..37e183bbe 100644 --- a/test/integration_test_helper.rb +++ b/test/integration_test_helper.rb @@ -7,6 +7,9 @@ class ActiveSupport::TestCase # disable transactions #self.use_transactional_fixtures = false + ActiveRecord::Base.logger = Rails.logger.clone + ActiveRecord::Base.logger.level = Logger::INFO + # clear cache Cache.clear @@ -19,8 +22,14 @@ class ActiveSupport::TestCase # clear cache Cache.clear + # remove all session messages + Sessions.cleanup + # remove background jobs Delayed::Job.destroy_all + Trigger.destroy_all + ActivityStream.destroy_all + PostmasterFilter.destroy_all # set current user UserInfo.current_user_id = nil diff --git a/test/test_helper.rb b/test/test_helper.rb index a003338b7..24f283f45 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,6 +12,9 @@ Coveralls.wear! class ActiveSupport::TestCase self.test_order = :sorted + ActiveRecord::Base.logger = Rails.logger.clone + ActiveRecord::Base.logger.level = Logger::INFO + # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests @@ -37,7 +40,14 @@ class ActiveSupport::TestCase # set system mode to done / to activate Setting.set('system_init_done', true) - def setup + setup do + + # exit all threads + Thread.list.each do |thread| + next if thread == Thread.current + thread.exit + thread.join + end # clear cache Cache.clear @@ -52,6 +62,14 @@ class ActiveSupport::TestCase PostmasterFilter.destroy_all Ticket.destroy_all + # reset settings + Setting.all.pluck(:name).each { |name| + next if name == 'models_searchable' # skip setting + Setting.reset(name, false) + } + Setting.set('system_init_done', true) + Setting.reload + # set current user UserInfo.current_user_id = nil diff --git a/test/unit/activity_stream_test.rb b/test/unit/activity_stream_test.rb index 47cef8b35..27b905ad1 100644 --- a/test/unit/activity_stream_test.rb +++ b/test/unit/activity_stream_test.rb @@ -2,12 +2,11 @@ require 'test_helper' class ActivityStreamTest < ActiveSupport::TestCase - admin_user = nil - current_user = nil - test 'aaa - setup' do + + setup do roles = Role.where(name: %w(Admin Agent)) - group = Group.lookup(name: 'Users') - admin_user = User.create_or_update( + groups = Group.where(name: 'Users') + @admin_user = User.create_or_update( login: 'admin', firstname: 'Bob', lastname: 'Smith', @@ -15,30 +14,31 @@ class ActivityStreamTest < ActiveSupport::TestCase password: 'some_pass', active: true, roles: roles, - group_ids: [group.id], + groups: groups, updated_by_id: 1, created_by_id: 1 ) - current_user = User.lookup(email: 'nicole.braun@zammad.org') + @current_user = User.lookup(email: 'nicole.braun@zammad.org') + ActivityStream.delete_all end test 'ticket+user' do ticket = Ticket.create( group_id: Group.lookup(name: 'Users').id, - customer_id: current_user.id, + customer_id: @current_user.id, owner_id: User.lookup(login: '-').id, title: 'Unit Test 1 (äöüß)!', state_id: Ticket::State.lookup(name: 'new').id, priority_id: Ticket::Priority.lookup(name: '2 normal').id, - updated_by_id: current_user.id, - created_by_id: current_user.id, + updated_by_id: @current_user.id, + created_by_id: @current_user.id, ) travel 2.seconds article = Ticket::Article.create( ticket_id: ticket.id, - updated_by_id: current_user.id, - created_by_id: current_user.id, + updated_by_id: @current_user.id, + created_by_id: @current_user.id, type_id: Ticket::Article::Type.lookup(name: 'phone').id, sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id, from: 'Unit Test ', @@ -61,28 +61,28 @@ class ActivityStreamTest < ActiveSupport::TestCase ) # check activity_stream - stream = admin_user.activity_stream(4) + stream = @admin_user.activity_stream(4) assert_equal(stream[0]['group_id'], ticket.group_id) assert_equal(stream[0]['o_id'], ticket.id) - assert_equal(stream[0]['created_by_id'], current_user.id) + assert_equal(stream[0]['created_by_id'], @current_user.id) assert_equal(stream[0]['created_at'].to_s, updated_at.to_s) assert_equal(stream[0]['object'], 'Ticket') assert_equal(stream[0]['type'], 'update') assert_equal(stream[1]['group_id'], ticket.group_id) assert_equal(stream[1]['o_id'], article.id) - assert_equal(stream[1]['created_by_id'], current_user.id) + assert_equal(stream[1]['created_by_id'], @current_user.id) assert_equal(stream[1]['created_at'].to_s, article.created_at.to_s) assert_equal(stream[1]['object'], 'Ticket::Article') assert_equal(stream[1]['type'], 'create') assert_equal(stream[2]['group_id'], ticket.group_id) assert_equal(stream[2]['o_id'], ticket.id) - assert_equal(stream[2]['created_by_id'], current_user.id) + assert_equal(stream[2]['created_by_id'], @current_user.id) assert_equal(stream[2]['created_at'].to_s, ticket.created_at.to_s) assert_equal(stream[2]['object'], 'Ticket') assert_equal(stream[2]['type'], 'create') assert_not(stream[3]) - stream = current_user.activity_stream(4) + stream = @current_user.activity_stream(4) assert(stream.empty?) # cleanup @@ -91,11 +91,10 @@ class ActivityStreamTest < ActiveSupport::TestCase end test 'organization' do - organization = Organization.create( name: 'some name', - updated_by_id: current_user.id, - created_by_id: current_user.id, + updated_by_id: @current_user.id, + created_by_id: @current_user.id, ) travel 100.seconds assert_equal(organization.class, Organization) @@ -107,22 +106,22 @@ class ActivityStreamTest < ActiveSupport::TestCase organization.update_attributes(name: 'some name 2 (äöüß)') # check activity_stream - stream = admin_user.activity_stream(3) + stream = @admin_user.activity_stream(3) assert_not(stream[0]['group_id']) assert_equal(stream[0]['o_id'], organization.id) - assert_equal(stream[0]['created_by_id'], current_user.id) + assert_equal(stream[0]['created_by_id'], @current_user.id) assert_equal(stream[0]['created_at'].to_s, updated_at.to_s) assert_equal(stream[0]['object'], 'Organization') assert_equal(stream[0]['type'], 'update') assert_not(stream[1]['group_id']) assert_equal(stream[1]['o_id'], organization.id) - assert_equal(stream[1]['created_by_id'], current_user.id) + assert_equal(stream[1]['created_by_id'], @current_user.id) assert_equal(stream[1]['created_at'].to_s, organization.created_at.to_s) assert_equal(stream[1]['object'], 'Organization') assert_equal(stream[1]['type'], 'create') assert_not(stream[2]) - stream = current_user.activity_stream(4) + stream = @current_user.activity_stream(4) assert(stream.empty?) # cleanup @@ -135,8 +134,8 @@ class ActivityStreamTest < ActiveSupport::TestCase login: 'someemail@example.com', email: 'someemail@example.com', firstname: 'Bob Smith II', - updated_by_id: current_user.id, - created_by_id: current_user.id, + updated_by_id: @current_user.id, + created_by_id: @current_user.id, ) assert_equal(user.class, User) user.update_attributes( @@ -145,16 +144,16 @@ class ActivityStreamTest < ActiveSupport::TestCase ) # check activity_stream - stream = admin_user.activity_stream(3) + stream = @admin_user.activity_stream(3) assert_not(stream[0]['group_id']) assert_equal(stream[0]['o_id'], user.id) - assert_equal(stream[0]['created_by_id'], current_user.id) + assert_equal(stream[0]['created_by_id'], @current_user.id) assert_equal(stream[0]['created_at'].to_s, user.created_at.to_s) assert_equal(stream[0]['object'], 'User') assert_equal(stream[0]['type'], 'create') assert_not(stream[1]) - stream = current_user.activity_stream(4) + stream = @current_user.activity_stream(4) assert(stream.empty?) # cleanup @@ -163,13 +162,12 @@ class ActivityStreamTest < ActiveSupport::TestCase end test 'user with update check true' do - user = User.create( login: 'someemail@example.com', email: 'someemail@example.com', firstname: 'Bob Smith II', - updated_by_id: current_user.id, - created_by_id: current_user.id, + updated_by_id: @current_user.id, + created_by_id: @current_user.id, ) travel 100.seconds assert_equal(user.class, User) @@ -187,22 +185,22 @@ class ActivityStreamTest < ActiveSupport::TestCase ) # check activity_stream - stream = admin_user.activity_stream(3) + stream = @admin_user.activity_stream(3) assert_not(stream[0]['group_id']) assert_equal(stream[0]['o_id'], user.id) - assert_equal(stream[0]['created_by_id'], current_user.id) + assert_equal(stream[0]['created_by_id'], @current_user.id) assert_equal(stream[0]['created_at'].to_s, updated_at.to_s) assert_equal(stream[0]['object'], 'User') assert_equal(stream[0]['type'], 'update') assert_not(stream[1]['group_id']) assert_equal(stream[1]['o_id'], user.id) - assert_equal(stream[1]['created_by_id'], current_user.id) + assert_equal(stream[1]['created_by_id'], @current_user.id) assert_equal(stream[1]['created_at'].to_s, user.created_at.to_s) assert_equal(stream[1]['object'], 'User') assert_equal(stream[1]['type'], 'create') assert_not(stream[2]) - stream = current_user.activity_stream(4) + stream = @current_user.activity_stream(4) assert(stream.empty?) # cleanup diff --git a/test/unit/cache_test.rb b/test/unit/cache_test.rb index 07152f081..37992bdaf 100644 --- a/test/unit/cache_test.rb +++ b/test/unit/cache_test.rb @@ -43,7 +43,7 @@ class CacheTest < ActiveSupport::TestCase # test 6 Cache.write('123', { key: 'some valueöäüß2' }, expires_in: 3.seconds) - sleep 5 + travel 5.seconds cache = Cache.get('123') assert_nil(cache) end diff --git a/test/unit/chat_test.rb b/test/unit/chat_test.rb index 927c921bd..fe406d23b 100644 --- a/test/unit/chat_test.rb +++ b/test/unit/chat_test.rb @@ -2,14 +2,11 @@ require 'test_helper' class ChatTest < ActiveSupport::TestCase - agent1 = nil - agent2 = nil - test 'aaa - setup' do - # create base + setup do groups = Group.all roles = Role.where( name: %w(Agent) ) - agent1 = User.create_or_update( + @agent1 = User.create_or_update( login: 'ticket-chat-agent1@example.com', firstname: 'Notification', lastname: 'Agent1', @@ -22,7 +19,7 @@ class ChatTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - agent2 = User.create_or_update( + @agent2 = User.create_or_update( login: 'ticket-chat-agent2@example.com', firstname: 'Notification', lastname: 'Agent2', @@ -35,15 +32,16 @@ class ChatTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - end - - test 'default test' do Chat.delete_all Chat::Session.delete_all Chat::Message.delete_all Chat::Agent.delete_all Setting.set('chat', false) + end + + test 'default test' do + chat = Chat.create_or_update( name: 'default', max_queue: 5, @@ -55,14 +53,14 @@ class ChatTest < ActiveSupport::TestCase # check if feature is disabled assert_equal('chat_disabled', chat.customer_state[:state]) - assert_equal('chat_disabled', Chat.agent_state(agent1.id)[:state]) + assert_equal('chat_disabled', Chat.agent_state(@agent1.id)[:state]) Setting.set('chat', true) # check customer state assert_equal('offline', chat.customer_state[:state]) # check agent state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(0, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -74,15 +72,15 @@ class ChatTest < ActiveSupport::TestCase chat_agent1 = Chat::Agent.create_or_update( active: true, concurrent: 4, - updated_by_id: agent1.id, - created_by_id: agent1.id, + updated_by_id: @agent1.id, + created_by_id: @agent1.id, ) # check customer state assert_equal('online', chat.customer_state[:state]) # check agent state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(0, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -93,7 +91,7 @@ class ChatTest < ActiveSupport::TestCase # start session chat_session1 = Chat::Session.create( chat_id: chat.id, - user_id: agent1.id, + user_id: @agent1.id, ) assert(chat_session1.session_id) @@ -101,7 +99,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal('online', chat.customer_state[:state]) # check agent state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(1, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -113,15 +111,15 @@ class ChatTest < ActiveSupport::TestCase chat_agent2 = Chat::Agent.create_or_update( active: true, concurrent: 2, - updated_by_id: agent2.id, - created_by_id: agent2.id, + updated_by_id: @agent2.id, + created_by_id: @agent2.id, ) # check customer state assert_equal('online', chat.customer_state[:state]) # check agent1 state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(1, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -130,7 +128,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal(true, agent_state[:active]) # check agent2 state - agent_state = Chat.agent_state_with_sessions(agent2.id) + agent_state = Chat.agent_state_with_sessions(@agent2.id) assert_equal(1, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -147,7 +145,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal('online', chat.customer_state[:state]) # check agent1 state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(2, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -156,7 +154,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal(true, agent_state[:active]) # check agent2 state - agent_state = Chat.agent_state_with_sessions(agent2.id) + agent_state = Chat.agent_state_with_sessions(@agent2.id) assert_equal(2, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -182,7 +180,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal('no_seats_available', chat.customer_state[:state]) # check agent1 state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(6, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -191,7 +189,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal(true, agent_state[:active]) # check agent2 state - agent_state = Chat.agent_state_with_sessions(agent2.id) + agent_state = Chat.agent_state_with_sessions(@agent2.id) assert_equal(6, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -199,26 +197,26 @@ class ChatTest < ActiveSupport::TestCase assert_equal(6, agent_state[:seads_total]) assert_equal(true, agent_state[:active]) - chat_session6.user_id = agent1.id + chat_session6.user_id = @agent1.id chat_session6.state = 'running' chat_session6.save Chat::Message.create( chat_session_id: chat_session6.id, content: 'message 1', - created_by_id: agent1.id, + created_by_id: @agent1.id, ) travel 1.second Chat::Message.create( chat_session_id: chat_session6.id, content: 'message 2', - created_by_id: agent1.id, + created_by_id: @agent1.id, ) travel 1.second Chat::Message.create( chat_session_id: chat_session6.id, content: 'message 3', - created_by_id: agent1.id, + created_by_id: @agent1.id, ) travel 1.second Chat::Message.create( @@ -245,12 +243,12 @@ class ChatTest < ActiveSupport::TestCase assert_nil(customer_state[:agent][:avatar]) # check agent1 state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(5, agent_state[:waiting_chat_count]) assert_equal(1, agent_state[:running_chat_count]) assert_equal(Array, agent_state[:active_sessions].class) assert_equal(chat.id, agent_state[:active_sessions][0]['chat_id']) - assert_equal(agent1.id, agent_state[:active_sessions][0]['user_id']) + assert_equal(@agent1.id, agent_state[:active_sessions][0]['user_id']) assert(agent_state[:active_sessions][0]['messages']) assert_equal(Array, agent_state[:active_sessions][0]['messages'].class) assert_equal('message 1', agent_state[:active_sessions][0]['messages'][0]['content']) @@ -262,7 +260,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal(true, agent_state[:active]) # check agent2 state - agent_state = Chat.agent_state_with_sessions(agent2.id) + agent_state = Chat.agent_state_with_sessions(@agent2.id) assert_equal(5, agent_state[:waiting_chat_count]) assert_equal(1, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -278,12 +276,12 @@ class ChatTest < ActiveSupport::TestCase assert_equal(5, chat.customer_state[:queue]) # check agent1 state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(5, agent_state[:waiting_chat_count]) assert_equal(1, agent_state[:running_chat_count]) assert_equal(Array, agent_state[:active_sessions].class) assert_equal(chat.id, agent_state[:active_sessions][0]['chat_id']) - assert_equal(agent1.id, agent_state[:active_sessions][0]['user_id']) + assert_equal(@agent1.id, agent_state[:active_sessions][0]['user_id']) assert(agent_state[:active_sessions][0]['messages']) assert_equal(Array, agent_state[:active_sessions][0]['messages'].class) assert_equal('message 1', agent_state[:active_sessions][0]['messages'][0]['content']) @@ -295,7 +293,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal(true, agent_state[:active]) # check agent2 state - agent_state = Chat.agent_state_with_sessions(agent2.id) + agent_state = Chat.agent_state_with_sessions(@agent2.id) assert_equal(5, agent_state[:waiting_chat_count]) assert_equal(1, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -311,7 +309,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal(5, chat.customer_state[:queue]) # check agent1 state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(5, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -320,7 +318,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal(true, agent_state[:active]) # check agent2 state - agent_state = Chat.agent_state_with_sessions(agent2.id) + agent_state = Chat.agent_state_with_sessions(@agent2.id) assert_equal(5, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -335,7 +333,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal('online', chat.customer_state[:state]) # check agent1 state - agent_state = Chat.agent_state_with_sessions(agent1.id) + agent_state = Chat.agent_state_with_sessions(@agent1.id) assert_equal(3, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) @@ -344,7 +342,7 @@ class ChatTest < ActiveSupport::TestCase assert_equal(true, agent_state[:active]) # check agent2 state - agent_state = Chat.agent_state_with_sessions(agent2.id) + agent_state = Chat.agent_state_with_sessions(@agent2.id) assert_equal(3, agent_state[:waiting_chat_count]) assert_equal(0, agent_state[:running_chat_count]) assert_equal([], agent_state[:active_sessions]) diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb index b5106c40b..f30c37588 100644 --- a/test/unit/online_notifiaction_test.rb +++ b/test/unit/online_notifiaction_test.rb @@ -2,18 +2,15 @@ require 'test_helper' class OnlineNotificationTest < ActiveSupport::TestCase - group = nil - agent_user1 = nil - agent_user2 = nil - customer_user = nil - test 'aaa - setup' do - role = Role.lookup(name: 'Agent') - group = Group.create_or_update( + + setup do + role = Role.lookup(name: 'Agent') + @group = Group.create_or_update( name: 'OnlineNotificationTest', updated_by_id: 1, created_by_id: 1 ) - agent_user1 = User.create_or_update( + @agent_user1 = User.create_or_update( login: 'agent_online_notify1', firstname: 'Bob', lastname: 'Smith', @@ -21,11 +18,11 @@ class OnlineNotificationTest < ActiveSupport::TestCase password: 'some_pass', active: true, role_ids: [role.id], - group_ids: [group.id], + group_ids: [@group.id], updated_by_id: 1, created_by_id: 1 ) - agent_user2 = User.create_or_update( + @agent_user2 = User.create_or_update( login: 'agent_online_notify2', firstname: 'Bob', lastname: 'Smith', @@ -33,11 +30,11 @@ class OnlineNotificationTest < ActiveSupport::TestCase password: 'some_pass', active: true, role_ids: [role.id], - group_ids: [group.id], + group_ids: [@group.id], updated_by_id: 1, created_by_id: 1 ) - customer_user = User.lookup(email: 'nicole.braun@zammad.org') + @customer_user = User.lookup(email: 'nicole.braun@zammad.org') end test 'ticket notification' do @@ -46,19 +43,19 @@ class OnlineNotificationTest < ActiveSupport::TestCase # case #1 ticket1 = Ticket.create( - group: group, - customer_id: customer_user.id, + group: @group, + customer_id: @customer_user.id, owner_id: User.lookup(login: '-').id, title: 'Unit Test 1 (äöüß)!', state_id: Ticket::State.lookup(name: 'closed').id, priority_id: Ticket::Priority.lookup(name: '2 normal').id, - updated_by_id: agent_user1.id, - created_by_id: agent_user1.id, + updated_by_id: @agent_user1.id, + created_by_id: @agent_user1.id, ) article1 = Ticket::Article.create( ticket_id: ticket1.id, - updated_by_id: agent_user1.id, - created_by_id: agent_user1.id, + updated_by_id: @agent_user1.id, + created_by_id: @agent_user1.id, type_id: Ticket::Article::Type.lookup(name: 'phone').id, sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id, from: 'Unit Test ', @@ -76,16 +73,16 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already closed assert(OnlineNotification.all_seen?('Ticket', ticket1.id)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket1.id, 'create', agent_user1, false)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket1.id, 'create', agent_user1, true)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket1.id, 'create', agent_user1, false)) - assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket1.id, 'create', agent_user1, true)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket1.id, 'create', @agent_user1, false)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket1.id, 'create', @agent_user1, true)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'create', @agent_user1, false)) + assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'create', @agent_user1, true)) ticket1.update_attributes( title: 'Unit Test 1 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'open').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, - updated_by_id: customer_user.id, + updated_by_id: @customer_user.id, ) # execute object transaction @@ -94,26 +91,26 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already open assert(!OnlineNotification.all_seen?('Ticket', ticket1.id)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket1.id, 'update', customer_user, true)) - assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket1.id, 'update', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket1.id, 'update', customer_user, true)) - assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket1.id, 'update', customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket1.id, 'update', @customer_user, true)) + assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket1.id, 'update', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'update', @customer_user, true)) + assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'update', @customer_user, false)) # case #2 ticket2 = Ticket.create( - group: group, - customer_id: customer_user.id, - owner_id: agent_user1.id, + group: @group, + customer_id: @customer_user.id, + owner_id: @agent_user1.id, title: 'Unit Test 1 (äöüß)!', state_id: Ticket::State.lookup(name: 'closed').id, priority_id: Ticket::Priority.lookup(name: '2 normal').id, - updated_by_id: customer_user.id, - created_by_id: customer_user.id, + updated_by_id: @customer_user.id, + created_by_id: @customer_user.id, ) article2 = Ticket::Article.create( ticket_id: ticket2.id, - updated_by_id: customer_user.id, - created_by_id: customer_user.id, + updated_by_id: @customer_user.id, + created_by_id: @customer_user.id, type_id: Ticket::Article::Type.lookup(name: 'phone').id, sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id, from: 'Unit Test ', @@ -131,16 +128,16 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already closed assert(!OnlineNotification.all_seen?('Ticket', ticket2.id)) - assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket2.id, 'create', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket2.id, 'create', customer_user, true)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket2.id, 'create', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket2.id, 'create', customer_user, true)) + assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket2.id, 'create', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket2.id, 'create', @customer_user, true)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'create', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'create', @customer_user, true)) ticket2.update_attributes( title: 'Unit Test 1 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'open').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, - updated_by_id: customer_user.id, + updated_by_id: @customer_user.id, ) # execute object transaction @@ -149,26 +146,26 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already open assert(!OnlineNotification.all_seen?('Ticket', ticket2.id)) - assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket2.id, 'update', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket2.id, 'update', customer_user, true)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket2.id, 'update', customer_user, true)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket2.id, 'update', customer_user, false)) + assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket2.id, 'update', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket2.id, 'update', @customer_user, true)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'update', @customer_user, true)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'update', @customer_user, false)) # case #3 ticket3 = Ticket.create( - group: group, - customer_id: customer_user.id, + group: @group, + customer_id: @customer_user.id, owner_id: User.lookup(login: '-').id, title: 'Unit Test 2 (äöüß)!', state_id: Ticket::State.lookup(name: 'new').id, priority_id: Ticket::Priority.lookup(name: '2 normal').id, - updated_by_id: agent_user1.id, - created_by_id: agent_user1.id, + updated_by_id: @agent_user1.id, + created_by_id: @agent_user1.id, ) article3 = Ticket::Article.create( ticket_id: ticket3.id, - updated_by_id: agent_user1.id, - created_by_id: agent_user1.id, + updated_by_id: @agent_user1.id, + created_by_id: @agent_user1.id, type_id: Ticket::Article::Type.lookup(name: 'phone').id, sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id, from: 'Unit Test ', @@ -185,16 +182,16 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already new assert(!OnlineNotification.all_seen?('Ticket', ticket3.id)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'create', agent_user1, false)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'create', agent_user1, true)) - assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'create', agent_user1, false)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'create', agent_user1, true)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'create', @agent_user1, false)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'create', @agent_user1, true)) + assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'create', @agent_user1, false)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'create', @agent_user1, true)) ticket3.update_attributes( title: 'Unit Test 2 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'closed').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, - updated_by_id: customer_user.id, + updated_by_id: @customer_user.id, ) # execute object transaction @@ -203,17 +200,17 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already closed assert(OnlineNotification.all_seen?('Ticket', ticket3.id)) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, agent_user1, 'update')) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, agent_user2, 'update')) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'update', customer_user, false)) - assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'update', customer_user, true)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'update', customer_user, false)) - assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'update', customer_user, true)) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent_user1, 'update')) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent_user2, 'update')) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'update', @customer_user, false)) + assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'update', @customer_user, true)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'update', @customer_user, false)) + assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'update', @customer_user, true)) article3 = Ticket::Article.create( ticket_id: ticket3.id, - updated_by_id: customer_user.id, - created_by_id: customer_user.id, + updated_by_id: @customer_user.id, + created_by_id: @customer_user.id, type_id: Ticket::Article::Type.lookup(name: 'phone').id, sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id, from: 'Unit Test ', @@ -227,28 +224,28 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already closed but an follow up arrived later assert(!OnlineNotification.all_seen?('Ticket', ticket3.id)) - assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'update', customer_user, false)) - assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket3.id, 'update', customer_user, true)) - assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'update', customer_user, false)) - assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket3.id, 'update', customer_user, true)) - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent_user1, 'update')) - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent_user2, 'update')) + assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'update', @customer_user, false)) + assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket3.id, 'update', @customer_user, true)) + assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'update', @customer_user, false)) + assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'update', @customer_user, true)) + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent_user1, 'update')) + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent_user2, 'update')) # case #4 ticket4 = Ticket.create( - group: group, - customer_id: customer_user.id, - owner_id: agent_user1.id, + group: @group, + customer_id: @customer_user.id, + owner_id: @agent_user1.id, title: 'Unit Test 3 (äöüß)!', state_id: Ticket::State.lookup(name: 'new').id, priority_id: Ticket::Priority.lookup(name: '2 normal').id, - updated_by_id: customer_user.id, - created_by_id: customer_user.id, + updated_by_id: @customer_user.id, + created_by_id: @customer_user.id, ) article4 = Ticket::Article.create( ticket_id: ticket4.id, - updated_by_id: customer_user.id, - created_by_id: customer_user.id, + updated_by_id: @customer_user.id, + created_by_id: @customer_user.id, type_id: Ticket::Article::Type.lookup(name: 'phone').id, sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id, from: 'Unit Test ', @@ -265,16 +262,16 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already new assert(!OnlineNotification.all_seen?('Ticket', ticket4.id)) - assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket4.id, 'create', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket4.id, 'create', customer_user, true)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket4.id, 'create', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket4.id, 'create', customer_user, true)) + assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket4.id, 'create', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket4.id, 'create', @customer_user, true)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'create', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'create', @customer_user, true)) ticket4.update_attributes( title: 'Unit Test 3 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'open').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, - updated_by_id: customer_user.id, + updated_by_id: @customer_user.id, ) # execute object transaction @@ -283,26 +280,26 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already open assert(!OnlineNotification.all_seen?('Ticket', ticket4.id)) - assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket4.id, 'update', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket4.id, 'update', customer_user, true)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket4.id, 'update', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket4.id, 'update', customer_user, true)) + assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket4.id, 'update', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket4.id, 'update', @customer_user, true)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'update', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'update', @customer_user, true)) # case #5 ticket5 = Ticket.create( - group: group, - customer_id: customer_user.id, + group: @group, + customer_id: @customer_user.id, owner_id: User.lookup(login: '-').id, title: 'Unit Test 4 (äöüß)!', state_id: Ticket::State.lookup(name: 'new').id, priority_id: Ticket::Priority.lookup( name: '2 normal').id, - updated_by_id: agent_user1.id, - created_by_id: agent_user1.id, + updated_by_id: @agent_user1.id, + created_by_id: @agent_user1.id, ) article5 = Ticket::Article.create( ticket_id: ticket5.id, - updated_by_id: agent_user1.id, - created_by_id: agent_user1.id, + updated_by_id: @agent_user1.id, + created_by_id: @agent_user1.id, type_id: Ticket::Article::Type.lookup(name: 'phone').id, sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id, from: 'Unit Test ', @@ -319,16 +316,16 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already new assert(!OnlineNotification.all_seen?('Ticket', ticket5.id)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket5.id, 'create', agent_user1, true)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket5.id, 'create', agent_user1, false)) - assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket5.id, 'create', agent_user1, false)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket5.id, 'create', agent_user1, true)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket5.id, 'create', @agent_user1, true)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket5.id, 'create', @agent_user1, false)) + assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'create', @agent_user1, false)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'create', @agent_user1, true)) ticket5.update_attributes( title: 'Unit Test 4 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'open').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, - updated_by_id: customer_user.id, + updated_by_id: @customer_user.id, ) # execute object transaction @@ -337,10 +334,10 @@ class OnlineNotificationTest < ActiveSupport::TestCase # because it's already open assert(!OnlineNotification.all_seen?('Ticket', ticket5.id)) - assert(OnlineNotification.exists?(agent_user1, 'Ticket', ticket5.id, 'update', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user1, 'Ticket', ticket5.id, 'update', customer_user, true)) - assert(OnlineNotification.exists?(agent_user2, 'Ticket', ticket5.id, 'update', customer_user, false)) - assert(!OnlineNotification.exists?(agent_user2, 'Ticket', ticket5.id, 'update', customer_user, true)) + assert(OnlineNotification.exists?(@agent_user1, 'Ticket', ticket5.id, 'update', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user1, 'Ticket', ticket5.id, 'update', @customer_user, true)) + assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'update', @customer_user, false)) + assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'update', @customer_user, true)) # merge tickets - also remove notifications of merged tickets tickets[0].merge_to( @@ -374,8 +371,8 @@ class OnlineNotificationTest < ActiveSupport::TestCase test 'ticket notification item check' do ticket1 = Ticket.create( title: 'some title', - group: group, - customer_id: customer_user.id, + group: @group, + customer_id: @customer_user.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, @@ -397,96 +394,96 @@ class OnlineNotificationTest < ActiveSupport::TestCase ) assert_equal(ticket1.online_notification_seen_state, false) - assert_equal(ticket1.online_notification_seen_state(agent_user1), false) - assert_equal(ticket1.online_notification_seen_state(agent_user2), false) + assert_equal(ticket1.online_notification_seen_state(@agent_user1), false) + assert_equal(ticket1.online_notification_seen_state(@agent_user2), false) # pending reminder, just let new owner to unseed ticket1.update_attributes( - owner_id: agent_user1.id, + owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'pending reminder'), - updated_by_id: agent_user2.id, + updated_by_id: @agent_user2.id, ) assert_equal(ticket1.online_notification_seen_state, true) - assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false) - assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true) + assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false) + assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # pending reminder, just let new owner to unseed ticket1.update_attributes( owner_id: 1, state: Ticket::State.lookup(name: 'pending reminder'), - updated_by_id: agent_user2.id, + updated_by_id: @agent_user2.id, ) assert_equal(ticket1.online_notification_seen_state, true) - assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false) - assert_equal(ticket1.online_notification_seen_state(agent_user2.id), false) + assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false) + assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), false) # pending reminder, self done, all to unseed ticket1.update_attributes( - owner_id: agent_user1.id, + owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'pending reminder'), - updated_by_id: agent_user1.id, + updated_by_id: @agent_user1.id, ) assert_equal(ticket1.online_notification_seen_state, true) - assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true) - assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true) + assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), true) + assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # pending close, all to unseen ticket1.update_attributes( - owner_id: agent_user1.id, + owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'pending close'), - updated_by_id: agent_user2.id, + updated_by_id: @agent_user2.id, ) assert_equal(ticket1.online_notification_seen_state, true) - assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false) - assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true) + assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false) + assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # to open, all to seen ticket1.update_attributes( - owner_id: agent_user1.id, + owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'open'), - updated_by_id: agent_user2.id, + updated_by_id: @agent_user2.id, ) assert_equal(ticket1.online_notification_seen_state, false) - assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false) - assert_equal(ticket1.online_notification_seen_state(agent_user2.id), false) + assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false) + assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), false) # to closed, all only others to seen ticket1.update_attributes( - owner_id: agent_user1.id, + owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'closed'), - updated_by_id: agent_user2.id, + updated_by_id: @agent_user2.id, ) assert_equal(ticket1.online_notification_seen_state, true) - assert_equal(ticket1.online_notification_seen_state(agent_user1.id), false) - assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true) + assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), false) + assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # to closed by owner self, all to seen ticket1.update_attributes( - owner_id: agent_user1.id, + owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'closed'), - updated_by_id: agent_user1.id, + updated_by_id: @agent_user1.id, ) assert_equal(ticket1.online_notification_seen_state, true) - assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true) - assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true) + assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), true) + assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # to closed by owner self, all to seen ticket1.update_attributes( - owner_id: agent_user1.id, + owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'merged'), - updated_by_id: agent_user2.id, + updated_by_id: @agent_user2.id, ) assert_equal(ticket1.online_notification_seen_state, true) - assert_equal(ticket1.online_notification_seen_state(agent_user1.id), true) - assert_equal(ticket1.online_notification_seen_state(agent_user2.id), true) + assert_equal(ticket1.online_notification_seen_state(@agent_user1.id), true) + assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) end @@ -496,7 +493,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase object: 'Ticket', o_id: 123, seen: false, - user_id: agent_user1.id, + user_id: @agent_user1.id, created_by_id: 1, updated_by_id: 1, created_at: Time.zone.now - 10.months, @@ -507,7 +504,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase object: 'Ticket', o_id: 123, seen: true, - user_id: agent_user1.id, + user_id: @agent_user1.id, created_by_id: 1, updated_by_id: 1, created_at: Time.zone.now - 10.months, @@ -518,7 +515,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase object: 'Ticket', o_id: 123, seen: false, - user_id: agent_user1.id, + user_id: @agent_user1.id, created_by_id: 1, updated_by_id: 1, created_at: Time.zone.now - 2.days, @@ -529,9 +526,9 @@ class OnlineNotificationTest < ActiveSupport::TestCase object: 'Ticket', o_id: 123, seen: true, - user_id: agent_user1.id, - created_by_id: agent_user1.id, - updated_by_id: agent_user1.id, + user_id: @agent_user1.id, + created_by_id: @agent_user1.id, + updated_by_id: @agent_user1.id, created_at: Time.zone.now - 2.days, updated_at: Time.zone.now - 2.days, ) @@ -540,9 +537,9 @@ class OnlineNotificationTest < ActiveSupport::TestCase object: 'Ticket', o_id: 123, seen: true, - user_id: agent_user1.id, - created_by_id: agent_user2.id, - updated_by_id: agent_user2.id, + user_id: @agent_user1.id, + created_by_id: @agent_user2.id, + updated_by_id: @agent_user2.id, created_at: Time.zone.now - 2.days, updated_at: Time.zone.now - 2.days, ) @@ -551,9 +548,9 @@ class OnlineNotificationTest < ActiveSupport::TestCase object: 'Ticket', o_id: 123, seen: true, - user_id: agent_user1.id, - created_by_id: agent_user1.id, - updated_by_id: agent_user1.id, + user_id: @agent_user1.id, + created_by_id: @agent_user1.id, + updated_by_id: @agent_user1.id, created_at: Time.zone.now - 5.minutes, updated_at: Time.zone.now - 5.minutes, ) @@ -562,9 +559,9 @@ class OnlineNotificationTest < ActiveSupport::TestCase object: 'Ticket', o_id: 123, seen: true, - user_id: agent_user1.id, - created_by_id: agent_user2.id, - updated_by_id: agent_user2.id, + user_id: @agent_user1.id, + created_by_id: @agent_user2.id, + updated_by_id: @agent_user2.id, created_at: Time.zone.now - 5.minutes, updated_at: Time.zone.now - 5.minutes, ) diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index 58d314716..3e239a2df 100644 --- a/test/unit/session_basic_test.rb +++ b/test/unit/session_basic_test.rb @@ -2,11 +2,11 @@ require 'test_helper' class SessionBasicTest < ActiveSupport::TestCase - test 'aaa - setup' do + setup do user = User.lookup(id: 1) roles = Role.where(name: %w(Agent Admin)) user.roles = roles - user.save + user.save! end test 'b cache' do diff --git a/test/unit/session_collections_test.rb b/test/unit/session_collections_test.rb index d6883d715..08b5b61d5 100644 --- a/test/unit/session_collections_test.rb +++ b/test/unit/session_collections_test.rb @@ -99,7 +99,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase # next check should be empty result1 = collection_client1.push assert(result1.empty?, 'check collections - recall') - sleep 0.4 + travel 0.4.seconds result2 = collection_client2.push assert(result2.empty?, 'check collections - recall') result3 = collection_client3.push @@ -108,13 +108,13 @@ class SessionCollectionsTest < ActiveSupport::TestCase # change collection group = Group.first group.touch - travel 3.seconds + travel 4.seconds # get whole collections result1 = collection_client1.push assert(result1, 'check collections - after touch') assert(check_if_collection_exists(result1, :Group), 'check collections - after touch') - sleep 0.1 + travel 0.1.seconds result2 = collection_client2.push assert(result2, 'check collections - after touch') assert(check_if_collection_exists(result2, :Group), 'check collections - after touch') @@ -123,7 +123,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase assert(check_if_collection_exists(result3, :Group), 'check collections - after touch') # next check should be empty - sleep 0.5 + travel 0.5.seconds result1 = collection_client1.push assert(result1.empty?, 'check collections - recall') result2 = collection_client2.push diff --git a/test/unit/session_enhanced_test.rb b/test/unit/session_enhanced_test.rb index f191b5f40..9ce8c0ece 100644 --- a/test/unit/session_enhanced_test.rb +++ b/test/unit/session_enhanced_test.rb @@ -47,9 +47,9 @@ class SessionEnhancedTest < ActiveSupport::TestCase agent3.save # create sessions - client_id1 = '1234' - client_id2 = '123456' - client_id3 = 'abc' + client_id1 = 'a1234' + client_id2 = 'a123456' + client_id3 = 'aabc' Sessions.destroy(client_id1) Sessions.destroy(client_id2) Sessions.destroy(client_id3) @@ -145,8 +145,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase jobs = Thread.new { Sessions.jobs } - sleep 3 - #jobs.join + sleep 6 # check client threads assert(Sessions.thread_client_exists?(client_id1), 'check if client is running') @@ -154,8 +153,9 @@ class SessionEnhancedTest < ActiveSupport::TestCase assert(Sessions.thread_client_exists?(client_id3), 'check if client is running') # check if session still exists after idle cleanup - sleep 4 + travel 10.seconds client_ids = Sessions.destroy_idle_sessions(2) + travel 2.seconds # check client sessions assert(!Sessions.session_exists?(client_id1), 'check if session is removed') @@ -171,7 +171,8 @@ class SessionEnhancedTest < ActiveSupport::TestCase # exit jobs jobs.exit - + jobs.join + travel_back end test 'b check client and backends' do @@ -196,7 +197,6 @@ class SessionEnhancedTest < ActiveSupport::TestCase roles: roles, groups: groups, ) - agent1.roles = roles agent1.save agent2 = User.create_or_update( login: 'session-agent-2', @@ -209,16 +209,29 @@ class SessionEnhancedTest < ActiveSupport::TestCase roles: roles, groups: groups, ) - agent2.roles = roles agent2.save + agent3 = User.create_or_update( + login: 'session-agent-3', + firstname: 'Session', + lastname: 'Agent 3', + email: 'session-agent3@example.com', + password: 'agentpw', + active: true, + organization: organization, + roles: roles, + groups: groups, + ) + agent3.save # create sessions - client_id1_0 = '1234-1' - client_id1_1 = '1234-2' - client_id2 = '123456' + client_id1_0 = 'b1234-1' + client_id1_1 = 'b1234-2' + client_id2 = 'b123456' + client_id3 = 'c123456' Sessions.destroy(client_id1_0) Sessions.destroy(client_id1_1) Sessions.destroy(client_id2) + Sessions.destroy(client_id3) # start jobs jobs = Thread.new { @@ -230,11 +243,16 @@ class SessionEnhancedTest < ActiveSupport::TestCase Sessions.create(client_id1_1, agent1.attributes, { type: 'websocket' }) sleep 3.2 Sessions.create(client_id2, agent2.attributes, { type: 'ajax' }) + sleep 3.2 + Sessions.create(client_id3, agent3.attributes, { type: 'websocket' }) # check if session exists assert(Sessions.session_exists?(client_id1_0), 'check if session exists') assert(Sessions.session_exists?(client_id1_1), 'check if session exists') assert(Sessions.session_exists?(client_id2), 'check if session exists') + assert(Sessions.session_exists?(client_id3), 'check if session exists') + + travel 8.seconds sleep 8 # check collections @@ -245,6 +263,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase assert_if_collection_reset_message_exists(client_id1_0, collections, 'init') assert_if_collection_reset_message_exists(client_id1_1, collections, 'init') assert_if_collection_reset_message_exists(client_id2, collections, 'init') + assert_if_collection_reset_message_exists(client_id3, collections, 'init') collections = { 'Group' => nil, @@ -253,7 +272,9 @@ class SessionEnhancedTest < ActiveSupport::TestCase assert_if_collection_reset_message_exists(client_id1_0, collections, 'init2') assert_if_collection_reset_message_exists(client_id1_1, collections, 'init2') assert_if_collection_reset_message_exists(client_id2, collections, 'init2') + assert_if_collection_reset_message_exists(client_id3, collections, 'init2') + travel 8.seconds sleep 8 collections = { @@ -263,12 +284,14 @@ class SessionEnhancedTest < ActiveSupport::TestCase assert_if_collection_reset_message_exists(client_id1_0, collections, 'init3') assert_if_collection_reset_message_exists(client_id1_1, collections, 'init3') assert_if_collection_reset_message_exists(client_id2, collections, 'init3') + assert_if_collection_reset_message_exists(client_id3, collections, 'init3') # change collection group = Group.first group.touch - sleep 10 + travel 12.seconds + sleep 12 # check collections collections = { @@ -278,16 +301,23 @@ class SessionEnhancedTest < ActiveSupport::TestCase assert_if_collection_reset_message_exists(client_id1_0, collections, 'update') assert_if_collection_reset_message_exists(client_id1_1, collections, 'update') assert_if_collection_reset_message_exists(client_id2, collections, 'update') + assert_if_collection_reset_message_exists(client_id3, collections, 'update') # check if session still exists after idle cleanup - sleep 4 - client_ids = Sessions.destroy_idle_sessions(3) + travel 10.seconds + client_ids = Sessions.destroy_idle_sessions(2) + travel 2.seconds # check client sessions assert(!Sessions.session_exists?(client_id1_0), 'check if session is removed') assert(!Sessions.session_exists?(client_id1_1), 'check if session is removed') assert(!Sessions.session_exists?(client_id2), 'check if session is removed') + assert(!Sessions.session_exists?(client_id3), 'check if session is removed') + # exit jobs + jobs.exit + jobs.join + travel_back end def assert_if_collection_reset_message_exists(client_id, collections_orig, type) diff --git a/test/unit/ticket_customer_organization_update_test.rb b/test/unit/ticket_customer_organization_update_test.rb index a13af3b34..8327048e9 100644 --- a/test/unit/ticket_customer_organization_update_test.rb +++ b/test/unit/ticket_customer_organization_update_test.rb @@ -2,15 +2,11 @@ require 'test_helper' class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase - agent1 = nil - organization1 = nil - customer1 = nil - test 'aaa - setup' do - # create base + setup do groups = Group.where(name: 'Users') roles = Role.where(name: 'Agent') - agent1 = User.create_or_update( + @agent1 = User.create_or_update( login: 'ticket-customer-organization-update-agent1@example.com', firstname: 'Notification', lastname: 'Agent1', @@ -24,20 +20,20 @@ class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase created_by_id: 1, ) roles = Role.where(name: 'Customer') - organization1 = Organization.create_if_not_exists( + @organization1 = Organization.create_if_not_exists( name: 'Customer Organization Update', updated_at: '2015-02-05 16:37:00', updated_by_id: 1, created_by_id: 1, ) - customer1 = User.create_or_update( + @customer1 = User.create_or_update( login: 'ticket-customer-organization-update-customer1@example.com', firstname: 'Notification', lastname: 'Customer1', email: 'ticket-customer-organization-update-customer1@example.com', password: 'customerpw', active: true, - organization_id: organization1.id, + organization_id: @organization1.id, roles: roles, updated_at: '2015-02-05 16:37:00', updated_by_id: 1, @@ -50,32 +46,32 @@ class TicketCustomerOrganizationUpdateTest < ActiveSupport::TestCase ticket = Ticket.create( title: "some title1\n äöüß", group: Group.lookup(name: 'Users'), - customer_id: customer1.id, - owner_id: agent1.id, + customer_id: @customer1.id, + owner_id: @agent1.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) assert(ticket, 'ticket created') - assert_equal(customer1.id, ticket.customer.id) - assert_equal(organization1.id, ticket.organization.id) + assert_equal(@customer1.id, ticket.customer.id) + assert_equal(@organization1.id, ticket.organization.id) # update customer organization - customer1.organization_id = nil - customer1.save + @customer1.organization_id = nil + @customer1.save! # verify ticket - ticket = Ticket.find(ticket.id) + ticket.reload assert_nil(ticket.organization_id) # update customer organization - customer1.organization_id = organization1.id - customer1.save + @customer1.organization_id = @organization1.id + @customer1.save! # verify ticket - ticket = Ticket.find(ticket.id) - assert_equal(organization1.id, ticket.organization_id) + ticket.reload + assert_equal(@organization1.id, ticket.organization_id) ticket.destroy end diff --git a/test/unit/ticket_notification_test.rb b/test/unit/ticket_notification_test.rb index 108e45de7..9d6ae786c 100644 --- a/test/unit/ticket_notification_test.rb +++ b/test/unit/ticket_notification_test.rb @@ -2,10 +2,7 @@ require 'test_helper' class TicketNotificationTest < ActiveSupport::TestCase - agent1 = nil - agent2 = nil - customer = nil - test 'aaa - setup' do + setup do Trigger.create_or_update( name: 'auto reply - new ticket', condition: { @@ -45,7 +42,7 @@ class TicketNotificationTest < ActiveSupport::TestCase updated_by_id: 1, ) - # create agent1 & agent2 + # create @agent1 & @agent2 Group.create_or_update( name: 'TicketNotificationTest', updated_by_id: 1, @@ -53,7 +50,7 @@ class TicketNotificationTest < ActiveSupport::TestCase ) groups = Group.where(name: 'TicketNotificationTest') roles = Role.where(name: 'Agent') - agent1 = User.create_or_update( + @agent1 = User.create_or_update( login: 'ticket-notification-agent1@example.com', firstname: 'Notification', lastname: 'Agent1', @@ -68,7 +65,7 @@ class TicketNotificationTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - agent2 = User.create_or_update( + @agent2 = User.create_or_update( login: 'ticket-notification-agent2@example.com', firstname: 'Notification', lastname: 'Agent2', @@ -90,9 +87,9 @@ class TicketNotificationTest < ActiveSupport::TestCase created_by_id: 1 ) - # create customer + # create @customer roles = Role.where(name: 'Customer') - customer = User.create_or_update( + @customer = User.create_or_update( login: 'ticket-notification-customer@example.com', firstname: 'Notification', lastname: 'Customer', @@ -110,16 +107,16 @@ class TicketNotificationTest < ActiveSupport::TestCase # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: 'some notification test 1', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, + customer: @customer, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: agent1.id, - created_by_id: agent1.id, + updated_by_id: @agent1.id, + created_by_id: @agent1.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -129,8 +126,8 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: agent1.id, - created_by_id: agent1.id, + updated_by_id: @agent1.id, + created_by_id: @agent1.id, ) assert(ticket1) @@ -138,22 +135,22 @@ class TicketNotificationTest < ActiveSupport::TestCase Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + # verify notifications to @agent1 + @agent2 + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id) # create ticket in group ApplicationHandleInfo.current = 'application_server' - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: 'some notification test 2', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, + customer: @customer, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: agent1.id, - created_by_id: agent1.id, + updated_by_id: @agent1.id, + created_by_id: @agent1.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -163,8 +160,8 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: agent1.id, - created_by_id: agent1.id, + updated_by_id: @agent1.id, + created_by_id: @agent1.id, ) assert(ticket1) @@ -172,25 +169,25 @@ class TicketNotificationTest < ActiveSupport::TestCase Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + # verify notifications to @agent1 + @agent2 + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id) end test 'ticket notification - simple' do # create ticket in group ApplicationHandleInfo.current = 'application_server' - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: 'some notification test 3', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, + customer: @customer, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -200,8 +197,8 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) assert(ticket1, 'ticket created - ticket notification simple') @@ -209,25 +206,25 @@ class TicketNotificationTest < ActiveSupport::TestCase Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + # verify notifications to @agent1 + @agent2 + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id) # update ticket attributes ticket1.title = "#{ticket1.title} - #2" ticket1.priority = Ticket::Priority.lookup(name: '3 high') - ticket1.save + ticket1.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + # verify notifications to @agent1 + @agent2 + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id) + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id) # add article to ticket - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket1.id, from: 'some person', subject: 'some note', @@ -235,23 +232,23 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: true, sender: Ticket::Article::Sender.where(name: 'Agent').first, type: Ticket::Article::Type.where(name: 'note').first, - updated_by_id: agent1.id, - created_by_id: agent1.id, + updated_by_id: @agent1.id, + created_by_id: @agent1.id, ) # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to not to agent1 but to agent2 - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) - assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + # verify notifications to not to @agent1 but to @agent2 + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id) + assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id) # update ticket by user - ticket1.owner_id = agent1.id - ticket1.updated_by_id = agent1.id - ticket1.save - Ticket::Article.create( + ticket1.owner_id = @agent1.id + ticket1.updated_by_id = @agent1.id + ticket1.save! + Ticket::Article.create!( ticket_id: ticket1.id, from: 'some person', subject: 'some note', @@ -259,30 +256,30 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: true, sender: Ticket::Article::Sender.where(name: 'Agent').first, type: Ticket::Article::Type.where(name: 'note').first, - updated_by_id: agent1.id, - created_by_id: agent1.id, + updated_by_id: @agent1.id, + created_by_id: @agent1.id, ) # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to not to agent1 but to agent2 - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) - assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + # verify notifications to not to @agent1 but to @agent2 + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id) + assert_equal(3, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id) - # create ticket with agent1 as owner - ticket2 = Ticket.create( + # create ticket with @agent1 as owner + ticket2 = Ticket.create!( title: 'some notification test 4', group: Group.lookup(name: 'TicketNotificationTest'), customer_id: 2, - owner_id: agent1.id, + owner_id: @agent1.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: agent1.id, - created_by_id: agent1.id, + updated_by_id: @agent1.id, + created_by_id: @agent1.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket2.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -292,8 +289,8 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Agent').first, type: Ticket::Article::Type.where(name: 'phone').first, - updated_by_id: agent1.id, - created_by_id: agent1.id, + updated_by_id: @agent1.id, + created_by_id: @agent1.id, ) # execute object transaction @@ -302,49 +299,49 @@ class TicketNotificationTest < ActiveSupport::TestCase assert(ticket2, 'ticket created') # verify notifications to no one - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id) # update ticket ticket2.title = "#{ticket2.title} - #2" - ticket2.updated_by_id = agent1.id + ticket2.updated_by_id = @agent1.id ticket2.priority = Ticket::Priority.lookup(name: '3 high') - ticket2.save + ticket2.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) # verify notifications to none - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id) # update ticket ticket2.title = "#{ticket2.title} - #3" - ticket2.updated_by_id = agent2.id + ticket2.updated_by_id = @agent2.id ticket2.priority = Ticket::Priority.lookup(name: '2 normal') - ticket2.save + ticket2.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 and not to agent2 - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id) + # verify notifications to @agent1 and not to @agent2 + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id) - # create ticket with agent2 and agent1 as owner - ticket3 = Ticket.create( + # create ticket with @agent2 and @agent1 as owner + ticket3 = Ticket.create!( title: 'some notification test 5', group: Group.lookup(name: 'TicketNotificationTest'), customer_id: 2, - owner_id: agent1.id, + owner_id: @agent1.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: agent2.id, - created_by_id: agent2.id, + updated_by_id: @agent2.id, + created_by_id: @agent2.id, ) - article_inbound = Ticket::Article.create( + article_inbound = Ticket::Article.create!( ticket_id: ticket3.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -354,8 +351,8 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Agent').first, type: Ticket::Article::Type.where(name: 'phone').first, - updated_by_id: agent2.id, - created_by_id: agent2.id, + updated_by_id: @agent2.id, + created_by_id: @agent2.id, ) # execute object transaction @@ -363,49 +360,49 @@ class TicketNotificationTest < ActiveSupport::TestCase Scheduler.worker(true) assert(ticket3, 'ticket created') - # verify notifications to agent1 and not to agent2 - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id) + # verify notifications to @agent1 and not to @agent2 + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id) # update ticket ticket3.title = "#{ticket3.title} - #2" - ticket3.updated_by_id = agent1.id + ticket3.updated_by_id = @agent1.id ticket3.priority = Ticket::Priority.lookup(name: '3 high') - ticket3.save + ticket3.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) # verify notifications to no one - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id) # update ticket ticket3.title = "#{ticket3.title} - #3" - ticket3.updated_by_id = agent2.id + ticket3.updated_by_id = @agent2.id ticket3.priority = Ticket::Priority.lookup(name: '2 normal') - ticket3.save + ticket3.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 and not to agent2 - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id) + # verify notifications to @agent1 and not to @agent2 + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id) # update article / not notification should be sent article_inbound.internal = true - article_inbound.save + article_inbound.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications not to agent1 and not to agent2 - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id) + # verify notifications not to @agent1 and not to @agent2 + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id) delete = ticket1.destroy assert(delete, 'ticket1 destroy') @@ -421,16 +418,16 @@ class TicketNotificationTest < ActiveSupport::TestCase test 'ticket notification - no notification' do # create ticket in group - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: 'some notification test 1 - no notification', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, + customer: @customer, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -440,8 +437,8 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) assert(ticket1, 'ticket created - ticket no notification') @@ -449,42 +446,42 @@ class TicketNotificationTest < ActiveSupport::TestCase Observer::Transaction.commit(disable_notification: true) Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + # verify notifications to @agent1 + @agent2 + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id) end test 'ticket notification - z preferences tests' do - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = false - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = false - agent1.save + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = false + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = false + @agent1.save! - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true - agent2.save + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true + @agent2.save! # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: 'some notification test - z preferences tests 1', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, + customer: @customer, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -494,43 +491,43 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + # verify notifications to @agent1 + @agent2 + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id) # update ticket attributes ticket1.title = "#{ticket1.title} - #2" ticket1.priority = Ticket::Priority.lookup(name: '3 high') - ticket1.save + ticket1.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, agent1, 'email'), ticket1.id) - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, agent2, 'email'), ticket1.id) + # verify notifications to @agent1 + @agent2 + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket1, @agent1, 'email'), ticket1.id) + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket1, @agent2, 'email'), ticket1.id) # create ticket in group - ticket2 = Ticket.create( + ticket2 = Ticket.create!( title: 'some notification test - z preferences tests 2', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, - owner: agent1, + customer: @customer, + owner: @agent1, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket2.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -540,43 +537,43 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id) + # verify notifications to @agent1 + @agent2 + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id) # update ticket attributes ticket2.title = "#{ticket2.title} - #2" ticket2.priority = Ticket::Priority.lookup(name: '3 high') - ticket2.save + ticket2.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, agent1, 'email'), ticket2.id) - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, agent2, 'email'), ticket2.id) + # verify notifications to @agent1 + @agent2 + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, @agent1, 'email'), ticket2.id) + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket2, @agent2, 'email'), ticket2.id) # create ticket in group - ticket3 = Ticket.create( + ticket3 = Ticket.create!( title: 'some notification test - z preferences tests 3', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, - owner: agent2, + customer: @customer, + owner: @agent2, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket3.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -586,61 +583,61 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id) + # verify notifications to @agent1 + @agent2 + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id) # update ticket attributes ticket3.title = "#{ticket3.title} - #2" ticket3.priority = Ticket::Priority.lookup(name: '3 high') - ticket3.save + ticket3.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, agent1, 'email'), ticket3.id) - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, agent2, 'email'), ticket3.id) + # verify notifications to @agent1 + @agent2 + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket3, @agent1, 'email'), ticket3.id) + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket3, @agent2, 'email'), ticket3.id) - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true - agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'TicketNotificationTest').id.to_s] - agent1.save + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true + @agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'TicketNotificationTest').id.to_s] + @agent1.save! - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true - agent1.preferences['notification_config']['group_ids'] = ['-'] - agent2.save + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true + @agent1.preferences['notification_config']['group_ids'] = ['-'] + @agent2.save! # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' - ticket4 = Ticket.create( + ticket4 = Ticket.create!( title: 'some notification test - z preferences tests 4', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, + customer: @customer, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket4.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -650,61 +647,61 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket4, agent1, 'email'), ticket4.id) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket4, agent2, 'email'), ticket4.id) + # verify notifications to @agent1 + @agent2 + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket4, @agent1, 'email'), ticket4.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket4, @agent2, 'email'), ticket4.id) # update ticket attributes ticket4.title = "#{ticket4.title} - #2" ticket4.priority = Ticket::Priority.lookup(name: '3 high') - ticket4.save + ticket4.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket4, agent1, 'email'), ticket4.id) - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket4, agent2, 'email'), ticket4.id) + # verify notifications to @agent1 + @agent2 + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket4, @agent1, 'email'), ticket4.id) + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket4, @agent2, 'email'), ticket4.id) - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true - agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'TicketNotificationTest').id.to_s] - agent1.save + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true + @agent1.preferences['notification_config']['group_ids'] = [Group.lookup(name: 'TicketNotificationTest').id.to_s] + @agent1.save! - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true - agent2.preferences['notification_config']['group_ids'] = [99] - agent2.save + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = false + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = false + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true + @agent2.preferences['notification_config']['group_ids'] = [99] + @agent2.save! # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' - ticket5 = Ticket.create( + ticket5 = Ticket.create!( title: 'some notification test - z preferences tests 5', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, + customer: @customer, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket5.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -714,62 +711,62 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket5, agent1, 'email'), ticket5.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket5, agent2, 'email'), ticket5.id) + # verify notifications to @agent1 + @agent2 + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket5, @agent1, 'email'), ticket5.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket5, @agent2, 'email'), ticket5.id) # update ticket attributes ticket5.title = "#{ticket5.title} - #2" ticket5.priority = Ticket::Priority.lookup(name: '3 high') - ticket5.save + ticket5.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket5, agent1, 'email'), ticket5.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket5, agent2, 'email'), ticket5.id) + # verify notifications to @agent1 + @agent2 + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket5, @agent1, 'email'), ticket5.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket5, @agent2, 'email'), ticket5.id) - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true - agent1.preferences['notification_config']['group_ids'] = [999] - agent1.save + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true + @agent1.preferences['notification_config']['group_ids'] = [999] + @agent1.save! - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true - agent2.preferences['notification_config']['group_ids'] = [999] - agent2.save + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true + @agent2.preferences['notification_config']['group_ids'] = [999] + @agent2.save! # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' - ticket6 = Ticket.create( + ticket6 = Ticket.create!( title: 'some notification test - z preferences tests 6', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, - owner: agent1, + customer: @customer, + owner: @agent1, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket6.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -779,74 +776,74 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'email'), ticket6.id) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'online'), ticket6.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, agent2, 'email'), ticket6.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, agent2, 'online'), ticket6.id) + # verify notifications to @agent1 + @agent2 + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket6, @agent1, 'email'), ticket6.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket6, @agent1, 'online'), ticket6.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, @agent2, 'email'), ticket6.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, @agent2, 'online'), ticket6.id) # update ticket attributes ticket6.title = "#{ticket6.title} - #2" ticket6.priority = Ticket::Priority.lookup(name: '3 high') - ticket6.save + ticket6.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'email'), ticket6.id) - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket6, agent1, 'online'), ticket6.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, agent2, 'email'), ticket6.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, agent2, 'online'), ticket6.id) + # verify notifications to @agent1 + @agent2 + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket6, @agent1, 'email'), ticket6.id) + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket6, @agent1, 'online'), ticket6.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, @agent2, 'email'), ticket6.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket6, @agent2, 'online'), ticket6.id) - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true - agent1.preferences['notification_config']['matrix']['create']['channel']['email'] = false - agent1.preferences['notification_config']['matrix']['create']['channel']['online'] = true - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true - agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true - agent1.preferences['notification_config']['matrix']['update']['channel']['email'] = false - agent1.preferences['notification_config']['matrix']['update']['channel']['online'] = true - agent1.preferences['notification_config']['group_ids'] = [999] - agent1.save + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['create']['criteria']['no'] = true + @agent1.preferences['notification_config']['matrix']['create']['channel']['email'] = false + @agent1.preferences['notification_config']['matrix']['create']['channel']['online'] = true + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true + @agent1.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent1.preferences['notification_config']['matrix']['update']['criteria']['no'] = true + @agent1.preferences['notification_config']['matrix']['update']['channel']['email'] = false + @agent1.preferences['notification_config']['matrix']['update']['channel']['online'] = true + @agent1.preferences['notification_config']['group_ids'] = [999] + @agent1.save! - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true - agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true - agent2.preferences['notification_config']['matrix']['create']['channel']['email'] = false - agent2.preferences['notification_config']['matrix']['create']['channel']['online'] = true - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true - agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false - agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true - agent2.preferences['notification_config']['matrix']['update']['channel']['email'] = false - agent2.preferences['notification_config']['matrix']['update']['channel']['online'] = true - agent2.preferences['notification_config']['group_ids'] = [999] - agent2.save + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_me'] = true + @agent2.preferences['notification_config']['matrix']['create']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['create']['criteria']['no'] = true + @agent2.preferences['notification_config']['matrix']['create']['channel']['email'] = false + @agent2.preferences['notification_config']['matrix']['create']['channel']['online'] = true + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_me'] = true + @agent2.preferences['notification_config']['matrix']['update']['criteria']['owned_by_nobody'] = false + @agent2.preferences['notification_config']['matrix']['update']['criteria']['no'] = true + @agent2.preferences['notification_config']['matrix']['update']['channel']['email'] = false + @agent2.preferences['notification_config']['matrix']['update']['channel']['online'] = true + @agent2.preferences['notification_config']['group_ids'] = [999] + @agent2.save! # create ticket in group ApplicationHandleInfo.current = 'scheduler.postmaster' - ticket7 = Ticket.create( + ticket7 = Ticket.create!( title: 'some notification test - z preferences tests 7', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, - owner: agent1, + customer: @customer, + owner: @agent1, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket7.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -856,50 +853,50 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'email'), ticket7.id) - assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'online'), ticket7.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent2, 'email'), ticket7.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent2, 'online'), ticket7.id) + # verify notifications to @agent1 + @agent2 + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent1, 'email'), ticket7.id) + assert_equal(1, NotificationFactory::Mailer.already_sent?(ticket7, @agent1, 'online'), ticket7.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent2, 'email'), ticket7.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent2, 'online'), ticket7.id) # update ticket attributes ticket7.title = "#{ticket7.title} - #2" ticket7.priority = Ticket::Priority.lookup(name: '3 high') - ticket7.save + ticket7.save! # execute object transaction Observer::Transaction.commit Scheduler.worker(true) - # verify notifications to agent1 + agent2 - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'email'), ticket7.id) - assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket7, agent1, 'online'), ticket7.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent2, 'email'), ticket7.id) - assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, agent2, 'online'), ticket7.id) + # verify notifications to @agent1 + @agent2 + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent1, 'email'), ticket7.id) + assert_equal(2, NotificationFactory::Mailer.already_sent?(ticket7, @agent1, 'online'), ticket7.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent2, 'email'), ticket7.id) + assert_equal(0, NotificationFactory::Mailer.already_sent?(ticket7, @agent2, 'online'), ticket7.id) end test 'ticket notification events' do # create ticket in group - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: 'some notification event test 1', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, + customer: @customer, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - Ticket::Article.create( + Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -909,8 +906,8 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) assert(ticket1, 'ticket created') @@ -920,7 +917,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # update ticket attributes ticket1.title = "#{ticket1.title} - #2" ticket1.priority = Ticket::Priority.lookup(name: '3 high') - ticket1.save + ticket1.save! list = EventBuffer.list('transaction') list_objects = Observer::Transaction.get_uniq_changes(list) @@ -934,7 +931,7 @@ class TicketNotificationTest < ActiveSupport::TestCase # update ticket attributes ticket1.title = "#{ticket1.title} - #3" ticket1.priority = Ticket::Priority.lookup(name: '1 low') - ticket1.save + ticket1.save! list = EventBuffer.list('transaction') list_objects = Observer::Transaction.get_uniq_changes(list) @@ -950,16 +947,16 @@ class TicketNotificationTest < ActiveSupport::TestCase test 'ticket notification template' do # create ticket in group - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: 'some notification template test 1 Bobs\'s resumé', group: Group.lookup(name: 'TicketNotificationTest'), - customer: customer, + customer: @customer, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) - article = Ticket::Article.create( + article = Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -969,8 +966,8 @@ class TicketNotificationTest < ActiveSupport::TestCase internal: false, sender: Ticket::Article::Sender.where(name: 'Customer').first, type: Ticket::Article::Type.where(name: 'email').first, - updated_by_id: customer.id, - created_by_id: customer.id, + updated_by_id: @customer.id, + created_by_id: @customer.id, ) assert(ticket1, 'ticket created - ticket notification template') @@ -986,7 +983,7 @@ class TicketNotificationTest < ActiveSupport::TestCase ) # check changed attributes - human_changes = bg.human_changes(agent2, ticket1) + human_changes = bg.human_changes(@agent2, ticket1) assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute') assert(human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute') assert_equal('1 low', human_changes['Priority'][0]) @@ -999,12 +996,12 @@ class TicketNotificationTest < ActiveSupport::TestCase # en notification result = NotificationFactory::Mailer.template( - locale: agent2.preferences[:locale], + locale: @agent2.preferences[:locale], template: 'ticket_update', objects: { ticket: ticket1, article: article, - recipient: agent2, + recipient: @agent2, changes: human_changes, }, ) @@ -1018,7 +1015,7 @@ class TicketNotificationTest < ActiveSupport::TestCase assert_no_match(/pending_till/, result[:body]) assert_no_match(/i18n/, result[:body]) - human_changes = bg.human_changes(agent1, ticket1) + human_changes = bg.human_changes(@agent1, ticket1) assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute') assert(human_changes['Pending till'], 'Check if attributes translated based on ObjectManager::Attribute') assert_equal('1 niedrig', human_changes['Priority'][0]) @@ -1031,12 +1028,12 @@ class TicketNotificationTest < ActiveSupport::TestCase # de notification result = NotificationFactory::Mailer.template( - locale: agent1.preferences[:locale], + locale: @agent1.preferences[:locale], template: 'ticket_update', objects: { ticket: ticket1, article: article, - recipient: agent1, + recipient: @agent1, changes: human_changes, }, ) @@ -1059,11 +1056,11 @@ class TicketNotificationTest < ActiveSupport::TestCase title: ['some notification template test old 1', 'some notification template test 1 #2'], priority_id: [2, 3], }, - user_id: customer.id, + user_id: @customer.id, ) # check changed attributes - human_changes = bg.human_changes(agent1, ticket1) + human_changes = bg.human_changes(@agent1, ticket1) assert(human_changes['Title'], 'Check if attributes translated based on ObjectManager::Attribute') assert(human_changes['Priority'], 'Check if attributes translated based on ObjectManager::Attribute') assert_equal('2 normal', human_changes['Priority'][0]) @@ -1076,12 +1073,12 @@ class TicketNotificationTest < ActiveSupport::TestCase # de notification result = NotificationFactory::Mailer.template( - locale: agent1.preferences[:locale], + locale: @agent1.preferences[:locale], template: 'ticket_update', objects: { ticket: ticket1, article: article, - recipient: agent1, + recipient: @agent1, changes: human_changes, } ) @@ -1097,16 +1094,16 @@ class TicketNotificationTest < ActiveSupport::TestCase assert_match(/2 normal/, result[:body]) assert_match(/aktualisier/, result[:body]) - human_changes = bg.human_changes(agent2, ticket1) + human_changes = bg.human_changes(@agent2, ticket1) # en notification result = NotificationFactory::Mailer.template( - locale: agent2.preferences[:locale], + locale: @agent2.preferences[:locale], template: 'ticket_update', objects: { ticket: ticket1, article: article, - recipient: agent2, + recipient: @agent2, changes: human_changes, } ) @@ -1126,8 +1123,4 @@ class TicketNotificationTest < ActiveSupport::TestCase end - test 'zzz - cleanup' do - Trigger.destroy_all - end - end diff --git a/test/unit/ticket_overview_test.rb b/test/unit/ticket_overview_test.rb index 555ebf023..8c1acc94d 100644 --- a/test/unit/ticket_overview_test.rb +++ b/test/unit/ticket_overview_test.rb @@ -2,31 +2,16 @@ require 'test_helper' class TicketOverviewTest < ActiveSupport::TestCase - agent1 = nil - agent2 = nil - organization_id = nil - customer1 = nil - customer2 = nil - customer3 = nil - overview1 = nil - overview2 = nil - overview3 = nil - overview4 = nil - overview5 = nil - overview6 = nil - overview7 = nil - overview8 = nil - test 'aaa - setup' do - # create base + setup do group = Group.create_or_update( name: 'OverviewTest', updated_at: '2015-02-05 16:37:00', updated_by_id: 1, created_by_id: 1, ) - roles = Role.where(name: 'Agent') - agent1 = User.create_or_update( + roles = Role.where(name: 'Agent') + @agent1 = User.create_or_update( login: 'ticket-overview-agent1@example.com', firstname: 'Overview', lastname: 'Agent1', @@ -39,7 +24,7 @@ class TicketOverviewTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - agent2 = User.create_or_update( + @agent2 = User.create_or_update( login: 'ticket-overview-agent2@example.com', firstname: 'Overview', lastname: 'Agent2', @@ -59,7 +44,7 @@ class TicketOverviewTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - customer1 = User.create_or_update( + @customer1 = User.create_or_update( login: 'ticket-overview-customer1@example.com', firstname: 'Overview', lastname: 'Customer1', @@ -72,7 +57,7 @@ class TicketOverviewTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - customer2 = User.create_or_update( + @customer2 = User.create_or_update( login: 'ticket-overview-customer2@example.com', firstname: 'Overview', lastname: 'Customer2', @@ -85,7 +70,7 @@ class TicketOverviewTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - customer3 = User.create_or_update( + @customer3 = User.create_or_update( login: 'ticket-overview-customer3@example.com', firstname: 'Overview', lastname: 'Customer3', @@ -101,7 +86,7 @@ class TicketOverviewTest < ActiveSupport::TestCase Overview.destroy_all UserInfo.current_user_id = 1 overview_role = Role.find_by(name: 'Agent') - overview1 = Overview.create_or_update( + @overview1 = Overview.create_or_update( name: 'My assigned Tickets', link: 'my_assigned', prio: 1000, @@ -109,7 +94,7 @@ class TicketOverviewTest < ActiveSupport::TestCase condition: { 'ticket.state_id' => { operator: 'is', - value: [ 1, 2, 3, 7 ], + value: [1, 2, 3, 7], }, 'ticket.owner_id' => { operator: 'is', @@ -128,7 +113,7 @@ class TicketOverviewTest < ActiveSupport::TestCase }, ) - overview2 = Overview.create_or_update( + @overview2 = Overview.create_or_update( name: 'Unassigned & Open', link: 'all_unassigned', prio: 1010, @@ -154,16 +139,16 @@ class TicketOverviewTest < ActiveSupport::TestCase view_mode_default: 's', }, ) - overview3 = Overview.create_or_update( + @overview3 = Overview.create_or_update( name: 'My Tickets 2', link: 'my_tickets_2', prio: 1020, role_ids: [overview_role.id], - user_ids: [agent2.id], + user_ids: [@agent2.id], condition: { 'ticket.state_id' => { operator: 'is', - value: [ 1, 2, 3, 7 ], + value: [1, 2, 3, 7], }, 'ticket.owner_id' => { operator: 'is', @@ -181,12 +166,12 @@ class TicketOverviewTest < ActiveSupport::TestCase view_mode_default: 's', }, ) - overview4 = Overview.create_or_update( + @overview4 = Overview.create_or_update( name: 'My Tickets only with Note', link: 'my_tickets_onyl_with_note', prio: 1030, role_ids: [overview_role.id], - user_ids: [agent1.id], + user_ids: [@agent1.id], condition: { 'article.type_id' => { operator: 'is', @@ -210,7 +195,7 @@ class TicketOverviewTest < ActiveSupport::TestCase ) overview_role = Role.find_by(name: 'Customer') - overview5 = Overview.create_or_update( + @overview5 = Overview.create_or_update( name: 'My Tickets', link: 'my_tickets', prio: 1100, @@ -218,7 +203,7 @@ class TicketOverviewTest < ActiveSupport::TestCase condition: { 'ticket.state_id' => { operator: 'is', - value: [ 1, 2, 3, 4, 6, 7 ], + value: [1, 2, 3, 4, 6, 7], }, 'ticket.customer_id' => { operator: 'is', @@ -236,7 +221,7 @@ class TicketOverviewTest < ActiveSupport::TestCase view_mode_default: 's', }, ) - overview6 = Overview.create_or_update( + @overview6 = Overview.create_or_update( name: 'My Organization Tickets', link: 'my_organization_tickets', prio: 1200, @@ -245,7 +230,7 @@ class TicketOverviewTest < ActiveSupport::TestCase condition: { 'ticket.state_id' => { operator: 'is', - value: [ 1, 2, 3, 4, 6, 7 ], + value: [1, 2, 3, 4, 6, 7], }, 'ticket.organization_id' => { operator: 'is', @@ -263,17 +248,17 @@ class TicketOverviewTest < ActiveSupport::TestCase view_mode_default: 's', }, ) - overview7 = Overview.create_or_update( + @overview7 = Overview.create_or_update( name: 'My Organization Tickets (open)', link: 'my_organization_tickets_open', prio: 1200, role_ids: [overview_role.id], - user_ids: [customer2.id], + user_ids: [@customer2.id], organization_shared: true, condition: { 'ticket.state_id' => { operator: 'is', - value: [ 1, 2, 3 ], + value: [1, 2, 3], }, 'ticket.organization_id' => { operator: 'is', @@ -293,7 +278,7 @@ class TicketOverviewTest < ActiveSupport::TestCase ) overview_role = Role.find_by(name: 'Admin') - overview8 = Overview.create_or_update( + @overview8 = Overview.create_or_update( name: 'Not Shown Admin', link: 'not_shown_admin', prio: 9900, @@ -301,7 +286,7 @@ class TicketOverviewTest < ActiveSupport::TestCase condition: { 'ticket.state_id' => { operator: 'is', - value: [ 1, 2, 3 ], + value: [1, 2, 3], }, }, order: { @@ -320,7 +305,7 @@ class TicketOverviewTest < ActiveSupport::TestCase test 'bbb overiview index' do result = Ticket::Overviews.all( - current_user: agent1, + current_user: @agent1, ) assert_equal(3, result.count) assert_equal('My assigned Tickets', result[0].name) @@ -328,7 +313,7 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal('My Tickets only with Note', result[2].name) result = Ticket::Overviews.all( - current_user: agent2, + current_user: @agent2, ) assert_equal(3, result.count) assert_equal('My assigned Tickets', result[0].name) @@ -336,14 +321,14 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal('My Tickets 2', result[2].name) result = Ticket::Overviews.all( - current_user: customer1, + current_user: @customer1, ) assert_equal(2, result.count) assert_equal('My Tickets', result[0].name) assert_equal('My Organization Tickets', result[1].name) result = Ticket::Overviews.all( - current_user: customer2, + current_user: @customer2, ) assert_equal(3, result.count) assert_equal('My Tickets', result[0].name) @@ -351,7 +336,7 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal('My Organization Tickets (open)', result[2].name) result = Ticket::Overviews.all( - current_user: customer3, + current_user: @customer3, ) assert_equal(1, result.count) assert_equal('My Tickets', result[0].name) @@ -362,7 +347,7 @@ class TicketOverviewTest < ActiveSupport::TestCase Ticket.destroy_all - result = Ticket::Overviews.index(agent1) + result = Ticket::Overviews.index(@agent1) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) @@ -379,7 +364,7 @@ class TicketOverviewTest < ActiveSupport::TestCase assert(result[2][:tickets].empty?) assert_equal(result[2][:count], 0) - result = Ticket::Overviews.index(agent2) + result = Ticket::Overviews.index(@agent2) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) @@ -395,7 +380,7 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal(result[2][:tickets].class, Array) assert(result[2][:tickets].empty?) - ticket1 = Ticket.create( + ticket1 = Ticket.create!( title: 'overview test 1', group: Group.lookup(name: 'OverviewTest'), customer_id: 2, @@ -404,7 +389,7 @@ class TicketOverviewTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - article1 = Ticket::Article.create( + article1 = Ticket::Article.create!( ticket_id: ticket1.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -418,7 +403,7 @@ class TicketOverviewTest < ActiveSupport::TestCase created_by_id: 1, ) - result = Ticket::Overviews.index(agent1) + result = Ticket::Overviews.index(@agent1) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) @@ -436,7 +421,7 @@ class TicketOverviewTest < ActiveSupport::TestCase assert(result[2][:tickets].empty?) assert_equal(result[2][:count], 0) - result = Ticket::Overviews.index(agent2) + result = Ticket::Overviews.index(@agent2) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) @@ -453,7 +438,7 @@ class TicketOverviewTest < ActiveSupport::TestCase assert(result[2][:tickets].empty?) travel 1.second # because of mysql millitime issues - ticket2 = Ticket.create( + ticket2 = Ticket.create!( title: 'overview test 2', group: Group.lookup(name: 'OverviewTest'), customer_id: 2, @@ -462,7 +447,7 @@ class TicketOverviewTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - article2 = Ticket::Article.create( + article2 = Ticket::Article.create!( ticket_id: ticket2.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -476,7 +461,7 @@ class TicketOverviewTest < ActiveSupport::TestCase created_by_id: 1, ) - result = Ticket::Overviews.index(agent1) + result = Ticket::Overviews.index(@agent1) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) @@ -495,7 +480,7 @@ class TicketOverviewTest < ActiveSupport::TestCase assert(result[2][:tickets].empty?) assert_equal(result[2][:count], 0) - result = Ticket::Overviews.index(agent2) + result = Ticket::Overviews.index(@agent2) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) @@ -511,10 +496,10 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal(result[2][:tickets].class, Array) assert(result[2][:tickets].empty?) - ticket2.owner_id = agent1.id + ticket2.owner_id = @agent1.id ticket2.save! - result = Ticket::Overviews.index(agent1) + result = Ticket::Overviews.index(@agent1) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:tickets].class, Array) @@ -533,7 +518,7 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal(result[2][:tickets][0][:id], ticket2.id) assert_equal(result[2][:count], 1) - result = Ticket::Overviews.index(agent2) + result = Ticket::Overviews.index(@agent2) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) @@ -550,7 +535,7 @@ class TicketOverviewTest < ActiveSupport::TestCase assert(result[2][:tickets].empty?) travel 1.second # because of mysql millitime issues - ticket3 = Ticket.create( + ticket3 = Ticket.create!( title: 'overview test 3', group: Group.lookup(name: 'OverviewTest'), customer_id: 2, @@ -559,7 +544,7 @@ class TicketOverviewTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - article3 = Ticket::Article.create( + article3 = Ticket::Article.create!( ticket_id: ticket3.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -574,15 +559,15 @@ class TicketOverviewTest < ActiveSupport::TestCase ) travel_back - result = Ticket::Overviews.index(agent1) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent1) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets][0][:id], ticket2.id) assert_equal(result[0][:count], 1) assert_equal(result[0][:tickets].class, Array) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) @@ -590,47 +575,47 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal(result[1][:tickets][0][:id], ticket1.id) assert_equal(result[1][:tickets][1][:id], ticket3.id) assert_equal(result[1][:count], 2) - assert_equal(result[2][:overview][:id], overview4.id) + assert_equal(result[2][:overview][:id], @overview4.id) assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note') assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets][0][:id], ticket2.id) assert_equal(result[2][:count], 1) - result = Ticket::Overviews.index(agent2) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent2) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) assert_equal(result[0][:tickets].class, Array) assert(result[0][:tickets].empty?) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) assert(result[1][:tickets].empty?) assert_equal(result[1][:count], 0) - assert_equal(result[2][:overview][:id], overview3.id) + assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:tickets].class, Array) assert(result[2][:tickets].empty?) - overview2.order = { + @overview2.order = { by: 'created_at', direction: 'DESC', } - overview2.save! + @overview2.save! - result = Ticket::Overviews.index(agent1) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent1) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets][0][:id], ticket2.id) assert_equal(result[0][:count], 1) assert_equal(result[0][:tickets].class, Array) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) @@ -638,47 +623,47 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal(result[1][:tickets][0][:id], ticket3.id) assert_equal(result[1][:tickets][1][:id], ticket1.id) assert_equal(result[1][:count], 2) - assert_equal(result[2][:overview][:id], overview4.id) + assert_equal(result[2][:overview][:id], @overview4.id) assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note') assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets][0][:id], ticket2.id) assert_equal(result[2][:count], 1) - result = Ticket::Overviews.index(agent2) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent2) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) assert_equal(result[0][:tickets].class, Array) assert(result[0][:tickets].empty?) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) assert(result[1][:tickets].empty?) assert_equal(result[1][:count], 0) - assert_equal(result[2][:overview][:id], overview3.id) + assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:tickets].class, Array) assert(result[2][:tickets].empty?) - overview2.order = { + @overview2.order = { by: 'priority_id', direction: 'DESC', } - overview2.save! + @overview2.save! - result = Ticket::Overviews.index(agent1) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent1) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets][0][:id], ticket2.id) assert_equal(result[0][:count], 1) assert_equal(result[0][:tickets].class, Array) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) @@ -686,47 +671,47 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal(result[1][:tickets][0][:id], ticket1.id) assert_equal(result[1][:tickets][1][:id], ticket3.id) assert_equal(result[1][:count], 2) - assert_equal(result[2][:overview][:id], overview4.id) + assert_equal(result[2][:overview][:id], @overview4.id) assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note') assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets][0][:id], ticket2.id) assert_equal(result[2][:count], 1) - result = Ticket::Overviews.index(agent2) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent2) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) assert_equal(result[0][:tickets].class, Array) assert(result[0][:tickets].empty?) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) assert(result[1][:tickets].empty?) assert_equal(result[1][:count], 0) - assert_equal(result[2][:overview][:id], overview3.id) + assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:tickets].class, Array) assert(result[2][:tickets].empty?) - overview2.order = { + @overview2.order = { by: 'priority_id', direction: 'ASC', } - overview2.save! + @overview2.save! - result = Ticket::Overviews.index(agent1) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent1) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets][0][:id], ticket2.id) assert_equal(result[0][:count], 1) assert_equal(result[0][:tickets].class, Array) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) @@ -734,47 +719,47 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal(result[1][:tickets][0][:id], ticket3.id) assert_equal(result[1][:tickets][1][:id], ticket1.id) assert_equal(result[1][:count], 2) - assert_equal(result[2][:overview][:id], overview4.id) + assert_equal(result[2][:overview][:id], @overview4.id) assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note') assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets][0][:id], ticket2.id) assert_equal(result[2][:count], 1) - result = Ticket::Overviews.index(agent2) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent2) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) assert_equal(result[0][:tickets].class, Array) assert(result[0][:tickets].empty?) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) assert(result[1][:tickets].empty?) assert_equal(result[1][:count], 0) - assert_equal(result[2][:overview][:id], overview3.id) + assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:tickets].class, Array) assert(result[2][:tickets].empty?) - overview2.order = { + @overview2.order = { by: 'priority', direction: 'DESC', } - overview2.save! + @overview2.save! - result = Ticket::Overviews.index(agent1) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent1) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets][0][:id], ticket2.id) assert_equal(result[0][:count], 1) assert_equal(result[0][:tickets].class, Array) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) @@ -782,47 +767,47 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal(result[1][:tickets][0][:id], ticket1.id) assert_equal(result[1][:tickets][1][:id], ticket3.id) assert_equal(result[1][:count], 2) - assert_equal(result[2][:overview][:id], overview4.id) + assert_equal(result[2][:overview][:id], @overview4.id) assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note') assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets][0][:id], ticket2.id) assert_equal(result[2][:count], 1) - result = Ticket::Overviews.index(agent2) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent2) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) assert_equal(result[0][:tickets].class, Array) assert(result[0][:tickets].empty?) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) assert(result[1][:tickets].empty?) assert_equal(result[1][:count], 0) - assert_equal(result[2][:overview][:id], overview3.id) + assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:tickets].class, Array) assert(result[2][:tickets].empty?) - overview2.order = { + @overview2.order = { by: 'priority', direction: 'ASC', } - overview2.save! + @overview2.save! - result = Ticket::Overviews.index(agent1) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent1) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:tickets].class, Array) assert_equal(result[0][:tickets][0][:id], ticket2.id) assert_equal(result[0][:count], 1) assert_equal(result[0][:tickets].class, Array) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) @@ -830,27 +815,27 @@ class TicketOverviewTest < ActiveSupport::TestCase assert_equal(result[1][:tickets][0][:id], ticket3.id) assert_equal(result[1][:tickets][1][:id], ticket1.id) assert_equal(result[1][:count], 2) - assert_equal(result[2][:overview][:id], overview4.id) + assert_equal(result[2][:overview][:id], @overview4.id) assert_equal(result[2][:overview][:name], 'My Tickets only with Note') assert_equal(result[2][:overview][:view], 'my_tickets_onyl_with_note') assert_equal(result[2][:tickets].class, Array) assert_equal(result[2][:tickets][0][:id], ticket2.id) assert_equal(result[2][:count], 1) - result = Ticket::Overviews.index(agent2) - assert_equal(result[0][:overview][:id], overview1.id) + result = Ticket::Overviews.index(@agent2) + assert_equal(result[0][:overview][:id], @overview1.id) assert_equal(result[0][:overview][:name], 'My assigned Tickets') assert_equal(result[0][:overview][:view], 'my_assigned') assert_equal(result[0][:count], 0) assert_equal(result[0][:tickets].class, Array) assert(result[0][:tickets].empty?) - assert_equal(result[1][:overview][:id], overview2.id) + assert_equal(result[1][:overview][:id], @overview2.id) assert_equal(result[1][:overview][:name], 'Unassigned & Open') assert_equal(result[1][:overview][:view], 'all_unassigned') assert_equal(result[1][:tickets].class, Array) assert(result[1][:tickets].empty?) assert_equal(result[1][:count], 0) - assert_equal(result[2][:overview][:id], overview3.id) + assert_equal(result[2][:overview][:id], @overview3.id) assert_equal(result[2][:overview][:name], 'My Tickets 2') assert_equal(result[2][:overview][:view], 'my_tickets_2') assert_equal(result[2][:tickets].class, Array) diff --git a/test/unit/ticket_ref_object_touch_test.rb b/test/unit/ticket_ref_object_touch_test.rb index 657d091cf..77bb2ed6c 100644 --- a/test/unit/ticket_ref_object_touch_test.rb +++ b/test/unit/ticket_ref_object_touch_test.rb @@ -2,16 +2,11 @@ require 'test_helper' class TicketRefObjectTouchTest < ActiveSupport::TestCase - agent1 = nil - organization1 = nil - customer1 = nil - customer2 = nil - test 'aaa - setup' do - # create base + setup do groups = Group.where(name: 'Users') roles = Role.where(name: 'Agent') - agent1 = User.create_or_update( + @agent1 = User.create_or_update( login: 'ticket-ref-object-update-agent1@example.com', firstname: 'Notification', lastname: 'Agent1', @@ -25,26 +20,26 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase created_by_id: 1, ) roles = Role.where(name: 'Customer') - organization1 = Organization.create_if_not_exists( + @organization1 = Organization.create_if_not_exists( name: 'Ref Object Update Org', updated_at: '2015-02-05 16:37:00', updated_by_id: 1, created_by_id: 1, ) - customer1 = User.create_or_update( + @customer1 = User.create_or_update( login: 'ticket-ref-object-update-customer1@example.com', firstname: 'Notification', lastname: 'Customer1', email: 'ticket-ref-object-update-customer1@example.com', password: 'customerpw', active: true, - organization_id: organization1.id, + organization_id: @organization1.id, roles: roles, updated_at: '2015-02-05 16:37:00', updated_by_id: 1, created_by_id: 1, ) - customer2 = User.create_or_update( + @customer2 = User.create_or_update( login: 'ticket-ref-object-update-customer2@example.com', firstname: 'Notification', lastname: 'Customer2', @@ -64,27 +59,27 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase ticket = Ticket.create( title: "some title1\n äöüß", group: Group.lookup(name: 'Users'), - customer_id: customer1.id, - owner_id: agent1.id, + customer_id: @customer1.id, + owner_id: @agent1.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) assert(ticket, 'ticket created') - assert_equal(ticket.customer.id, customer1.id) - assert_equal(ticket.organization.id, organization1.id) + assert_equal(ticket.customer.id, @customer1.id) + assert_equal(ticket.organization.id, @organization1.id) # check if customer and organization has been touched - customer1 = User.find(customer1.id) - if customer1.updated_at > 3.seconds.ago + @customer1 = User.find(@customer1.id) + if @customer1.updated_at > 3.seconds.ago assert(true, 'customer1.updated_at has been updated') else assert(false, 'customer1.updated_at has not been updated') end - organization1 = Organization.find(organization1.id) - if organization1.updated_at > 3.seconds.ago + @organization1 = Organization.find(@organization1.id) + if @organization1.updated_at > 3.seconds.ago assert(true, 'organization1.updated_at has been updated') else assert(false, 'organization1.updated_at has not been updated') @@ -96,15 +91,15 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase assert(delete, 'ticket destroy') # check if customer and organization has been touched - customer1 = User.find(customer1.id) - if customer1.updated_at > 3.seconds.ago + @customer1.reload + if @customer1.updated_at > 3.seconds.ago assert(true, 'customer1.updated_at has been updated') else assert(false, 'customer1.updated_at has not been updated') end - organization1 = Organization.find(organization1.id) - if organization1.updated_at > 3.seconds.ago + @organization1.reload + if @organization1.updated_at > 3.seconds.ago assert(true, 'organization1.updated_at has been updated') else assert(false, 'organization1.updated_at has not been updated') @@ -118,27 +113,27 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase ticket = Ticket.create( title: "some title2\n äöüß", group: Group.lookup(name: 'Users'), - customer_id: customer2.id, - owner_id: agent1.id, + customer_id: @customer2.id, + owner_id: @agent1.id, state: Ticket::State.lookup(name: 'new'), priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) assert(ticket, 'ticket created') - assert_equal(ticket.customer.id, customer2.id) + assert_equal(ticket.customer.id, @customer2.id) assert_nil(ticket.organization) # check if customer and organization has been touched - customer2 = User.find(customer2.id) - if customer2.updated_at > 3.seconds.ago + @customer2.reload + if @customer2.updated_at > 3.seconds.ago assert(true, 'customer2.updated_at has been updated') else assert(false, 'customer2.updated_at has not been updated') end - organization1 = Organization.find(organization1.id) - if organization1.updated_at > 3.seconds.ago + @organization1.reload + if @organization1.updated_at > 3.seconds.ago assert(false, 'organization1.updated_at has been updated') else assert(true, 'organization1.updated_at has not been updated') @@ -150,15 +145,15 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase assert(delete, 'ticket destroy') # check if customer and organization has been touched - customer2 = User.find(customer2.id) - if customer2.updated_at > 3.seconds.ago + @customer2.reload + if @customer2.updated_at > 3.seconds.ago assert(true, 'customer2.updated_at has been updated') else assert(false, 'customer2.updated_at has not been updated') end - organization1 = Organization.find(organization1.id) - if organization1.updated_at > 3.seconds.ago + @organization1.reload + if @organization1.updated_at > 3.seconds.ago assert(false, 'organization1.updated_at has been updated') else assert(true, 'organization1.updated_at has not been updated') diff --git a/test/unit/ticket_selector_test.rb b/test/unit/ticket_selector_test.rb index bece536c7..374172b09 100644 --- a/test/unit/ticket_selector_test.rb +++ b/test/unit/ticket_selector_test.rb @@ -2,24 +2,16 @@ require 'test_helper' class TicketSelectorTest < ActiveSupport::TestCase - agent1 = nil - agent2 = nil - group = nil - organization1 = nil - customer1 = nil - customer2 = nil - test 'aaa - setup' do - - # create base - group = Group.create_or_update( + setup do + @group = Group.create_or_update( name: 'SelectorTest', updated_at: '2015-02-05 16:37:00', updated_by_id: 1, created_by_id: 1, ) - roles = Role.where(name: 'Agent') - agent1 = User.create_or_update( + roles = Role.where(name: 'Agent') + @agent1 = User.create_or_update( login: 'ticket-selector-agent1@example.com', firstname: 'Notification', lastname: 'Agent1', @@ -27,12 +19,12 @@ class TicketSelectorTest < ActiveSupport::TestCase password: 'agentpw', active: true, roles: roles, - groups: [group], + groups: [@group], updated_at: '2015-02-05 16:37:00', updated_by_id: 1, created_by_id: 1, ) - agent2 = User.create_or_update( + @agent2 = User.create_or_update( login: 'ticket-selector-agent2@example.com', firstname: 'Notification', lastname: 'Agent2', @@ -40,32 +32,31 @@ class TicketSelectorTest < ActiveSupport::TestCase password: 'agentpw', active: true, roles: roles, - #groups: groups, updated_at: '2015-02-05 16:38:00', updated_by_id: 1, created_by_id: 1, ) roles = Role.where(name: 'Customer') - organization1 = Organization.create_if_not_exists( + @organization1 = Organization.create_if_not_exists( name: 'Selector Org', updated_at: '2015-02-05 16:37:00', updated_by_id: 1, created_by_id: 1, ) - customer1 = User.create_or_update( + @customer1 = User.create_or_update( login: 'ticket-selector-customer1@example.com', firstname: 'Notification', lastname: 'Customer1', email: 'ticket-selector-customer1@example.com', password: 'customerpw', active: true, - organization_id: organization1.id, + organization_id: @organization1.id, roles: roles, updated_at: '2015-02-05 16:37:00', updated_by_id: 1, created_by_id: 1, ) - customer2 = User.create_or_update( + @customer2 = User.create_or_update( login: 'ticket-selector-customer2@example.com', firstname: 'Notification', lastname: 'Customer2', @@ -79,7 +70,7 @@ class TicketSelectorTest < ActiveSupport::TestCase created_by_id: 1, ) - Ticket.where(group_id: group.id).destroy_all + Ticket.where(group_id: @group.id).destroy_all end test 'ticket create' do @@ -88,9 +79,9 @@ class TicketSelectorTest < ActiveSupport::TestCase ticket1 = Ticket.create!( title: 'some title1', - group: group, - customer_id: customer1.id, - owner_id: agent1.id, + 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', @@ -99,14 +90,14 @@ class TicketSelectorTest < ActiveSupport::TestCase created_by_id: 1, ) assert(ticket1, 'ticket created') - assert_equal(ticket1.customer.id, customer1.id) - assert_equal(ticket1.organization.id, organization1.id) + assert_equal(ticket1.customer.id, @customer1.id) + assert_equal(ticket1.organization.id, @organization1.id) travel 1.second ticket2 = Ticket.create!( title: 'some title2', - group: group, - customer_id: customer2.id, + 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', @@ -115,14 +106,14 @@ class TicketSelectorTest < ActiveSupport::TestCase created_by_id: 1, ) assert(ticket2, 'ticket created') - assert_equal(ticket2.customer.id, customer2.id) + assert_equal(ticket2.customer.id, @customer2.id) assert_nil(ticket2.organization_id) travel 1.second ticket3 = Ticket.create!( title: 'some title3', - group: group, - customer_id: customer2.id, + 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', @@ -132,7 +123,7 @@ class TicketSelectorTest < ActiveSupport::TestCase ) ticket3.update_columns(escalation_at: '2015-02-06 10:00:00') assert(ticket3, 'ticket created') - assert_equal(ticket3.customer.id, customer2.id) + assert_equal(ticket3.customer.id, @customer2.id) assert_nil(ticket3.organization_id) travel 1.second @@ -143,23 +134,23 @@ class TicketSelectorTest < ActiveSupport::TestCase value: [99], }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) # search matching with empty value / missing key condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.state_id' => { operator: 'is', @@ -169,23 +160,23 @@ class TicketSelectorTest < ActiveSupport::TestCase ticket_count, tickets = Ticket.selectors(condition, 10) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_nil(ticket_count) # search matching with empty value [] condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.state_id' => { operator: 'is', @@ -196,23 +187,23 @@ class TicketSelectorTest < ActiveSupport::TestCase ticket_count, tickets = Ticket.selectors(condition, 10) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_nil(ticket_count) # search matching with empty value '' condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.state_id' => { operator: 'is', @@ -223,23 +214,23 @@ class TicketSelectorTest < ActiveSupport::TestCase ticket_count, tickets = Ticket.selectors(condition, 10) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_nil(ticket_count) # search matching condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.state_id' => { operator: 'is', @@ -250,22 +241,22 @@ class TicketSelectorTest < ActiveSupport::TestCase ticket_count, tickets = Ticket.selectors(condition, 10) assert_equal(ticket_count, 2) - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 2) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 1) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.state_id' => { operator: 'is not', @@ -275,16 +266,16 @@ class TicketSelectorTest < ActiveSupport::TestCase ticket_count, tickets = Ticket.selectors(condition, 10) assert_equal(ticket_count, 2) - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 2) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 1) condition = { @@ -296,111 +287,111 @@ class TicketSelectorTest < ActiveSupport::TestCase ticket_count, tickets = Ticket.selectors(condition, 10) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 1) # search - created_at condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.created_at' => { operator: 'after (absolute)', # before (absolute) value: '2015-02-05T16:00:00.000Z', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.created_at' => { operator: 'after (absolute)', # before (absolute) value: '2015-02-05T18:00:00.000Z', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.created_at' => { operator: 'before (absolute)', value: '2015-02-05T18:00:00.000Z', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.created_at' => { operator: 'before (absolute)', value: '2015-02-05T16:00:00.000Z', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.created_at' => { operator: 'before (relative)', @@ -408,22 +399,22 @@ class TicketSelectorTest < ActiveSupport::TestCase value: '10', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.created_at' => { operator: 'within next (relative)', @@ -431,22 +422,22 @@ class TicketSelectorTest < ActiveSupport::TestCase value: '10', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.created_at' => { operator: 'within last (relative)', @@ -454,111 +445,111 @@ class TicketSelectorTest < ActiveSupport::TestCase value: '10', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) # search - updated_at condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.updated_at' => { operator: 'before (absolute)', value: (Time.zone.now + 1.day).iso8601, }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.updated_at' => { operator: 'before (absolute)', value: (Time.zone.now - 1.day).iso8601, }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.updated_at' => { operator: 'after (absolute)', value: (Time.zone.now + 1.day).iso8601, }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.updated_at' => { operator: 'after (absolute)', value: (Time.zone.now - 1.day).iso8601, }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.updated_at' => { operator: 'before (relative)', @@ -566,22 +557,22 @@ class TicketSelectorTest < ActiveSupport::TestCase value: '10', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.updated_at' => { operator: 'within next (relative)', @@ -589,22 +580,22 @@ class TicketSelectorTest < ActiveSupport::TestCase value: '10', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.updated_at' => { operator: 'within last (relative)', @@ -612,16 +603,16 @@ class TicketSelectorTest < ActiveSupport::TestCase value: '10', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) # invalid conditions @@ -633,75 +624,75 @@ class TicketSelectorTest < ActiveSupport::TestCase condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'customer.email' => { operator: 'contains', value: 'ticket-selector-customer1', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'customer.email' => { operator: 'contains not', value: 'ticket-selector-customer1-not_existing', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 3) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) # search with organizations condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'organization.name' => { operator: 'contains', value: 'selector', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) # search with organizations condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'organization.name' => { operator: 'contains', @@ -712,22 +703,22 @@ class TicketSelectorTest < ActiveSupport::TestCase value: 'ticket-selector-customer1', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'organization.name' => { operator: 'contains', @@ -738,260 +729,260 @@ class TicketSelectorTest < ActiveSupport::TestCase value: 'ticket-selector-customer1', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) # with owner/customer/org condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.owner_id' => { operator: 'is', pre_condition: 'specific', - value: agent1.id, + value: @agent1.id, }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.owner_id' => { operator: 'is', pre_condition: 'specific', - #value: agent1.id, # value is not set, no result should be shown + #value: @agent1.id, # value is not set, no result should be shown }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_nil(ticket_count) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_nil(ticket_count) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.owner_id' => { operator: 'is', pre_condition: 'not_set', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 2) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.owner_id' => { operator: 'is not', pre_condition: 'not_set', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) - UserInfo.current_user_id = agent1.id + UserInfo.current_user_id = @agent1.id condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.owner_id' => { operator: 'is', pre_condition: 'current_user.id', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 1) ticket_count, tickets = Ticket.selectors(condition, 10) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) - UserInfo.current_user_id = agent2.id + UserInfo.current_user_id = @agent2.id condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.owner_id' => { operator: 'is', pre_condition: 'current_user.id', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) ticket_count, tickets = Ticket.selectors(condition, 10) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) - UserInfo.current_user_id = customer1.id + UserInfo.current_user_id = @customer1.id condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.customer_id' => { operator: 'is', pre_condition: 'current_user.id', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) ticket_count, tickets = Ticket.selectors(condition, 10) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) - UserInfo.current_user_id = customer2.id + UserInfo.current_user_id = @customer2.id condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.customer_id' => { operator: 'is', pre_condition: 'current_user.id', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 2) ticket_count, tickets = Ticket.selectors(condition, 10) assert_equal(ticket_count, 2) - UserInfo.current_user_id = customer1.id + UserInfo.current_user_id = @customer1.id condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.organization_id' => { operator: 'is', pre_condition: 'current_user.organization_id', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) ticket_count, tickets = Ticket.selectors(condition, 10) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) - UserInfo.current_user_id = customer2.id + UserInfo.current_user_id = @customer2.id condition = { 'ticket.group_id' => { operator: 'is', - value: group.id, + value: @group.id, }, 'ticket.organization_id' => { operator: 'is', pre_condition: 'current_user.organization_id', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, agent2) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent2) assert_equal(ticket_count, 0) - ticket_count, tickets = Ticket.selectors(condition, 10, customer1) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer1) assert_equal(ticket_count, 1) - ticket_count, tickets = Ticket.selectors(condition, 10, customer2) + ticket_count, tickets = Ticket.selectors(condition, 10, @customer2) assert_equal(ticket_count, 0) ticket_count, tickets = Ticket.selectors(condition, 10) @@ -1002,9 +993,9 @@ class TicketSelectorTest < ActiveSupport::TestCase test 'ticket tags filter' do ticket_tags_1 = Ticket.create!( title: 'some title1', - group: group, - customer_id: customer1.id, - owner_id: agent1.id, + 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', @@ -1013,9 +1004,9 @@ class TicketSelectorTest < ActiveSupport::TestCase ) ticket_tags_2 = Ticket.create!( title: 'some title1', - group: group, - customer_id: customer1.id, - owner_id: agent1.id, + 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', @@ -1024,9 +1015,9 @@ class TicketSelectorTest < ActiveSupport::TestCase ) ticket_tags_3 = Ticket.create!( title: 'some title1', - group: group, - customer_id: customer1.id, - owner_id: agent1.id, + 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', @@ -1066,7 +1057,7 @@ class TicketSelectorTest < ActiveSupport::TestCase value: 'contains_all_1, contains_all_2, contains_all_3', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(1, ticket_count) condition = { @@ -1075,7 +1066,7 @@ class TicketSelectorTest < ActiveSupport::TestCase value: 'contains_all_1, contains_all_2, contains_all_3, xxx', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(0, ticket_count) # search all with contains one @@ -1085,7 +1076,7 @@ class TicketSelectorTest < ActiveSupport::TestCase value: 'contains_all_1, contains_all_2, contains_all_3', }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(2, ticket_count) condition = { @@ -1094,7 +1085,7 @@ class TicketSelectorTest < ActiveSupport::TestCase value: 'contains_all_1, contains_all_2' }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(1, ticket_count) # search all with contains one not @@ -1104,7 +1095,7 @@ class TicketSelectorTest < ActiveSupport::TestCase value: 'contains_all_1, contains_all_3' }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(2, ticket_count) condition = { @@ -1113,7 +1104,7 @@ class TicketSelectorTest < ActiveSupport::TestCase value: 'contains_all_1, contains_all_2, contains_all_3' }, } - ticket_count, tickets = Ticket.selectors(condition, 10, agent1) + ticket_count, tickets = Ticket.selectors(condition, 10, @agent1) assert_equal(2, ticket_count) end