Rework, get unit tests up and running again.
This commit is contained in:
parent
c826625ce7
commit
9b9f9ed8c5
25 changed files with 321 additions and 395 deletions
|
@ -50,11 +50,7 @@ add a new activity entry for an object
|
||||||
|
|
||||||
# resturn if old entry is really fresh
|
# resturn if old entry is really fresh
|
||||||
if result
|
if result
|
||||||
activity_record_delay = if ENV['ZAMMAD_ACTIVITY_RECORD_DELAY']
|
activity_record_delay = 90.seconds
|
||||||
ENV['ZAMMAD_ACTIVITY_RECORD_DELAY'].to_i.seconds
|
|
||||||
else
|
|
||||||
90.seconds
|
|
||||||
end
|
|
||||||
return result if result.created_at.to_i >= ( data[:created_at].to_i - activity_record_delay )
|
return result if result.created_at.to_i >= ( data[:created_at].to_i - activity_record_delay )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,13 +93,10 @@ return all activity entries of an user
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.list(user, limit)
|
def self.list(user, limit)
|
||||||
# do not return an activity stream for custoers
|
# do not return an activity stream for customers
|
||||||
return [] if !user.permissions?('ticket.agent') && !user.permissions?('admin')
|
return [] if !user.permissions?('ticket.agent') && !user.permissions?('admin')
|
||||||
|
|
||||||
permission_ids = []
|
permission_ids = user.permissions_with_child_ids
|
||||||
user.roles.each { |role|
|
|
||||||
permission_ids = permission_ids.concat(role.permission_ids)
|
|
||||||
}
|
|
||||||
group_ids = user.group_ids
|
group_ids = user.group_ids
|
||||||
|
|
||||||
stream = if group_ids.empty?
|
stream = if group_ids.empty?
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
# process all database filter
|
# process all database filter
|
||||||
module Channel::Filter::Database
|
module Channel::Filter::Database
|
||||||
|
|
||||||
def self.run( _channel, mail )
|
def self.run(_channel, mail)
|
||||||
|
|
||||||
# process postmaster filter
|
# process postmaster filter
|
||||||
filters = PostmasterFilter.where( active: true, channel: 'email' ).order(:name, :created_at)
|
filters = PostmasterFilter.where(active: true, channel: 'email').order(:name, :created_at)
|
||||||
filters.each { |filter|
|
filters.each { |filter|
|
||||||
Rails.logger.info " process filter #{filter.name} ..."
|
Rails.logger.info " process filter #{filter.name} ..."
|
||||||
all_matches_ok = true
|
all_matches_ok = true
|
||||||
|
|
|
@ -52,7 +52,7 @@ get signup roles
|
||||||
|
|
||||||
Role.signup_roles
|
Role.signup_roles
|
||||||
|
|
||||||
returnes
|
returns
|
||||||
|
|
||||||
[role1, role2, ...]
|
[role1, role2, ...]
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ get signup role ids
|
||||||
|
|
||||||
Role.signup_role_ids
|
Role.signup_role_ids
|
||||||
|
|
||||||
returnes
|
returns
|
||||||
|
|
||||||
[role1, role2, ...]
|
[role1, role2, ...]
|
||||||
|
|
||||||
|
|
|
@ -380,6 +380,32 @@ returns
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
|
returns all accessable permission ids of user
|
||||||
|
|
||||||
|
user = User.find(123)
|
||||||
|
user.permissions_with_child_ids
|
||||||
|
|
||||||
|
returns
|
||||||
|
|
||||||
|
[permission1_id, permission2_id, permission3_id]
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def permissions_with_child_ids
|
||||||
|
where = ''
|
||||||
|
where_bind = [true]
|
||||||
|
permissions.each { |permission_name, _value|
|
||||||
|
where += ' OR ' if where != ''
|
||||||
|
where += 'permissions.name = ? OR permissions.name LIKE ?'
|
||||||
|
where_bind.push permission_name
|
||||||
|
where_bind.push "#{permission_name}.%"
|
||||||
|
}
|
||||||
|
return [] if where == ''
|
||||||
|
Object.const_get('Permission').where("permissions.active = ? AND (#{where})", *where_bind).pluck(:id)
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
get all users with permission
|
get all users with permission
|
||||||
|
|
||||||
users = User.with_permissions('admin.session')
|
users = User.with_permissions('admin.session')
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class SearchControllerTest < ActionDispatch::IntegrationTest
|
class SearchControllerTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
def base_data
|
||||||
|
|
||||||
# clear cache
|
# clear cache
|
||||||
Cache.clear
|
Cache.clear
|
||||||
|
@ -192,6 +192,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'settings index with nobody' do
|
test 'settings index with nobody' do
|
||||||
|
base_data
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
query: 'test 1234',
|
query: 'test 1234',
|
||||||
|
@ -222,6 +223,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'settings index with admin' do
|
test 'settings index with admin' do
|
||||||
|
base_data
|
||||||
|
|
||||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-admin@example.com', 'adminpw')
|
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-admin@example.com', 'adminpw')
|
||||||
|
|
||||||
|
@ -295,6 +297,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'settings index with agent' do
|
test 'settings index with agent' do
|
||||||
|
base_data
|
||||||
|
|
||||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-agent@example.com', 'agentpw')
|
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-agent@example.com', 'agentpw')
|
||||||
|
|
||||||
|
@ -368,6 +371,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'settings index with customer 1' do
|
test 'settings index with customer 1' do
|
||||||
|
base_data
|
||||||
|
|
||||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-customer1@example.com', 'customer1pw')
|
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-customer1@example.com', 'customer1pw')
|
||||||
|
|
||||||
|
@ -413,6 +417,7 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'settings index with customer 2' do
|
test 'settings index with customer 2' do
|
||||||
|
base_data
|
||||||
|
|
||||||
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-customer2@example.com', 'customer2pw')
|
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('search-customer2@example.com', 'customer2pw')
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ class ActiveSupport::TestCase
|
||||||
|
|
||||||
# remove background jobs
|
# remove background jobs
|
||||||
Delayed::Job.destroy_all
|
Delayed::Job.destroy_all
|
||||||
|
ActivityStream.destroy_all
|
||||||
|
PostmasterFilter.destroy_all
|
||||||
|
Ticket.destroy_all
|
||||||
|
|
||||||
# set current user
|
# set current user
|
||||||
UserInfo.current_user_id = nil
|
UserInfo.current_user_id = nil
|
||||||
|
|
|
@ -5,7 +5,7 @@ class ActivityStreamTest < ActiveSupport::TestCase
|
||||||
admin_user = nil
|
admin_user = nil
|
||||||
current_user = nil
|
current_user = nil
|
||||||
test 'aaa - setup' do
|
test 'aaa - setup' do
|
||||||
role = Role.lookup(name: 'Admin')
|
roles = Role.where(name: %w(Admin Agent))
|
||||||
group = Group.lookup(name: 'Users')
|
group = Group.lookup(name: 'Users')
|
||||||
admin_user = User.create_or_update(
|
admin_user = User.create_or_update(
|
||||||
login: 'admin',
|
login: 'admin',
|
||||||
|
@ -14,7 +14,7 @@ class ActivityStreamTest < ActiveSupport::TestCase
|
||||||
email: 'bob@example.com',
|
email: 'bob@example.com',
|
||||||
password: 'some_pass',
|
password: 'some_pass',
|
||||||
active: true,
|
active: true,
|
||||||
role_ids: [role.id],
|
roles: roles,
|
||||||
group_ids: [group.id],
|
group_ids: [group.id],
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1
|
created_by_id: 1
|
||||||
|
@ -23,377 +23,191 @@ class ActivityStreamTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'ticket+user' do
|
test 'ticket+user' do
|
||||||
tests = [
|
ticket = Ticket.create(
|
||||||
|
group_id: Group.lookup(name: 'Users').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,
|
||||||
|
)
|
||||||
|
travel 2.seconds
|
||||||
|
|
||||||
# test 1
|
article = Ticket::Article.create(
|
||||||
{
|
ticket_id: ticket.id,
|
||||||
create: {
|
updated_by_id: current_user.id,
|
||||||
ticket: {
|
created_by_id: current_user.id,
|
||||||
group_id: Group.lookup(name: 'Users').id,
|
type_id: Ticket::Article::Type.lookup(name: 'phone').id,
|
||||||
customer_id: current_user.id,
|
sender_id: Ticket::Article::Sender.lookup(name: 'Customer').id,
|
||||||
owner_id: User.lookup(login: '-').id,
|
from: 'Unit Test <unittest@example.com>',
|
||||||
title: 'Unit Test 1 (äöüß)!',
|
body: 'Unit Test 123',
|
||||||
state_id: Ticket::State.lookup(name: 'new').id,
|
internal: false,
|
||||||
priority_id: Ticket::Priority.lookup(name: '2 normal').id,
|
)
|
||||||
updated_by_id: current_user.id,
|
|
||||||
created_by_id: current_user.id,
|
|
||||||
},
|
|
||||||
article: {
|
|
||||||
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>',
|
|
||||||
body: 'Unit Test 123',
|
|
||||||
internal: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
update: {
|
|
||||||
ticket: {
|
|
||||||
title: 'Unit Test 1 (äöüß) - update!',
|
|
||||||
state_id: Ticket::State.lookup(name: 'open').id,
|
|
||||||
priority_id: Ticket::Priority.lookup(name: '1 low').id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
update2: {
|
|
||||||
ticket: {
|
|
||||||
title: 'Unit Test 2 (äöüß) - update!',
|
|
||||||
priority_id: Ticket::Priority.lookup(name: '2 normal').id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
check: [
|
|
||||||
{
|
|
||||||
result: true,
|
|
||||||
object: 'Ticket',
|
|
||||||
type: 'update',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
result: true,
|
|
||||||
object: 'Ticket::Article',
|
|
||||||
type: 'create',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
result: true,
|
|
||||||
object: 'Ticket',
|
|
||||||
type: 'create',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
result: false,
|
|
||||||
object: 'User',
|
|
||||||
type: 'update',
|
|
||||||
o_id: current_user.id,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
tickets = []
|
|
||||||
tests.each { |test|
|
|
||||||
|
|
||||||
ticket = Ticket.create(test[:create][:ticket])
|
travel 100.seconds
|
||||||
test[:check][0][:o_id] = ticket.id
|
ticket.update_attributes(
|
||||||
test[:check][2][:o_id] = ticket.id
|
title: 'Unit Test 1 (äöüß) - update!',
|
||||||
test[:check][2][:created_at] = ticket.created_at
|
state_id: Ticket::State.lookup(name: 'open').id,
|
||||||
test[:check][2][:created_by_id] = current_user.id
|
priority_id: Ticket::Priority.lookup(name: '1 low').id,
|
||||||
travel 2.seconds
|
)
|
||||||
|
updated_at = ticket.updated_at
|
||||||
|
|
||||||
test[:create][:article][:ticket_id] = ticket.id
|
travel 1.second
|
||||||
article = Ticket::Article.create(test[:create][:article])
|
ticket.update_attributes(
|
||||||
test[:check][1][:o_id] = article.id
|
title: 'Unit Test 2 (äöüß) - update!',
|
||||||
test[:check][1][:created_at] = article.created_at
|
priority_id: Ticket::Priority.lookup(name: '2 normal').id,
|
||||||
test[:check][1][:created_by_id] = current_user.id
|
)
|
||||||
|
|
||||||
assert_equal(ticket.class.to_s, 'Ticket')
|
# check activity_stream
|
||||||
assert_equal(article.class.to_s, 'Ticket::Article')
|
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_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_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_at'].to_s, ticket.created_at.to_s)
|
||||||
|
assert_equal(stream[2]['object'], 'Ticket')
|
||||||
|
assert_equal(stream[2]['type'], 'create')
|
||||||
|
assert_not(stream[3])
|
||||||
|
|
||||||
# update ticket
|
stream = current_user.activity_stream(4)
|
||||||
if test[:update][:ticket]
|
assert(stream.empty?)
|
||||||
ticket.update_attributes(test[:update][:ticket])
|
|
||||||
|
|
||||||
# check updated user
|
# cleanup
|
||||||
test[:check][3][:o_id] = current_user.id
|
ticket.destroy
|
||||||
test[:check][3][:created_at] = ticket.created_at
|
travel_back
|
||||||
test[:check][3][:created_by_id] = current_user.id
|
|
||||||
end
|
|
||||||
if test[:update2][:ticket]
|
|
||||||
ticket = Ticket.find(ticket.id)
|
|
||||||
ticket.update_attributes(test[:update2][:ticket])
|
|
||||||
end
|
|
||||||
if test[:update][:article]
|
|
||||||
article.update_attributes(test[:update][:article])
|
|
||||||
end
|
|
||||||
|
|
||||||
travel 1.second
|
|
||||||
if test[:update][:ticket]
|
|
||||||
ticket.update_attributes(test[:update][:ticket])
|
|
||||||
end
|
|
||||||
if test[:update2][:ticket]
|
|
||||||
ticket.update_attributes(test[:update2][:ticket])
|
|
||||||
end
|
|
||||||
|
|
||||||
# remember ticket
|
|
||||||
tickets.push ticket
|
|
||||||
|
|
||||||
# check activity_stream
|
|
||||||
activity_stream_check(admin_user.activity_stream(3), test[:check])
|
|
||||||
}
|
|
||||||
|
|
||||||
# delete tickets
|
|
||||||
tickets.each { |ticket|
|
|
||||||
ticket_id = ticket.id
|
|
||||||
ticket.destroy
|
|
||||||
found = Ticket.where(id: ticket_id).first
|
|
||||||
assert_not(found, 'Ticket destroyed')
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'organization' do
|
test 'organization' do
|
||||||
tests = [
|
|
||||||
|
|
||||||
# test 1
|
organization = Organization.create(
|
||||||
{
|
name: 'some name',
|
||||||
create: {
|
updated_by_id: current_user.id,
|
||||||
organization: {
|
created_by_id: current_user.id,
|
||||||
name: 'some name',
|
)
|
||||||
updated_by_id: current_user.id,
|
travel 100.seconds
|
||||||
created_by_id: current_user.id,
|
assert_equal(organization.class, Organization)
|
||||||
},
|
|
||||||
},
|
|
||||||
update1: {
|
|
||||||
organization: {
|
|
||||||
name: 'some name (äöüß)',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
update2: {
|
|
||||||
organization: {
|
|
||||||
name: 'some name 2 (äöüß)',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
check: [
|
|
||||||
{
|
|
||||||
result: true,
|
|
||||||
object: 'Organization',
|
|
||||||
type: 'update',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
result: true,
|
|
||||||
object: 'Organization',
|
|
||||||
type: 'create',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
organizations = []
|
|
||||||
tests.each { |test|
|
|
||||||
|
|
||||||
organization = Organization.create(test[:create][:organization])
|
organization.update_attributes(name: 'some name (äöüß)')
|
||||||
test[:check][0][:o_id] = organization.id
|
updated_at = organization.updated_at
|
||||||
test[:check][0][:created_at] = organization.created_at
|
|
||||||
test[:check][0][:created_by_id] = current_user.id
|
|
||||||
travel 2.seconds
|
|
||||||
|
|
||||||
assert_equal(organization.class.to_s, 'Organization')
|
travel 10.seconds
|
||||||
|
organization.update_attributes(name: 'some name 2 (äöüß)')
|
||||||
|
|
||||||
if test[:update1][:organization]
|
# check activity_stream
|
||||||
organization.update_attributes(test[:update1][:organization])
|
stream = admin_user.activity_stream(3)
|
||||||
test[:check][1][:o_id] = organization.id
|
assert_not(stream[0]['group_id'])
|
||||||
test[:check][1][:updated_at] = organization.updated_at
|
assert_equal(stream[0]['o_id'], organization.id)
|
||||||
test[:check][1][:created_by_id] = current_user.id
|
assert_equal(stream[0]['created_by_id'], current_user.id)
|
||||||
travel 1.second
|
assert_equal(stream[0]['created_at'].to_s, updated_at.to_s)
|
||||||
end
|
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_at'].to_s, organization.created_at.to_s)
|
||||||
|
assert_equal(stream[1]['object'], 'Organization')
|
||||||
|
assert_equal(stream[1]['type'], 'create')
|
||||||
|
assert_not(stream[2])
|
||||||
|
|
||||||
if test[:update2][:organization]
|
stream = current_user.activity_stream(4)
|
||||||
organization.update_attributes(test[:update2][:organization])
|
assert(stream.empty?)
|
||||||
end
|
|
||||||
|
|
||||||
# remember organization
|
# cleanup
|
||||||
organizations.push organization
|
organization.destroy
|
||||||
|
travel_back
|
||||||
# check activity_stream
|
|
||||||
activity_stream_check(admin_user.activity_stream(2), test[:check])
|
|
||||||
}
|
|
||||||
|
|
||||||
# delete tickets
|
|
||||||
organizations.each { |organization|
|
|
||||||
organization_id = organization.id
|
|
||||||
organization.destroy
|
|
||||||
found = Organization.where(id: organization_id).first
|
|
||||||
assert( !found, 'Organization destroyed')
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'user with update check false' do
|
test 'user with update check false' do
|
||||||
tests = [
|
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,
|
||||||
|
)
|
||||||
|
assert_equal(user.class, User)
|
||||||
|
user.update_attributes(
|
||||||
|
firstname: 'Bob U',
|
||||||
|
lastname: 'Smith U',
|
||||||
|
)
|
||||||
|
|
||||||
# test 1
|
# check activity_stream
|
||||||
{
|
stream = admin_user.activity_stream(3)
|
||||||
create: {
|
assert_not(stream[0]['group_id'])
|
||||||
user: {
|
assert_equal(stream[0]['o_id'], user.id)
|
||||||
login: 'someemail@example.com',
|
assert_equal(stream[0]['created_by_id'], current_user.id)
|
||||||
email: 'someemail@example.com',
|
assert_equal(stream[0]['created_at'].to_s, user.created_at.to_s)
|
||||||
firstname: 'Bob Smith II',
|
assert_equal(stream[0]['object'], 'User')
|
||||||
updated_by_id: current_user.id,
|
assert_equal(stream[0]['type'], 'create')
|
||||||
created_by_id: current_user.id,
|
assert_not(stream[1])
|
||||||
},
|
|
||||||
},
|
|
||||||
update1: {
|
|
||||||
user: {
|
|
||||||
firstname: 'Bob U',
|
|
||||||
lastname: 'Smith U',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
check: [
|
|
||||||
{
|
|
||||||
result: true,
|
|
||||||
object: 'User',
|
|
||||||
type: 'create',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
result: false,
|
|
||||||
object: 'User',
|
|
||||||
type: 'update',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
users = []
|
|
||||||
tests.each { |test|
|
|
||||||
|
|
||||||
user = User.create(test[:create][:user])
|
stream = current_user.activity_stream(4)
|
||||||
test[:check][0][:o_id] = user.id
|
assert(stream.empty?)
|
||||||
test[:check][0][:created_at] = user.created_at
|
|
||||||
test[:check][0][:created_by_id] = current_user.id
|
|
||||||
|
|
||||||
assert_equal(user.class.to_s, 'User')
|
# cleanup
|
||||||
|
user.destroy
|
||||||
if test[:update1][:user]
|
travel_back
|
||||||
user.update_attributes(test[:update1][:user])
|
|
||||||
test[:check][1][:o_id] = user.id
|
|
||||||
test[:check][1][:updated_at] = user.updated_at
|
|
||||||
test[:check][1][:created_by_id] = current_user.id
|
|
||||||
end
|
|
||||||
|
|
||||||
# remember organization
|
|
||||||
users.push user
|
|
||||||
|
|
||||||
# check activity_stream
|
|
||||||
activity_stream_check(admin_user.activity_stream(3), test[:check])
|
|
||||||
}
|
|
||||||
|
|
||||||
# delete tickets
|
|
||||||
users.each { |user|
|
|
||||||
user_id = user.id
|
|
||||||
user.destroy
|
|
||||||
found = User.where( id: user_id ).first
|
|
||||||
assert_not(found, 'User destroyed')
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'user with update check true' do
|
test 'user with update check true' do
|
||||||
tests = [
|
|
||||||
|
|
||||||
# test 1
|
user = User.create(
|
||||||
{
|
login: 'someemail@example.com',
|
||||||
create: {
|
email: 'someemail@example.com',
|
||||||
user: {
|
firstname: 'Bob Smith II',
|
||||||
login: 'someemail@example.com',
|
updated_by_id: current_user.id,
|
||||||
email: 'someemail@example.com',
|
created_by_id: current_user.id,
|
||||||
firstname: 'Bob Smith II',
|
)
|
||||||
updated_by_id: current_user.id,
|
travel 100.seconds
|
||||||
created_by_id: current_user.id,
|
assert_equal(user.class, User)
|
||||||
},
|
|
||||||
},
|
|
||||||
update1: {
|
|
||||||
user: {
|
|
||||||
firstname: 'Bob U',
|
|
||||||
lastname: 'Smith U',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
update2: {
|
|
||||||
user: {
|
|
||||||
firstname: 'Bob',
|
|
||||||
lastname: 'Smith',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
check: [
|
|
||||||
{
|
|
||||||
result: true,
|
|
||||||
object: 'User',
|
|
||||||
type: 'update',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
result: true,
|
|
||||||
object: 'User',
|
|
||||||
type: 'create',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
users = []
|
|
||||||
tests.each { |test|
|
|
||||||
|
|
||||||
user = User.create(test[:create][:user])
|
user.update_attributes(
|
||||||
test[:check][0][:o_id] = user.id
|
firstname: 'Bob U',
|
||||||
test[:check][0][:created_at] = user.created_at
|
lastname: 'Smith U',
|
||||||
test[:check][0][:created_by_id] = current_user.id
|
)
|
||||||
|
updated_at = user.updated_at
|
||||||
|
|
||||||
assert_equal(user.class.to_s, 'User')
|
travel 10.seconds
|
||||||
|
user.update_attributes(
|
||||||
|
firstname: 'Bob',
|
||||||
|
lastname: 'Smith',
|
||||||
|
)
|
||||||
|
|
||||||
if test[:update1][:user]
|
# check activity_stream
|
||||||
user.update_attributes(test[:update1][:user])
|
stream = admin_user.activity_stream(3)
|
||||||
test[:check][1][:o_id] = user.id
|
assert_not(stream[0]['group_id'])
|
||||||
test[:check][1][:updated_at] = user.updated_at
|
assert_equal(stream[0]['o_id'], user.id)
|
||||||
test[:check][1][:created_by_id] = current_user.id
|
assert_equal(stream[0]['created_by_id'], current_user.id)
|
||||||
end
|
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_at'].to_s, user.created_at.to_s)
|
||||||
|
assert_equal(stream[1]['object'], 'User')
|
||||||
|
assert_equal(stream[1]['type'], 'create')
|
||||||
|
assert_not(stream[2])
|
||||||
|
|
||||||
# to verify update which need to be logged
|
stream = current_user.activity_stream(4)
|
||||||
travel 1.second
|
assert(stream.empty?)
|
||||||
|
|
||||||
if test[:update2][:user]
|
# cleanup
|
||||||
user.update_attributes(test[:update2][:user])
|
user.destroy
|
||||||
end
|
travel_back
|
||||||
|
|
||||||
# remember organization
|
|
||||||
users.push user
|
|
||||||
|
|
||||||
# check activity_stream
|
|
||||||
activity_stream_check(admin_user.activity_stream(2), test[:check])
|
|
||||||
}
|
|
||||||
|
|
||||||
# delete tickets
|
|
||||||
users.each { |user|
|
|
||||||
user_id = user.id
|
|
||||||
user.destroy
|
|
||||||
found = User.where(id: user_id).first
|
|
||||||
assert(!found, 'User destroyed')
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def activity_stream_check(activity_stream_list, checks)
|
|
||||||
#activity_stream_list = activity_stream_list.reverse
|
|
||||||
#puts 'AS ' + activity_stream_list.inspect
|
|
||||||
check_count = 0
|
|
||||||
checks.each { |check_item|
|
|
||||||
check_count += 1
|
|
||||||
|
|
||||||
#puts '+++++++++++'
|
|
||||||
#puts check_item.inspect
|
|
||||||
check_list = 0
|
|
||||||
activity_stream_list.each { |item|
|
|
||||||
check_list += 1
|
|
||||||
next if check_list != check_count
|
|
||||||
#next if match
|
|
||||||
#puts '--------'
|
|
||||||
#puts item.inspect
|
|
||||||
#puts check_item.inspect
|
|
||||||
if check_item[:result]
|
|
||||||
assert_equal(check_item[:object], item['object'])
|
|
||||||
assert_equal(check_item[:type], item['type'])
|
|
||||||
assert_equal(check_item[:o_id], item['o_id'])
|
|
||||||
elsif check_item[:object] == item['object'] && check_item[:type] == item['type'] && check_item[:o_id] == item['o_id']
|
|
||||||
assert(false, "entry should not exist #{item['object']}/#{item['type']}/#{item['o_id']}")
|
|
||||||
end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ class AssetsTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
roles = Role.where(name: %w(Agent Admin))
|
roles = Role.where(name: %w(Agent Admin))
|
||||||
groups = Group.all
|
groups = Group.all
|
||||||
org = Organization.create_or_update(
|
org1 = Organization.create_or_update(
|
||||||
name: 'some user org',
|
name: 'some user org',
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
|
@ -21,7 +21,7 @@ class AssetsTest < ActiveSupport::TestCase
|
||||||
active: true,
|
active: true,
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
organization_id: org.id,
|
organization_id: org1.id,
|
||||||
roles: roles,
|
roles: roles,
|
||||||
groups: groups,
|
groups: groups,
|
||||||
)
|
)
|
||||||
|
@ -54,10 +54,10 @@ class AssetsTest < ActiveSupport::TestCase
|
||||||
user3 = User.find(user3.id)
|
user3 = User.find(user3.id)
|
||||||
assets = user3.assets({})
|
assets = user3.assets({})
|
||||||
|
|
||||||
org = Organization.find(org.id)
|
org1 = Organization.find(org1.id)
|
||||||
attributes = org.attributes_with_associations
|
attributes = org1.attributes_with_associations
|
||||||
attributes.delete('user_ids')
|
attributes.delete('user_ids')
|
||||||
assert( diff(attributes, assets[:Organization][org.id]), 'check assets')
|
assert( diff(attributes, assets[:Organization][org1.id]), 'check assets')
|
||||||
|
|
||||||
user1 = User.find(user1.id)
|
user1 = User.find(user1.id)
|
||||||
attributes = user1.attributes_with_associations
|
attributes = user1.attributes_with_associations
|
||||||
|
@ -85,7 +85,7 @@ class AssetsTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
# touch org, check if user1 has changed
|
# touch org, check if user1 has changed
|
||||||
travel 2.seconds
|
travel 2.seconds
|
||||||
org2 = Organization.find(org.id)
|
org2 = Organization.find(org1.id)
|
||||||
org2.note = "some note...#{rand(9_999_999_999_999)}"
|
org2.note = "some note...#{rand(9_999_999_999_999)}"
|
||||||
org2.save
|
org2.save
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class AssetsTest < ActiveSupport::TestCase
|
||||||
assets = user3.assets({})
|
assets = user3.assets({})
|
||||||
attributes = org2.attributes_with_associations
|
attributes = org2.attributes_with_associations
|
||||||
attributes.delete('user_ids')
|
attributes.delete('user_ids')
|
||||||
assert( diff(attributes, assets[:Organization][org.id]), 'check assets')
|
assert( diff(attributes, assets[:Organization][org1.id]), 'check assets')
|
||||||
|
|
||||||
user1 = User.find(user1.id)
|
user1 = User.find(user1.id)
|
||||||
attributes = user1.attributes_with_associations
|
attributes = user1.attributes_with_associations
|
||||||
|
@ -130,6 +130,13 @@ class AssetsTest < ActiveSupport::TestCase
|
||||||
attributes.delete('token_ids')
|
attributes.delete('token_ids')
|
||||||
attributes.delete('authorization_ids')
|
attributes.delete('authorization_ids')
|
||||||
assert( diff(attributes, assets[:User][user3.id]), 'check assets' )
|
assert( diff(attributes, assets[:User][user3.id]), 'check assets' )
|
||||||
|
travel_back
|
||||||
|
|
||||||
|
user1.destroy
|
||||||
|
user2.destroy
|
||||||
|
user3.destroy
|
||||||
|
org1.destroy
|
||||||
|
org2.destroy
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -148,8 +155,8 @@ class AssetsTest < ActiveSupport::TestCase
|
||||||
roles: roles,
|
roles: roles,
|
||||||
)
|
)
|
||||||
|
|
||||||
roles = Role.where( name: %w(Customer) )
|
roles = Role.where( name: %w(Customer) )
|
||||||
org = Organization.create_or_update(
|
org = Organization.create_or_update(
|
||||||
name: 'some customer org',
|
name: 'some customer org',
|
||||||
updated_by_id: admin1.id,
|
updated_by_id: admin1.id,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
|
@ -261,6 +268,13 @@ class AssetsTest < ActiveSupport::TestCase
|
||||||
attributes.delete('token_ids')
|
attributes.delete('token_ids')
|
||||||
attributes.delete('authorization_ids')
|
attributes.delete('authorization_ids')
|
||||||
assert( diff(attributes, assets[:User][user_new_2.id]), 'check assets' )
|
assert( diff(attributes, assets[:User][user_new_2.id]), 'check assets' )
|
||||||
|
travel_back
|
||||||
|
|
||||||
|
user1.destroy
|
||||||
|
user2.destroy
|
||||||
|
user3.destroy
|
||||||
|
org.destroy
|
||||||
|
org_new.destroy
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ class CalendarTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
assert_equal(true, calendar2.default)
|
assert_equal(true, calendar2.default)
|
||||||
assert_equal(false, calendar3.default)
|
assert_equal(false, calendar3.default)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -351,7 +351,7 @@ class ChatTest < ActiveSupport::TestCase
|
||||||
assert_equal(1, agent_state[:seads_available])
|
assert_equal(1, agent_state[:seads_available])
|
||||||
assert_equal(4, agent_state[:seads_total])
|
assert_equal(4, agent_state[:seads_total])
|
||||||
assert_equal(false, agent_state[:active])
|
assert_equal(false, agent_state[:active])
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,6 +32,8 @@ class EmailProcessBounceTest < ActiveSupport::TestCase
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string)
|
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
assert_equal(ticket.id, ticket_p.id)
|
assert_equal(ticket.id, ticket_p.id)
|
||||||
assert_equal('new', ticket_p.state.name)
|
assert_equal('new', ticket_p.state.name)
|
||||||
|
travel_back
|
||||||
|
ticket.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -125,6 +125,7 @@ no reference "
|
||||||
travel 1.second
|
travel 1.second
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_references2)
|
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_references2)
|
||||||
assert_not_equal(ticket.id, ticket_p.id)
|
assert_not_equal(ticket.id, ticket_p.id)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'process with follow up check with two external reference headers' do
|
test 'process with follow up check with two external reference headers' do
|
||||||
|
@ -166,7 +167,7 @@ test 123
|
||||||
assert_equal(ticket_p2.id, ticket_p3.id)
|
assert_equal(ticket_p2.id, ticket_p3.id)
|
||||||
|
|
||||||
Setting.set('postmaster_follow_up_search_in', setting_orig)
|
Setting.set('postmaster_follow_up_search_in', setting_orig)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'process with follow up check - with auto responses and no T# in subject_build' do
|
test 'process with follow up check - with auto responses and no T# in subject_build' do
|
||||||
|
@ -211,6 +212,7 @@ Some Text"
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal(ticket.id, ticket_p.id)
|
assert_equal(ticket.id, ticket_p.id)
|
||||||
assert_equal('open', ticket.state.name)
|
assert_equal('open', ticket.state.name)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'process with follow up check - email with more forgein T#\'s in subject' do
|
test 'process with follow up check - email with more forgein T#\'s in subject' do
|
||||||
|
@ -255,6 +257,7 @@ Some Text"
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal(ticket.id, ticket_p.id)
|
assert_equal(ticket.id, ticket_p.id)
|
||||||
assert_equal('open', ticket.state.name)
|
assert_equal('open', ticket.state.name)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'process with follow up check - ticket initiated by customer without T# in subject and other people in Cc reply to all' do
|
test 'process with follow up check - ticket initiated by customer without T# in subject and other people in Cc reply to all' do
|
||||||
|
|
|
@ -86,7 +86,7 @@ Some Text"
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal(ticket.id, ticket_p.id)
|
assert_equal(ticket.id, ticket_p.id)
|
||||||
assert_equal('closed', ticket.state.name)
|
assert_equal('closed', ticket.state.name)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'process with out of office check - zimbra' do
|
test 'process with out of office check - zimbra' do
|
||||||
|
@ -164,7 +164,7 @@ Some Text"
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal(ticket.id, ticket_p.id)
|
assert_equal(ticket.id, ticket_p.id)
|
||||||
assert_equal('closed', ticket.state.name)
|
assert_equal('closed', ticket.state.name)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'process with out of office check - cloud' do
|
test 'process with out of office check - cloud' do
|
||||||
|
@ -237,7 +237,7 @@ Some Text"
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal(ticket.id, ticket_p.id)
|
assert_equal(ticket.id, ticket_p.id)
|
||||||
assert_equal('closed', ticket.state.name)
|
assert_equal('closed', ticket.state.name)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'process with out of office check - gmail' do
|
test 'process with out of office check - gmail' do
|
||||||
|
@ -294,6 +294,7 @@ Some Text 2"
|
||||||
ticket = Ticket.find(ticket.id)
|
ticket = Ticket.find(ticket.id)
|
||||||
assert_equal(ticket.id, ticket_p.id)
|
assert_equal(ticket.id, ticket_p.id)
|
||||||
assert_equal('open', ticket_p.state.name)
|
assert_equal('open', ticket_p.state.name)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,5 +123,6 @@ class OrganizationRefObjectTouchTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
delete = ticket.destroy
|
delete = ticket.destroy
|
||||||
assert(delete, 'ticket destroy')
|
assert(delete, 'ticket destroy')
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -123,4 +123,48 @@ class PermissionTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'user permission with childs' do
|
||||||
|
|
||||||
|
permission1 = Permission.create_or_update(
|
||||||
|
name: 'admin.permission_child1',
|
||||||
|
note: 'Admin Interface',
|
||||||
|
preferences: {},
|
||||||
|
active: true,
|
||||||
|
)
|
||||||
|
permission2 = Permission.create_or_update(
|
||||||
|
name: 'admin.permission_child2',
|
||||||
|
note: 'Admin Interface',
|
||||||
|
preferences: {},
|
||||||
|
active: false,
|
||||||
|
)
|
||||||
|
role_permission1 = Role.create_or_update(
|
||||||
|
name: 'AdminPermissionChild1',
|
||||||
|
note: 'To configure your permission child1.',
|
||||||
|
preferences: {
|
||||||
|
not: ['Customer'],
|
||||||
|
},
|
||||||
|
default_at_signup: false,
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
role_permission1.permission_grand('admin')
|
||||||
|
user_with_permission1 = User.create_or_update(
|
||||||
|
login: 'setting-permission-child1',
|
||||||
|
firstname: 'Setting',
|
||||||
|
lastname: 'Admin Permission Child1',
|
||||||
|
email: 'setting-admin-permission-child1@example.com',
|
||||||
|
password: 'some_pw',
|
||||||
|
active: true,
|
||||||
|
roles: [role_permission1],
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
assert(user_with_permission1.permissions_with_child_ids.include?(permission1.id))
|
||||||
|
assert_not(user_with_permission1.permissions_with_child_ids.include?(permission2.id))
|
||||||
|
assert(user_with_permission1.permissions_with_child_ids.include?(Permission.find_by(name: 'admin').id))
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
user_with_permission1.destroy
|
||||||
|
role_permission1.destroy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,6 +54,7 @@ class RecentViewTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
list = RecentView.list(user1)
|
list = RecentView.list(user1)
|
||||||
assert(!list[0], 'check if recent view list is empty')
|
assert(!list[0], 'check if recent view list is empty')
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'existing tests' do
|
test 'existing tests' do
|
||||||
|
|
|
@ -50,6 +50,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
||||||
Sessions::CacheIn.delete('last_run_delete')
|
Sessions::CacheIn.delete('last_run_delete')
|
||||||
result = Sessions::CacheIn.get('last_run_delete')
|
result = Sessions::CacheIn.get('last_run_delete')
|
||||||
assert_equal(nil, nil, 'check delete')
|
assert_equal(nil, nil, 'check delete')
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'c session create / update' do
|
test 'c session create / update' do
|
||||||
|
@ -184,6 +185,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
||||||
result2 = collection_client2.push
|
result2 = collection_client2.push
|
||||||
assert(!result2, 'check collections - after destroy - recall')
|
assert(!result2, 'check collections - after destroy - recall')
|
||||||
assert_equal(result1, result2, 'check collections')
|
assert_equal(result1, result2, 'check collections')
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'c activity stream' do
|
test 'c activity stream' do
|
||||||
|
@ -206,6 +208,14 @@ class SessionBasicTest < ActiveSupport::TestCase
|
||||||
agent1.roles = roles
|
agent1.roles = roles
|
||||||
assert(agent1.save, 'create/update agent1')
|
assert(agent1.save, 'create/update agent1')
|
||||||
|
|
||||||
|
# create min. on activity record
|
||||||
|
random_name = "Random:#{rand(9_999_999_999)}"
|
||||||
|
Group.create_or_update(
|
||||||
|
name: random_name,
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
|
||||||
as_client1 = Sessions::Backend::ActivityStream.new(agent1, {}, false, '123-1', 3)
|
as_client1 = Sessions::Backend::ActivityStream.new(agent1, {}, false, '123-1', 3)
|
||||||
|
|
||||||
# get as stream
|
# get as stream
|
||||||
|
@ -230,6 +240,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
||||||
# get as stream
|
# get as stream
|
||||||
result1 = as_client1.push
|
result1 = as_client1.push
|
||||||
assert( result1, 'check as agent1 - recall 3')
|
assert( result1, 'check as agent1 - recall 3')
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'c ticket_create' do
|
test 'c ticket_create' do
|
||||||
|
@ -259,6 +270,7 @@ class SessionBasicTest < ActiveSupport::TestCase
|
||||||
# get as stream
|
# get as stream
|
||||||
result1 = ticket_create_client1.push
|
result1 = ticket_create_client1.push
|
||||||
assert(result1, 'check ticket_create - recall 3')
|
assert(result1, 'check ticket_create - recall 3')
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,6 +70,7 @@ class SessionBasicTicketTest < ActiveSupport::TestCase
|
||||||
Sessions::Backend::TicketOverviewList.reset(user.id)
|
Sessions::Backend::TicketOverviewList.reset(user.id)
|
||||||
result1 = client1.push
|
result1 = client1.push
|
||||||
assert(result1, 'check ticket_overview_index - recall 7')
|
assert(result1, 'check ticket_overview_index - recall 7')
|
||||||
|
travel_back
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,7 @@ class SessionCollectionsTest < ActiveSupport::TestCase
|
||||||
assert(result2.empty?, 'check collections - recall')
|
assert(result2.empty?, 'check collections - recall')
|
||||||
result3 = collection_client3.push
|
result3 = collection_client3.push
|
||||||
assert(result3.empty?, 'check collections - recall')
|
assert(result3.empty?, 'check collections - recall')
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_if_collection_exists(results, collection, attributes = nil)
|
def check_if_collection_exists(results, collection, attributes = nil)
|
||||||
|
|
|
@ -242,17 +242,17 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
||||||
'Group' => true,
|
'Group' => true,
|
||||||
'User' => nil,
|
'User' => nil,
|
||||||
}
|
}
|
||||||
check_if_collection_reset_message_exists(client_id1_0, collections, 'init')
|
assert_if_collection_reset_message_exists(client_id1_0, collections, 'init')
|
||||||
check_if_collection_reset_message_exists(client_id1_1, collections, 'init')
|
assert_if_collection_reset_message_exists(client_id1_1, collections, 'init')
|
||||||
check_if_collection_reset_message_exists(client_id2, collections, 'init')
|
assert_if_collection_reset_message_exists(client_id2, collections, 'init')
|
||||||
|
|
||||||
collections = {
|
collections = {
|
||||||
'Group' => nil,
|
'Group' => nil,
|
||||||
'User' => nil,
|
'User' => nil,
|
||||||
}
|
}
|
||||||
check_if_collection_reset_message_exists(client_id1_0, collections, 'init2')
|
assert_if_collection_reset_message_exists(client_id1_0, collections, 'init2')
|
||||||
check_if_collection_reset_message_exists(client_id1_1, collections, 'init2')
|
assert_if_collection_reset_message_exists(client_id1_1, collections, 'init2')
|
||||||
check_if_collection_reset_message_exists(client_id2, collections, 'init2')
|
assert_if_collection_reset_message_exists(client_id2, collections, 'init2')
|
||||||
|
|
||||||
sleep 8
|
sleep 8
|
||||||
|
|
||||||
|
@ -260,9 +260,9 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
||||||
'Group' => nil,
|
'Group' => nil,
|
||||||
'User' => nil,
|
'User' => nil,
|
||||||
}
|
}
|
||||||
check_if_collection_reset_message_exists(client_id1_0, collections, 'init3')
|
assert_if_collection_reset_message_exists(client_id1_0, collections, 'init3')
|
||||||
check_if_collection_reset_message_exists(client_id1_1, collections, 'init3')
|
assert_if_collection_reset_message_exists(client_id1_1, collections, 'init3')
|
||||||
check_if_collection_reset_message_exists(client_id2, collections, 'init3')
|
assert_if_collection_reset_message_exists(client_id2, collections, 'init3')
|
||||||
|
|
||||||
# change collection
|
# change collection
|
||||||
group = Group.first
|
group = Group.first
|
||||||
|
@ -275,9 +275,9 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
||||||
'Group' => true,
|
'Group' => true,
|
||||||
'User' => nil,
|
'User' => nil,
|
||||||
}
|
}
|
||||||
check_if_collection_reset_message_exists(client_id1_0, collections, 'update')
|
assert_if_collection_reset_message_exists(client_id1_0, collections, 'update')
|
||||||
check_if_collection_reset_message_exists(client_id1_1, collections, 'update')
|
assert_if_collection_reset_message_exists(client_id1_1, collections, 'update')
|
||||||
check_if_collection_reset_message_exists(client_id2, collections, 'update')
|
assert_if_collection_reset_message_exists(client_id2, collections, 'update')
|
||||||
|
|
||||||
# check if session still exists after idle cleanup
|
# check if session still exists after idle cleanup
|
||||||
sleep 4
|
sleep 4
|
||||||
|
@ -290,7 +290,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_if_collection_reset_message_exists(client_id, collections_orig, type)
|
def assert_if_collection_reset_message_exists(client_id, collections_orig, type)
|
||||||
messages = Sessions.queue(client_id)
|
messages = Sessions.queue(client_id)
|
||||||
#puts "cid: #{client_id}"
|
#puts "cid: #{client_id}"
|
||||||
#puts "m: #{messages.inspect}"
|
#puts "m: #{messages.inspect}"
|
||||||
|
@ -309,7 +309,7 @@ class SessionEnhancedTest < ActiveSupport::TestCase
|
||||||
}
|
}
|
||||||
#puts "c: #{collections_result.inspect}"
|
#puts "c: #{collections_result.inspect}"
|
||||||
collections_orig.each { |key, _value|
|
collections_orig.each { |key, _value|
|
||||||
assert_equal( collections_orig[key], collections_result[key], "collection message for #{key} #{type}-check (client_id #{client_id})" )
|
assert_equal(collections_orig[key], collections_result[key], "collection message for #{key} #{type}-check (client_id #{client_id})")
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -359,6 +359,6 @@ class TagTest < ActiveSupport::TestCase
|
||||||
assert_not_equal(ticket1_lookup4.updated_at.to_s, ticket1_lookup3.updated_at.to_s)
|
assert_not_equal(ticket1_lookup4.updated_at.to_s, ticket1_lookup3.updated_at.to_s)
|
||||||
ticket2_lookup4 = Ticket.lookup(id: ticket2.id)
|
ticket2_lookup4 = Ticket.lookup(id: ticket2.id)
|
||||||
assert_not_equal(ticket2_lookup4.updated_at.to_s, ticket2_lookup3.updated_at.to_s)
|
assert_not_equal(ticket2_lookup4.updated_at.to_s, ticket2_lookup3.updated_at.to_s)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -452,6 +452,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
|
||||||
assert_equal(result[2][:tickets].class, Array)
|
assert_equal(result[2][:tickets].class, Array)
|
||||||
assert(result[2][:tickets].empty?)
|
assert(result[2][:tickets].empty?)
|
||||||
|
|
||||||
|
travel 1.second # because of mysql millitime issues
|
||||||
ticket2 = Ticket.create(
|
ticket2 = Ticket.create(
|
||||||
title: 'overview test 2',
|
title: 'overview test 2',
|
||||||
group: Group.lookup(name: 'OverviewTest'),
|
group: Group.lookup(name: 'OverviewTest'),
|
||||||
|
@ -548,7 +549,7 @@ class TicketOverviewTest < ActiveSupport::TestCase
|
||||||
assert_equal(result[2][:tickets].class, Array)
|
assert_equal(result[2][:tickets].class, Array)
|
||||||
assert(result[2][:tickets].empty?)
|
assert(result[2][:tickets].empty?)
|
||||||
|
|
||||||
travel_to Time.zone.now + 1.second # because of mysql millitime issues
|
travel 1.second # because of mysql millitime issues
|
||||||
ticket3 = Ticket.create(
|
ticket3 = Ticket.create(
|
||||||
title: 'overview test 3',
|
title: 'overview test 3',
|
||||||
group: Group.lookup(name: 'OverviewTest'),
|
group: Group.lookup(name: 'OverviewTest'),
|
||||||
|
|
|
@ -109,11 +109,12 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase
|
||||||
else
|
else
|
||||||
assert(false, 'organization1.updated_at has not been updated')
|
assert(false, 'organization1.updated_at has not been updated')
|
||||||
end
|
end
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'c - check if customer (not organization) has been updated' do
|
test 'c - check if customer (not organization) has been updated' do
|
||||||
|
|
||||||
travel 6.seconds
|
travel 8.seconds
|
||||||
ticket = Ticket.create(
|
ticket = Ticket.create(
|
||||||
title: "some title2\n äöüß",
|
title: "some title2\n äöüß",
|
||||||
group: Group.lookup(name: 'Users'),
|
group: Group.lookup(name: 'Users'),
|
||||||
|
@ -162,6 +163,6 @@ class TicketRefObjectTouchTest < ActiveSupport::TestCase
|
||||||
else
|
else
|
||||||
assert(true, 'organization1.updated_at has not been updated')
|
assert(true, 'organization1.updated_at has not been updated')
|
||||||
end
|
end
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -995,7 +995,7 @@ class TicketSelectorTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
ticket_count, tickets = Ticket.selectors(condition, 10)
|
ticket_count, tickets = Ticket.selectors(condition, 10)
|
||||||
assert_equal(ticket_count, 0)
|
assert_equal(ticket_count, 0)
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -193,6 +193,7 @@ class TicketTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
delete = ticket.destroy
|
delete = ticket.destroy
|
||||||
assert(delete, 'ticket destroy')
|
assert(delete, 'ticket destroy')
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'ticket latest change' do
|
test 'ticket latest change' do
|
||||||
|
@ -207,7 +208,7 @@ class TicketTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
assert_equal(Ticket.latest_change.to_s, ticket1.updated_at.to_s)
|
assert_equal(Ticket.latest_change.to_s, ticket1.updated_at.to_s)
|
||||||
|
|
||||||
travel 1.second
|
travel 1.minute
|
||||||
|
|
||||||
ticket2 = Ticket.create(
|
ticket2 = Ticket.create(
|
||||||
title: 'latest change 2',
|
title: 'latest change 2',
|
||||||
|
@ -220,20 +221,21 @@ class TicketTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
assert_equal(Ticket.latest_change.to_s, ticket2.updated_at.to_s)
|
assert_equal(Ticket.latest_change.to_s, ticket2.updated_at.to_s)
|
||||||
|
|
||||||
travel 1.second
|
travel 1.minute
|
||||||
|
|
||||||
ticket1.title = 'latest change 1 - 1'
|
ticket1.title = 'latest change 1 - 1'
|
||||||
ticket1.save
|
ticket1.save
|
||||||
assert_equal(Ticket.latest_change.to_s, ticket1.updated_at.to_s)
|
assert_equal(Ticket.latest_change.to_s, ticket1.updated_at.to_s)
|
||||||
|
|
||||||
travel 1.second
|
travel 1.minute
|
||||||
|
|
||||||
ticket1.touch
|
ticket1.touch
|
||||||
assert_equal(Ticket.latest_change.to_s, ticket1.updated_at.to_s)
|
assert_equal(Ticket.latest_change.to_s, ticket1.updated_at.to_s)
|
||||||
|
|
||||||
ticket1.destroy
|
ticket1.destroy
|
||||||
assert_equal(Ticket.latest_change.to_s, ticket2.updated_at.to_s)
|
assert_equal(Ticket.latest_change.to_s, ticket2.updated_at.to_s)
|
||||||
|
ticket2.destroy
|
||||||
|
travel_back
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'ticket process_pending' do
|
test 'ticket process_pending' do
|
||||||
|
|
Loading…
Reference in a new issue