2014-07-13 18:52:32 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class SessionBasicTest < ActiveSupport::TestCase
|
2016-05-17 07:37:25 +00:00
|
|
|
|
2016-06-20 08:55:45 +00:00
|
|
|
test 'b cache' do
|
2016-05-21 16:19:34 +00:00
|
|
|
Sessions::CacheIn.set('last_run_test', true, { expires_in: 1.second })
|
2016-03-03 08:56:13 +00:00
|
|
|
result = Sessions::CacheIn.get('last_run_test')
|
|
|
|
assert_equal(true, result, 'check 1')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# should not be expired
|
2016-03-03 08:56:13 +00:00
|
|
|
result = Sessions::CacheIn.expired('last_run_test')
|
|
|
|
assert_equal(false, result, 'check 1 - expired')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# should be expired
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 2.seconds
|
2016-03-03 08:56:13 +00:00
|
|
|
result = Sessions::CacheIn.expired('last_run_test')
|
|
|
|
assert_equal(true, result, 'check 1 - expired')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# renew expire
|
2016-03-03 08:56:13 +00:00
|
|
|
result = Sessions::CacheIn.get('last_run_test', re_expire: true)
|
|
|
|
assert_equal(true, result, 'check 1 - re_expire')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# should not be expired
|
2016-03-03 08:56:13 +00:00
|
|
|
result = Sessions::CacheIn.expired('last_run_test')
|
|
|
|
assert_equal(false, result, 'check 1 - expired')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# ignore expired
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 2.seconds
|
2016-03-03 08:56:13 +00:00
|
|
|
result = Sessions::CacheIn.get('last_run_test', ignore_expire: true)
|
|
|
|
assert_equal(true, result, 'check 1 - ignore_expire')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# should be expired
|
2016-03-03 08:56:13 +00:00
|
|
|
result = Sessions::CacheIn.expired('last_run_test')
|
|
|
|
assert_equal(true, result, 'check 2')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2016-03-03 08:56:13 +00:00
|
|
|
result = Sessions::CacheIn.get('last_run_test')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(result, 'check 2')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# check delete cache
|
2016-03-03 08:56:13 +00:00
|
|
|
Sessions::CacheIn.set('last_run_delete', true, { expires_in: 5.seconds })
|
|
|
|
result = Sessions::CacheIn.get('last_run_delete')
|
|
|
|
assert_equal(true, result, 'check 1')
|
|
|
|
Sessions::CacheIn.delete('last_run_delete')
|
|
|
|
result = Sessions::CacheIn.get('last_run_delete')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(result, 'check delete')
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2014-07-13 18:52:32 +00:00
|
|
|
end
|
|
|
|
|
2015-05-03 12:11:47 +00:00
|
|
|
test 'c session create / update' do
|
|
|
|
|
|
|
|
# create users
|
2017-11-23 08:09:44 +00:00
|
|
|
roles = Role.where(name: %w[Agent])
|
2015-05-03 12:11:47 +00:00
|
|
|
groups = Group.all
|
|
|
|
|
|
|
|
agent1 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'session-agent-1',
|
|
|
|
firstname: 'Session',
|
|
|
|
lastname: 'Agent 1',
|
|
|
|
email: 'session-agent1@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2017-06-16 22:53:20 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-05-03 12:11:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# create sessions
|
|
|
|
client_id1 = '123456789'
|
2016-03-03 08:56:13 +00:00
|
|
|
Sessions.create(client_id1, {}, { type: 'websocket' })
|
2015-05-03 12:11:47 +00:00
|
|
|
|
|
|
|
# check if session exists
|
2016-03-03 08:56:13 +00:00
|
|
|
assert(Sessions.session_exists?(client_id1), 'check if session exists')
|
2015-05-03 12:11:47 +00:00
|
|
|
|
|
|
|
# check session data
|
|
|
|
data = Sessions.get(client_id1)
|
2016-03-03 08:56:13 +00:00
|
|
|
assert(data[:meta], 'check if meta exists')
|
|
|
|
assert(data[:user], 'check if user exists')
|
2017-03-24 10:02:13 +00:00
|
|
|
assert_nil(data[:user]['id'], 'check if user id is correct')
|
2015-05-03 12:11:47 +00:00
|
|
|
|
|
|
|
# recreate session
|
2016-03-03 08:56:13 +00:00
|
|
|
Sessions.create(client_id1, agent1.attributes, { type: 'websocket' })
|
2015-05-03 12:11:47 +00:00
|
|
|
|
|
|
|
# check if session exists
|
2016-03-03 08:56:13 +00:00
|
|
|
assert(Sessions.session_exists?(client_id1), 'check if session exists')
|
2015-05-03 12:11:47 +00:00
|
|
|
|
|
|
|
# check session data
|
|
|
|
data = Sessions.get(client_id1)
|
2016-03-03 08:56:13 +00:00
|
|
|
assert(data[:meta], 'check if meta exists')
|
|
|
|
assert(data[:user], 'check if user exists')
|
|
|
|
assert_equal(data[:user]['id'], agent1.id, 'check if user id is correct')
|
2015-05-03 12:11:47 +00:00
|
|
|
|
|
|
|
# destroy session
|
2016-11-30 10:30:03 +00:00
|
|
|
Sessions.destroy(client_id1)
|
2015-05-03 12:11:47 +00:00
|
|
|
|
|
|
|
# check if session exists
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(Sessions.session_exists?(client_id1), 'check if session exists')
|
2015-05-03 12:11:47 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'c collections group' do
|
2014-07-13 18:52:32 +00:00
|
|
|
require 'sessions/backend/collections/group.rb'
|
2014-07-14 05:26:22 +00:00
|
|
|
|
2017-06-16 22:53:20 +00:00
|
|
|
# create users
|
|
|
|
roles = Role.where(name: ['Agent'])
|
|
|
|
groups = Group.all
|
|
|
|
|
|
|
|
agent1 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'session-collection-agent-1',
|
|
|
|
firstname: 'Session',
|
|
|
|
lastname: 'Agent 1',
|
|
|
|
email: 'session-collection-agent1@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2017-06-16 22:53:20 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
collection_client1 = Sessions::Backend::Collections::Group.new(agent1, {}, false, '123-1', 3)
|
|
|
|
collection_client2 = Sessions::Backend::Collections::Group.new(agent1, {}, false, '234-2', 3)
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# get whole collections
|
|
|
|
result1 = collection_client1.push
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result1.present?, 'check collections')
|
2015-02-25 22:35:00 +00:00
|
|
|
sleep 0.6
|
2014-07-13 18:52:32 +00:00
|
|
|
result2 = collection_client2.push
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result2.present?, 'check collections')
|
2017-09-08 08:28:34 +00:00
|
|
|
assert_equal(result1, result2, 'check collections')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# next check should be empty
|
|
|
|
result1 = collection_client1.push
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result1, 'check collections - recall')
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 1.second
|
2014-07-13 18:52:32 +00:00
|
|
|
result2 = collection_client2.push
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result2, 'check collections - recall')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# change collection
|
|
|
|
group = Group.first
|
2017-06-16 22:53:20 +00:00
|
|
|
travel 4.seconds
|
2014-07-13 18:52:32 +00:00
|
|
|
group.touch
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 4.seconds
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# get whole collections
|
|
|
|
result1 = collection_client1.push
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result1.present?, 'check collections - after touch')
|
2017-06-16 22:53:20 +00:00
|
|
|
|
2014-07-13 18:52:32 +00:00
|
|
|
result2 = collection_client2.push
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result2.present?, 'check collections - after touch')
|
2017-09-08 08:28:34 +00:00
|
|
|
assert_equal(result1, result2, 'check collections')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# check again after touch
|
|
|
|
result1 = collection_client1.push
|
2017-05-02 20:58:56 +00:00
|
|
|
assert_nil(result1, 'check collections - after touch - recall')
|
2014-07-13 18:52:32 +00:00
|
|
|
result2 = collection_client2.push
|
2017-05-02 20:58:56 +00:00
|
|
|
assert_nil(result2, 'check collections - after touch - recall')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# change collection
|
2017-06-16 22:53:20 +00:00
|
|
|
group = Group.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: "SomeGroup::#{rand(999_999)}",
|
|
|
|
active: true,
|
2017-06-16 22:53:20 +00:00
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1,
|
2017-06-16 20:43:09 +00:00
|
|
|
)
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 4.seconds
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# get whole collections
|
|
|
|
result1 = collection_client1.push
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result1.present?, 'check collections - after create')
|
2014-07-13 18:52:32 +00:00
|
|
|
result2 = collection_client2.push
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result2.present?, 'check collections - after create')
|
2016-03-03 08:56:13 +00:00
|
|
|
assert_equal(result1, result2, 'check collections')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# check again after create
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 4.seconds
|
2014-07-13 18:52:32 +00:00
|
|
|
result1 = collection_client1.push
|
2017-05-02 20:58:56 +00:00
|
|
|
assert_nil(result1, 'check collections - after create - recall')
|
2014-07-13 18:52:32 +00:00
|
|
|
result2 = collection_client2.push
|
2017-05-02 20:58:56 +00:00
|
|
|
assert_nil(result2, 'check collections - after create - recall')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# change collection
|
|
|
|
group.destroy
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 4.seconds
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# get whole collections
|
|
|
|
result1 = collection_client1.push
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result1.present?, 'check collections - after destroy')
|
2014-07-13 18:52:32 +00:00
|
|
|
result2 = collection_client2.push
|
2017-11-23 08:09:44 +00:00
|
|
|
assert(result2.present?, 'check collections - after destroy')
|
2016-03-03 08:56:13 +00:00
|
|
|
assert_equal(result1, result2, 'check collections')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# check again after destroy
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 4.seconds
|
2014-07-13 18:52:32 +00:00
|
|
|
result1 = collection_client1.push
|
2017-05-02 20:58:56 +00:00
|
|
|
assert_nil(result1, 'check collections - after destroy - recall')
|
2014-07-13 18:52:32 +00:00
|
|
|
result2 = collection_client2.push
|
2017-05-02 20:58:56 +00:00
|
|
|
assert_nil(result2, 'check collections - after destroy - recall')
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2014-07-13 18:52:32 +00:00
|
|
|
end
|
|
|
|
|
2015-05-03 12:11:47 +00:00
|
|
|
test 'c activity stream' do
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# create users
|
2017-11-23 08:09:44 +00:00
|
|
|
roles = Role.where(name: %w[Agent Admin])
|
2014-07-13 18:52:32 +00:00
|
|
|
groups = Group.all
|
|
|
|
|
|
|
|
agent1 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'activity-stream-agent-1',
|
|
|
|
firstname: 'Session',
|
|
|
|
lastname: "activity stream #{rand(99_999)}",
|
|
|
|
email: 'activity-stream-agent1@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2017-06-16 22:53:20 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2014-07-13 18:52:32 +00:00
|
|
|
)
|
|
|
|
|
2016-12-08 14:06:54 +00:00
|
|
|
# create min. on activity record
|
|
|
|
random_name = "Random:#{rand(9_999_999_999)}"
|
|
|
|
Group.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: random_name,
|
2016-12-08 14:06:54 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
2016-09-08 06:44:40 +00:00
|
|
|
as_client1 = Sessions::Backend::ActivityStream.new(agent1, {}, false, '123-1', 3)
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# get as stream
|
|
|
|
result1 = as_client1.push
|
2016-03-03 08:56:13 +00:00
|
|
|
assert(result1, 'check as agent1')
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 1.second
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# next check should be empty
|
|
|
|
result1 = as_client1.push
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result1, 'check as agent1 - recall')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# next check should be empty
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 4.seconds
|
2014-07-13 18:52:32 +00:00
|
|
|
result1 = as_client1.push
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result1, 'check as agent1 - recall 2')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2017-09-11 11:16:08 +00:00
|
|
|
agent1.update!(email: 'activity-stream-agent11@example.com')
|
2017-06-16 23:02:34 +00:00
|
|
|
ticket = Ticket.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
title: '12323',
|
|
|
|
group_id: 1,
|
|
|
|
priority_id: 1,
|
|
|
|
state_id: 1,
|
|
|
|
customer_id: 1,
|
2017-06-16 22:53:20 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 4.seconds
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# get as stream
|
|
|
|
result1 = as_client1.push
|
2016-03-03 08:56:13 +00:00
|
|
|
assert( result1, 'check as agent1 - recall 3')
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2014-07-13 18:52:32 +00:00
|
|
|
end
|
|
|
|
|
2015-05-03 12:11:47 +00:00
|
|
|
test 'c ticket_create' do
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2017-06-16 20:43:09 +00:00
|
|
|
# create users
|
2017-11-23 08:09:44 +00:00
|
|
|
roles = Role.where(name: %w[Agent Admin])
|
2017-06-16 20:43:09 +00:00
|
|
|
groups = Group.all
|
|
|
|
|
|
|
|
agent1 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'ticket_create-agent-1',
|
|
|
|
firstname: 'Session',
|
|
|
|
lastname: "ticket_create #{rand(99_999)}",
|
|
|
|
email: 'ticket_create-agent1@example.com',
|
|
|
|
password: 'agentpw',
|
|
|
|
active: true,
|
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2017-06-16 22:53:20 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2017-06-16 20:43:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
ticket_create_client1 = Sessions::Backend::TicketCreate.new(agent1, {}, false, '123-1', 3)
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# get as stream
|
|
|
|
result1 = ticket_create_client1.push
|
2016-03-03 08:56:13 +00:00
|
|
|
assert(result1, 'check ticket_create')
|
2017-06-16 20:43:09 +00:00
|
|
|
travel 1.second
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# next check should be empty
|
|
|
|
result1 = ticket_create_client1.push
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result1, 'check ticket_create - recall')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# next check should be empty
|
2017-06-16 20:43:09 +00:00
|
|
|
travel 1.second
|
2014-07-13 18:52:32 +00:00
|
|
|
result1 = ticket_create_client1.push
|
2018-10-09 06:17:41 +00:00
|
|
|
assert_not(result1, 'check ticket_create - recall 2')
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2017-06-16 23:02:34 +00:00
|
|
|
Group.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: "SomeTicketCreateGroup::#{rand(999_999)}",
|
|
|
|
active: true,
|
2017-06-16 22:53:20 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
2017-06-16 23:02:34 +00:00
|
|
|
groups = Group.all
|
|
|
|
agent1.groups = groups
|
|
|
|
agent1.save!
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2016-12-07 07:15:56 +00:00
|
|
|
travel 4.seconds
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
# get as stream
|
|
|
|
result1 = ticket_create_client1.push
|
2016-03-03 08:56:13 +00:00
|
|
|
assert(result1, 'check ticket_create - recall 3')
|
2016-12-08 14:06:54 +00:00
|
|
|
travel_back
|
2014-07-13 18:52:32 +00:00
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|