Improved tests.

This commit is contained in:
Martin Edenhofer 2017-06-14 17:25:45 +02:00
parent 71980d6cf5
commit 1a43d9bd5c
20 changed files with 1481 additions and 1502 deletions

View file

@ -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})"

View file

@ -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]

View file

@ -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,

View file

@ -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

View file

@ -1,19 +1,22 @@
# encoding: utf-8
require 'integration_test_helper'
require 'rake'
class ElasticsearchTest < ActiveSupport::TestCase
setup do
# set config
if !ENV['ES_URL']
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'] && !ENV['ES_INDEX_RAND']
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
end
if ENV['ES_INDEX_RAND']
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')
@ -25,13 +28,15 @@ class ElasticsearchTest < ActiveSupport::TestCase
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
system('rake searchindex:rebuild')
Rake::Task['searchindex:rebuild'].execute
groups = Group.where(name: 'Users')
roles = Role.where(name: 'Agent')
agent = User.create_or_update(
@agent = User.create_or_update(
login: 'es-agent@example.com',
firstname: 'E',
lastname: 'S',
@ -50,39 +55,39 @@ class ElasticsearchTest < 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',
note: 'some note',
updated_by_id: 1,
created_by_id: 1,
)
customer1 = User.create_or_update(
@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,
organization_id: @organization1.id,
roles: roles,
updated_by_id: 1,
created_by_id: 1,
)
sleep 1
customer2 = User.create_or_update(
@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,
organization_id: @organization1.id,
roles: roles,
updated_by_id: 1,
created_by_id: 1,
)
sleep 1
customer3 = User.create_or_update(
@customer3 = User.create_or_update(
login: 'es-customer3@example.com',
firstname: 'ES',
lastname: 'Customer3',
@ -93,19 +98,20 @@ class ElasticsearchTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
end
# 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
# 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

View file

@ -1,20 +1,22 @@
# encoding: utf-8
require 'integration_test_helper'
require 'rake'
class ReportTest < ActiveSupport::TestCase
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'] && !ENV['ES_INDEX_RAND']
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
end
if ENV['ES_INDEX_RAND']
if ENV['ES_INDEX_RAND'].present?
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
end
Setting.set('es_index', ENV['ES_INDEX'])
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')
@ -22,18 +24,14 @@ class ReportTest < ActiveSupport::TestCase
# Setting.set('es_password', 'zammad')
# Setting.set('es_attachment_max_size_in_mb', 1)
# clear cache
Cache.clear
# remove background jobs
Delayed::Job.destroy_all
Ticket.destroy_all
# 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
group1 = Group.lookup(name: 'Users')
group2 = Group.create_if_not_exists(
@ -42,9 +40,7 @@ class ReportTest < ActiveSupport::TestCase
created_by_id: 1
)
load "#{Rails.root}/test/fixtures/seeds.rb"
ticket1 = Ticket.create(
@ticket1 = Ticket.create!(
title: 'test 1',
group: group2,
customer_id: 2,
@ -55,8 +51,8 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
article1 = Ticket::Article.create(
ticket_id: ticket1.id,
Ticket::Article.create!(
ticket_id: @ticket1.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
@ -70,12 +66,12 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
ticket1.update_attributes(
@ticket1.update_attributes(
group: Group.lookup(name: 'Users'),
updated_at: '2015-10-28 14:30:00 UTC',
)
ticket2 = Ticket.create(
@ticket2 = Ticket.create!(
title: 'test 2',
group: group1,
customer_id: 2,
@ -86,8 +82,8 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
article2 = Ticket::Article.create(
ticket_id: ticket2.id,
Ticket::Article.create!(
ticket_id: @ticket2.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
@ -101,12 +97,12 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
ticket2.update_attributes(
@ticket2.update_attributes(
group_id: group2.id,
updated_at: '2015-10-28 14:30:00 UTC',
)
ticket3 = Ticket.create(
@ticket3 = Ticket.create!(
title: 'test 3',
group: group1,
customer_id: 2,
@ -117,8 +113,8 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
article3 = Ticket::Article.create(
ticket_id: ticket3.id,
Ticket::Article.create!(
ticket_id: @ticket3.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
@ -133,7 +129,7 @@ class ReportTest < ActiveSupport::TestCase
created_by_id: 1,
)
ticket4 = Ticket.create(
@ticket4 = Ticket.create!(
title: 'test 4',
group: group1,
customer_id: 2,
@ -145,8 +141,8 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
article4 = Ticket::Article.create(
ticket_id: ticket4.id,
Ticket::Article.create!(
ticket_id: @ticket4.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
@ -161,7 +157,7 @@ class ReportTest < ActiveSupport::TestCase
created_by_id: 1,
)
ticket5 = Ticket.create(
@ticket5 = Ticket.create!(
title: 'test 5',
group: group1,
customer_id: 2,
@ -173,8 +169,8 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
article5 = Ticket::Article.create(
ticket_id: ticket5.id,
Ticket::Article.create!(
ticket_id: @ticket5.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
@ -188,12 +184,12 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
ticket5.update_attributes(
@ticket5.update_attributes(
state: Ticket::State.lookup(name: 'open'),
updated_at: '2015-10-28 14:30:00 UTC',
)
ticket6 = Ticket.create(
@ticket6 = Ticket.create!(
title: 'test 6',
group: group1,
customer_id: 2,
@ -205,8 +201,8 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
article6 = Ticket::Article.create(
ticket_id: ticket6.id,
Ticket::Article.create!(
ticket_id: @ticket6.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
@ -221,7 +217,7 @@ class ReportTest < ActiveSupport::TestCase
created_by_id: 1,
)
ticket7 = Ticket.create(
@ticket7 = Ticket.create!(
title: 'test 7',
group: group1,
customer_id: 2,
@ -233,8 +229,8 @@ class ReportTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
article7 = Ticket::Article.create(
ticket_id: ticket7.id,
Ticket::Article.create!(
ticket_id: @ticket7.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'some subject',
@ -252,11 +248,11 @@ class ReportTest < ActiveSupport::TestCase
# execute background jobs
Scheduler.worker(true)
sleep 6
end
test 'a - first solution' do
test 'compare' 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

View file

@ -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

View file

@ -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

View file

@ -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 <unittest@example.com>',
@ -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

View file

@ -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

View file

@ -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])

View file

@ -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
setup do
role = Role.lookup(name: 'Agent')
group = Group.create_or_update(
@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 <unittest@example.com>',
@ -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 <unittest@example.com>',
@ -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 <unittest@example.com>',
@ -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 <unittest@example.com>',
@ -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 <unittest@example.com>',
@ -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 <unittest@example.com>',
@ -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,
)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -2,23 +2,8 @@
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',
@ -26,7 +11,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
created_by_id: 1,
)
roles = Role.where(name: 'Agent')
agent1 = User.create_or_update(
@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)

View file

@ -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')

File diff suppressed because it is too large Load diff