Merged sipgate controller tests into regular controllers tests to increase total speed of tests (no extra job needed). Removed duplicate calendar subscription tickets controller.

This commit is contained in:
Martin Edenhofer 2018-04-23 15:33:29 +02:00
parent 33f0082da6
commit 12c26bcc88
5 changed files with 469 additions and 700 deletions

View file

@ -254,17 +254,6 @@ test:integration:clearbit:
- rake db:drop
allow_failure: true
test:integration:sipgate:
stage: test
tags:
- core
script:
- export RAILS_ENV=test
- rake db:create
- rake db:migrate
- ruby -I test test/integration/sipgate_controller_test.rb
- rake db:drop
test:integration:telegram:
stage: test
tags:

View file

@ -75,7 +75,6 @@ script:
- ruby -I test/ test/integration/geo_calendar_test.rb
- ruby -I test/ test/integration/user_agent_test.rb
- ruby -I test/ test/integration/user_device_controller_test.rb
- ruby -I test/ test/integration/sipgate_controller_test.rb
- rake db:drop
after_success:
- if [ "${DB}" = "mysql" ]; then contrib/travis-ci.org/trigger_docker_image_build.sh; fi

View file

@ -0,0 +1,469 @@
require 'test_helper'
require 'rexml/document'
class IntegrationSipgateControllerTest < ActionDispatch::IntegrationTest
setup do
Cti::Log.destroy_all
Setting.set('sipgate_integration', true)
Setting.set('sipgate_config', {
outbound: {
routing_table: [
{
dest: '41*',
caller_id: '41715880339000',
},
{
dest: '491714000000',
caller_id: '41715880339000',
},
],
default_caller_id: '4930777000000',
},
inbound: {
block_caller_ids: [
{
caller_id: '491715000000',
note: 'some note',
}
],
notify_user_ids: {
2 => true,
4 => false,
},
}
},)
groups = Group.where(name: 'Users')
roles = Role.where(name: %w[Agent])
agent = User.create_or_update(
login: 'cti-agent@example.com',
firstname: 'E',
lastname: 'S',
email: 'cti-agent@example.com',
password: 'agentpw',
active: true,
roles: roles,
groups: groups,
updated_by_id: 1,
created_by_id: 1,
)
customer1 = User.create_or_update(
login: 'ticket-caller_id_sipgate-customer1@example.com',
firstname: 'CallerId',
lastname: 'Customer1',
email: 'ticket-caller_id_sipgate-customer1@example.com',
password: 'customerpw',
active: true,
phone: '+49 99999 222222',
fax: '+49 99999 222223',
mobile: '+4912347114711',
note: 'Phone at home: +49 99999 222224',
updated_by_id: 1,
created_by_id: 1,
)
customer2 = User.create_or_update(
login: 'ticket-caller_id_sipgate-customer2@example.com',
firstname: 'CallerId',
lastname: 'Customer2',
email: 'ticket-caller_id_sipgate-customer2@example.com',
password: 'customerpw',
active: true,
phone: '+49 99999 222222 2',
updated_by_id: 1,
created_by_id: 1,
)
customer3 = User.create_or_update(
login: 'ticket-caller_id_sipgate-customer3@example.com',
firstname: 'CallerId',
lastname: 'Customer3',
email: 'ticket-caller_id_sipgate-customer3@example.com',
password: 'customerpw',
active: true,
phone: '+49 99999 222222 2',
updated_by_id: 1,
created_by_id: 1,
)
Cti::CallerId.rebuild
end
test 'basic call' do
# inbound - I
params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&callId=4991155921769858278-1&user%5B%5D=user+1&user%5B%5D=user+2'
post '/api/v1/sipgate/in', params: params
assert_response(200)
on_hangup = nil
on_answer = nil
content = @response.body
response = REXML::Document.new(content)
response.elements.each('Response') do |element|
on_hangup = element.attributes['onHangup']
on_answer = element.attributes['onAnswer']
end
assert_equal('http://zammad.example.com/api/v1/sipgate/in', on_hangup)
assert_equal('http://zammad.example.com/api/v1/sipgate/in', on_answer)
# inbound - II - block caller
params = 'event=newCall&direction=in&from=491715000000&to=4930600000000&callId=4991155921769858278-2&user%5B%5D=user+1&user%5B%5D=user+2'
post '/api/v1/sipgate/in', params: params
assert_response(200)
on_hangup = nil
on_answer = nil
content = @response.body
response = REXML::Document.new(content)
response.elements.each('Response') do |element|
on_hangup = element.attributes['onHangup']
on_answer = element.attributes['onAnswer']
end
assert_equal('http://zammad.example.com/api/v1/sipgate/in', on_hangup)
assert_equal('http://zammad.example.com/api/v1/sipgate/in', on_answer)
reason = nil
response.elements.each('Response/Reject') do |element|
reason = element.attributes['reason']
end
assert_equal('busy', reason)
# outbound - I - set default_caller_id
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&callId=8621106404543334274-3&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
assert_response(200)
on_hangup = nil
on_answer = nil
caller_id = nil
number_to_dail = nil
content = @response.body
response = REXML::Document.new(content)
response.elements.each('Response') do |element|
on_hangup = element.attributes['onHangup']
on_answer = element.attributes['onAnswer']
end
response.elements.each('Response/Dial') do |element|
caller_id = element.attributes['callerId']
end
response.elements.each('Response/Dial/Number') do |element|
number_to_dail = element.text
end
assert_equal('4930777000000', caller_id)
assert_equal('4912347114711', number_to_dail)
assert_equal('http://zammad.example.com/api/v1/sipgate/out', on_hangup)
assert_equal('http://zammad.example.com/api/v1/sipgate/out', on_answer)
# outbound - II - set caller_id based on routing_table by explicite number
params = 'event=newCall&direction=out&from=4930600000000&to=491714000000&callId=8621106404543334274-4&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
assert_response(200)
on_hangup = nil
on_answer = nil
caller_id = nil
number_to_dail = nil
content = @response.body
response = REXML::Document.new(content)
response.elements.each('Response') do |element|
on_hangup = element.attributes['onHangup']
on_answer = element.attributes['onAnswer']
end
response.elements.each('Response/Dial') do |element|
caller_id = element.attributes['callerId']
end
response.elements.each('Response/Dial/Number') do |element|
number_to_dail = element.text
end
assert_equal('41715880339000', caller_id)
assert_equal('491714000000', number_to_dail)
assert_equal('http://zammad.example.com/api/v1/sipgate/out', on_hangup)
assert_equal('http://zammad.example.com/api/v1/sipgate/out', on_answer)
# outbound - III - set caller_id based on routing_table by 41*
params = 'event=newCall&direction=out&from=4930600000000&to=4147110000000&callId=8621106404543334274-5&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
assert_response(200)
on_hangup = nil
on_answer = nil
caller_id = nil
number_to_dail = nil
content = @response.body
response = REXML::Document.new(content)
response.elements.each('Response') do |element|
on_hangup = element.attributes['onHangup']
on_answer = element.attributes['onAnswer']
end
response.elements.each('Response/Dial') do |element|
caller_id = element.attributes['callerId']
end
response.elements.each('Response/Dial/Number') do |element|
number_to_dail = element.text
end
assert_equal('41715880339000', caller_id)
assert_equal('4147110000000', number_to_dail)
assert_equal('http://zammad.example.com/api/v1/sipgate/out', on_hangup)
assert_equal('http://zammad.example.com/api/v1/sipgate/out', on_answer)
# no config
Setting.set('sipgate_config', {})
params = 'event=newCall&direction=in&from=4912347114711&to=4930600000000&callId=4991155921769858278-6&user%5B%5D=user+1&user%5B%5D=user+2'
post '/api/v1/sipgate/in', params: params
assert_response(422)
error = nil
content = @response.body
response = REXML::Document.new(content)
response.elements.each('Response/Error') do |element|
error = element.text
end
assert_equal('Feature not configured, please contact your admin!', error)
end
test 'log call' do
# outbound - I - new call
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&callId=1234567890-1&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-1')
assert(log)
assert_equal('4930777000000', log.from)
assert_equal('4912347114711', log.to)
assert_equal('out', log.direction)
assert_equal('user 1', log.from_comment)
assert_equal('CallerId Customer1', log.to_comment)
assert_nil(log.comment)
assert_equal('newCall', log.state)
assert_equal(true, log.done)
# outbound - I - hangup by agent
params = 'event=hangup&direction=out&callId=1234567890-1&cause=cancel'
post '/api/v1/sipgate/out', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-1')
assert(log)
assert_equal('4930777000000', log.from)
assert_equal('4912347114711', log.to)
assert_equal('out', log.direction)
assert_equal('user 1', log.from_comment)
assert_equal('CallerId Customer1', log.to_comment)
assert_equal('cancel', log.comment)
assert_equal('hangup', log.state)
assert_equal(true, log.done)
# outbound - II - new call
params = 'event=newCall&direction=out&from=4930600000000&to=4912347114711&callId=1234567890-2&user%5B%5D=user+1'
post '/api/v1/sipgate/out', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-2')
assert(log)
assert_equal('4930777000000', log.from)
assert_equal('4912347114711', log.to)
assert_equal('out', log.direction)
assert_equal('user 1', log.from_comment)
assert_equal('CallerId Customer1', log.to_comment)
assert_nil(log.comment)
assert_equal('newCall', log.state)
assert_equal(true, log.done)
# outbound - II - answer by customer
params = 'event=answer&direction=out&callId=1234567890-2&from=4930600000000&to=4912347114711'
post '/api/v1/sipgate/out', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-2')
assert(log)
assert_equal('4930777000000', log.from)
assert_equal('4912347114711', log.to)
assert_equal('out', log.direction)
assert_equal('user 1', log.from_comment)
assert_equal('CallerId Customer1', log.to_comment)
assert_nil(log.comment)
assert_equal('answer', log.state)
assert_equal(true, log.done)
# outbound - II - hangup by customer
params = 'event=hangup&direction=out&callId=1234567890-2&cause=normalClearing&from=4930600000000&to=4912347114711'
post '/api/v1/sipgate/out', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-2')
assert(log)
assert_equal('4930777000000', log.from)
assert_equal('4912347114711', log.to)
assert_equal('out', log.direction)
assert_equal('user 1', log.from_comment)
assert_equal('CallerId Customer1', log.to_comment)
assert_equal('normalClearing', log.comment)
assert_equal('hangup', log.state)
assert_equal(true, log.done)
# inbound - I - new call
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&callId=1234567890-3&user%5B%5D=user+1'
post '/api/v1/sipgate/in', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-3')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('4912347114711', log.from)
assert_equal('in', log.direction)
assert_equal('user 1', log.to_comment)
assert_equal('CallerId Customer1', log.from_comment)
assert_nil(log.comment)
assert_equal('newCall', log.state)
assert_equal(true, log.done)
# inbound - I - answer by customer
params = 'event=answer&direction=in&callId=1234567890-3&to=4930600000000&from=4912347114711'
post '/api/v1/sipgate/in', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-3')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('4912347114711', log.from)
assert_equal('in', log.direction)
assert_equal('user 1', log.to_comment)
assert_equal('CallerId Customer1', log.from_comment)
assert_nil(log.comment)
assert_equal('answer', log.state)
assert_equal(true, log.done)
# inbound - I - hangup by customer
params = 'event=hangup&direction=in&callId=1234567890-3&cause=normalClearing&to=4930600000000&from=4912347114711'
post '/api/v1/sipgate/in', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-3')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('4912347114711', log.from)
assert_equal('in', log.direction)
assert_equal('user 1', log.to_comment)
assert_equal('CallerId Customer1', log.from_comment)
assert_equal('normalClearing', log.comment)
assert_equal('hangup', log.state)
assert_equal(true, log.done)
# inbound - II - new call
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&callId=1234567890-4&user%5B%5D=user+1,user+2'
post '/api/v1/sipgate/in', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-4')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('4912347114711', log.from)
assert_equal('in', log.direction)
assert_equal('user 1,user 2', log.to_comment)
assert_equal('CallerId Customer1', log.from_comment)
assert_nil(log.comment)
assert_equal('newCall', log.state)
assert_equal(true, log.done)
# inbound - II - answer by voicemail
params = 'event=answer&direction=in&callId=1234567890-4&to=4930600000000&from=4912347114711&user=voicemail'
post '/api/v1/sipgate/in', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-4')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('4912347114711', log.from)
assert_equal('in', log.direction)
assert_equal('voicemail', log.to_comment)
assert_equal('CallerId Customer1', log.from_comment)
assert_nil(log.comment)
assert_equal('answer', log.state)
assert_equal(true, log.done)
# inbound - II - hangup by customer
params = 'event=hangup&direction=in&callId=1234567890-4&cause=normalClearing&to=4930600000000&from=4912347114711'
post '/api/v1/sipgate/in', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-4')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('4912347114711', log.from)
assert_equal('in', log.direction)
assert_equal('voicemail', log.to_comment)
assert_equal('CallerId Customer1', log.from_comment)
assert_equal('normalClearing', log.comment)
assert_equal('hangup', log.state)
assert_equal(false, log.done)
# inbound - III - new call
params = 'event=newCall&direction=in&to=4930600000000&from=4912347114711&callId=1234567890-5&user%5B%5D=user+1,user+2'
post '/api/v1/sipgate/in', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-5')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('4912347114711', log.from)
assert_equal('in', log.direction)
assert_equal('user 1,user 2', log.to_comment)
assert_equal('CallerId Customer1', log.from_comment)
assert_nil(log.comment)
assert_equal('newCall', log.state)
assert_equal(true, log.done)
# inbound - III - hangup by customer
params = 'event=hangup&direction=in&callId=1234567890-5&cause=normalClearing&to=4930600000000&from=4912347114711'
post '/api/v1/sipgate/in', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-5')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('4912347114711', log.from)
assert_equal('in', log.direction)
assert_equal('user 1,user 2', log.to_comment)
assert_equal('CallerId Customer1', log.from_comment)
assert_equal('normalClearing', log.comment)
assert_equal('hangup', log.state)
assert_equal(false, log.done)
# inbound - IV - new call
params = 'event=newCall&direction=in&to=4930600000000&from=49999992222222&callId=1234567890-6&user%5B%5D=user+1,user+2'
post '/api/v1/sipgate/in', params: params
assert_response(200)
log = Cti::Log.find_by(call_id: '1234567890-6')
assert(log)
assert_equal('4930600000000', log.to)
assert_equal('49999992222222', log.from)
assert_equal('in', log.direction)
assert_equal('user 1,user 2', log.to_comment)
assert_equal('CallerId Customer3,CallerId Customer2', log.from_comment)
assert_not(log.preferences['to'])
assert(log.preferences['from'])
assert_nil(log.comment)
assert_equal('newCall', log.state)
assert_equal(true, log.done)
# get caller list
get '/api/v1/cti/log'
assert_response(401)
customer2 = User.lookup(login: 'ticket-caller_id_sipgate-customer2@example.com')
customer3 = User.lookup(login: 'ticket-caller_id_sipgate-customer3@example.com')
headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
credentials = ActionController::HttpAuthentication::Basic.encode_credentials('cti-agent@example.com', 'agentpw')
get '/api/v1/cti/log', headers: headers.merge('Authorization' => credentials)
assert_response(200)
result = JSON.parse(@response.body)
assert_equal(result['list'].class, Array)
assert_equal(6, result['list'].count)
assert(result['assets'])
assert(result['assets']['User'])
assert(result['assets']['User'][customer2.id.to_s])
assert(result['assets']['User'][customer3.id.to_s])
assert_equal('1234567890-6', result['list'][0]['call_id'])
assert_equal('1234567890-5', result['list'][1]['call_id'])
assert_equal('1234567890-4', result['list'][2]['call_id'])
assert_equal('1234567890-3', result['list'][3]['call_id'])
assert_equal('1234567890-2', result['list'][4]['call_id'])
assert_equal('hangup', result['list'][4]['state'])
assert_equal('4930777000000', result['list'][4]['from'])
assert_equal('user 1', result['list'][4]['from_comment'])
assert_equal('4912347114711', result['list'][4]['to'])
assert_equal('CallerId Customer1', result['list'][4]['to_comment'])
assert_equal('normalClearing', result['list'][4]['comment'])
assert_equal('hangup', result['list'][4]['state'])
assert_equal('1234567890-1', result['list'][5]['call_id'])
end
end

View file

@ -1,252 +0,0 @@
require 'test_helper'
class AutoWizardTest < ActiveSupport::TestCase
test 'a simple' do
auto_wizard_data = {
Users: [
{
login: 'master_unit_test01@example.com',
firstname: 'Test Master',
lastname: 'Agent',
email: 'master_unit_test01@example.com',
password: 'test',
},
{
login: 'agent1_unit_test01@example.com',
firstname: 'Agent 1',
lastname: 'Test',
email: 'agent1_unit_test01@example.com',
password: 'test',
roles: ['Agent'],
}
],
Groups: [
{
name: 'some group1',
users: ['master_unit_test01@example.com', 'agent1_unit_test01@example.com']
}
],
Settings: [
{
name: 'developer_mode',
value: true
},
{
name: 'product_name',
value: 'Zammad UnitTest01 System'
},
]
}
assert_equal(false, AutoWizard.enabled?)
auto_wizard_file_write(auto_wizard_data)
assert_equal(true, AutoWizard.enabled?)
AutoWizard.setup
assert_equal(false, AutoWizard.enabled?)
# check first user roles
auto_wizard_data[:Users][0][:roles] = %w[Agent Admin]
auto_wizard_data[:Users].each do |local_user|
user = User.find_by(login: local_user[:login])
assert_equal(local_user[:login], user.login)
assert_equal(local_user[:firstname], user.firstname)
assert_equal(local_user[:lastname], user.lastname)
assert_equal(local_user[:email], user.email)
assert_equal(local_user[:roles].count, user.role_ids.count)
next unless local_user[:roles]
local_user[:roles].each do |local_role_name|
local_role = Role.find_by(name: local_role_name)
assert(user.role_ids.include?(local_role.id))
end
end
auto_wizard_data[:Groups].each do |local_group|
group = Group.find_by(name: local_group[:name])
assert_equal(local_group[:name], group.name)
next unless local_group[:users]
local_group[:users].each do |local_user_login|
local_user = User.find_by(login: local_user_login)
assert(group.user_ids.include?(local_user.id))
end
end
auto_wizard_data[:Settings].each do |local_setting|
setting_value = Setting.get(local_setting[:name])
assert_equal(local_setting[:value], setting_value)
end
end
test 'b complex' do
auto_wizard_data = {
Organizations: [
{
name: 'Auto Wizard Test Org',
shared: false,
}
],
Users: [
{
login: 'master_unit_test01@example.com',
firstname: 'Test Master',
lastname: 'Agent',
email: 'master_unit_test01@example.com',
password: 'test',
organization: 'Auto Wizard Test Org',
roles: ['Admin'],
},
{
login: 'agent1_unit_test01@example.com',
firstname: 'Agent 1',
lastname: 'Test',
email: 'agent1_unit_test01@example.com',
password: 'test',
roles: ['Agent'],
}
],
Groups: [
{
name: 'some group1',
users: ['master_unit_test01@example.com', 'agent1_unit_test01@example.com']
},
{
name: 'Users',
users: ['master_unit_test01@example.com', 'agent1_unit_test01@example.com'],
signature: 'default',
email_address_id: 1,
note: 'Standard Group/Pool for Tickets.',
}
],
Settings: [
{
name: 'developer_mode',
value: false,
},
{
name: 'product_name',
value: 'Zammad UnitTest02 System'
},
],
Permissions: [
{
name: 'admin.session',
active: false,
},
{
name: 'admin.session.new',
active: true,
},
],
Channels: [
{
id: 1,
area: 'Email::Account',
group: 'Users',
options: {
inbound: {
adapter: 'imap',
options: {
host: 'mx1.example.com',
user: 'not_existing',
password: 'some_pass',
ssl: true
}
},
outbound: {
adapter: 'sendmail'
}
},
preferences: {
online_service_disable: true,
},
active: true
}
],
EmailAddresses: [
{
id: 1,
channel_id: 1,
realname: 'Zammad',
email: 'zammad@localhost',
}
],
TextModuleLocale: {
Locale: 'de-de',
},
CalendarSetup: {
Ip: '195.65.29.254',
},
}
assert_equal(false, AutoWizard.enabled?)
auto_wizard_file_write(auto_wizard_data)
assert_equal(true, AutoWizard.enabled?)
AutoWizard.setup
assert_equal(false, AutoWizard.enabled?)
assert_not_equal(0, TextModule.count)
assert_equal(1, Calendar.count)
assert_equal('Switzerland', Calendar.first.name)
assert_equal('Europe/Zurich', Calendar.first.timezone)
auto_wizard_data[:Users].each do |local_user|
user = User.find_by(login: local_user[:login])
assert_equal(local_user[:login], user.login)
assert_equal(local_user[:firstname], user.firstname)
assert_equal(local_user[:lastname], user.lastname)
assert_equal(local_user[:email], user.email)
next unless local_user[:roles]
assert_equal(local_user[:roles].count, user.role_ids.count)
local_user[:roles].each do |local_role_name|
local_role = Role.find_by(name: local_role_name)
assert(user.role_ids.include?(local_role.id))
end
end
auto_wizard_data[:Groups].each do |local_group|
group = Group.find_by(name: local_group[:name])
assert_equal(local_group[:name], group.name)
local_group[:users]&.each do |local_user_login|
local_user = User.find_by(login: local_user_login)
assert(group.user_ids.include?(local_user.id))
end
if local_group[:signature]
signature = group.signature
assert_equal('default', signature.name)
end
end
auto_wizard_data[:EmailAddresses].each do |local_email_address|
email_address = EmailAddress.find_by(email: local_email_address[:email])
assert_equal(local_email_address[:email], email_address.email)
assert_equal(local_email_address[:realname], email_address.realname)
channel = email_address.channel
assert_equal(local_email_address[:channel_id], email_address.channel.id)
end
auto_wizard_data[:Channels].each do |local_channel|
channel = Channel.find_by(id: local_channel[:id])
assert_equal(local_channel[:area], channel.area)
group = channel.group
assert_equal(local_channel[:group], group.name)
end
auto_wizard_data[:Settings].each do |local_setting|
setting_value = Setting.get(local_setting[:name])
assert_equal(local_setting[:value], setting_value)
end
auto_wizard_data[:Permissions].each do |local_permission|
permission = Permission.find_by(name: local_permission[:name])
assert_equal(local_permission[:name], permission.name)
assert_equal(local_permission[:active], permission.active)
end
end
def auto_wizard_file_write(data)
location = Rails.root.join('auto_wizard.json')
file = File.new(location, 'wb')
file.write(data.to_json)
file.close
end
def auto_wizard_file_exists?
location = Rails.root.join('auto_wizard.json')
return false if File.exist?(location)
true
end
end

View file

@ -1,436 +0,0 @@
require 'integration_test_helper'
class CalendarSubscriptionsTicketsTest < ActiveSupport::TestCase
user = User.create(
firstname: 'CalendarSubscriptions',
lastname: 'Testuser',
email: 'calendar_subscriptions_testuser@example.com',
updated_by_id: 1,
created_by_id: 1,
)
user_not_assigned = User.find(1)
sla = Sla.create(
name: 'sla 1',
condition: {},
data: {
'Mon' => 'Mon', 'Tue' => 'Tue', 'Wed' => 'Wed', 'Thu' => 'Thu', 'Fri' => 'Fri', 'Sat' => 'Sat', 'Sun' => 'Sun',
'beginning_of_workday' => '9:00',
'end_of_workday' => '18:00',
},
timezone: 'Europe/Berlin',
first_response_time: 10,
update_time: 10,
close_time: 10,
active: true,
updated_by_id: 1,
created_by_id: 1,
)
tickets = [
{
owner: user,
title: 'new 1',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'new' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user_not_assigned,
title: 'new 2',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'new' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user,
title: 'open 1',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'open' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user_not_assigned,
title: 'open 2',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'open' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user,
title: 'pending reminder 1',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'pending reminder' ),
pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user,
title: 'pending reminder 2',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'pending reminder' ),
pending_time: DateTime.tomorrow,
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user_not_assigned,
title: 'pending reminder 3',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'pending reminder' ),
pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user_not_assigned,
title: 'pending reminder 4',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'pending reminder' ),
pending_time: DateTime.tomorrow,
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user,
title: 'pending close 1',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'pending close' ),
pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user,
title: 'pending close 2',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'pending close' ),
pending_time: DateTime.tomorrow,
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user_not_assigned,
title: 'pending close 3',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'pending close' ),
pending_time: Time.zone.parse('1977-10-27 22:00:00 +0000'),
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user_not_assigned,
title: 'pending close 4',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'pending close' ),
pending_time: DateTime.tomorrow,
priority: Ticket::Priority.lookup( name: '2 normal' ),
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user,
title: 'escalation 1',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'open' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
created_at: '2013-03-21 09:30:00 UTC',
updated_at: '2013-03-21 09:30:00 UTC',
updated_by_id: 1,
created_by_id: 1,
},
{
owner: user_not_assigned,
title: 'escalation 2',
group: Group.lookup( name: 'Users'),
customer_id: user.id,
state: Ticket::State.lookup( name: 'open' ),
priority: Ticket::Priority.lookup( name: '2 normal' ),
created_at: '2013-03-21 09:30:00 UTC',
updated_at: '2013-03-21 09:30:00 UTC',
updated_by_id: 1,
created_by_id: 1,
},
]
tickets.each do |ticket|
Ticket.create( ticket )
end
defaults_disabled = {
escalation: {
own: false,
not_assigned: false,
},
new_open: {
own: false,
not_assigned: false,
},
pending: {
own: false,
not_assigned: false,
}
}
test 'new_open' do
tests = [
{
count: 0,
name: 'none',
preferences: {
new_open: {
own: false,
not_assigned: false,
}
},
owner_ids: []
},
{
count: 3,
name: 'owner',
preferences: {
new_open: {
own: true,
not_assigned: false,
}
},
owner_ids: [user.id]
},
{
count: 3,
name: 'not_assigned',
preferences: {
new_open: {
own: false,
not_assigned: true,
}
},
owner_ids: [user_not_assigned.id]
},
{
count: 6,
name: 'owner+not_assigned',
preferences: {
new_open: {
own: true,
not_assigned: true,
}
},
owner_ids: [user.id, user_not_assigned.id]
},
]
tests.each do |test_data|
preferences = defaults_disabled.merge( test_data[:preferences] )
user.preferences[:calendar_subscriptions] = {}
user.preferences[:calendar_subscriptions][:tickets] = preferences
calendar_subscriptions_ticket = CalendarSubscriptions::Tickets.new( user, preferences )
event_data = calendar_subscriptions_ticket.new_open
assert_equal( test_data[:count], event_data.length, "#{test_data[:name]} event count" )
calendar_subscriptions = CalendarSubscriptions.new( user )
ical = calendar_subscriptions.all
event_data.each do |event|
contained = false
if ical.match?(/#{event[:summary]}/)
contained = true
end
assert( contained, "#{test_data[:name]} new_open ical contains '#{event[:summary]}'" )
end
end
end
test 'pending' do
tests = [
{
count: 0,
name: 'none',
preferences: {
pending: {
own: false,
not_assigned: false,
}
},
owner_ids: []
},
{
count: 4,
name: 'owner',
preferences: {
pending: {
own: true,
not_assigned: false,
}
},
owner_ids: [user.id]
},
{
count: 4,
name: 'not_assigned',
preferences: {
pending: {
own: false,
not_assigned: true,
}
},
owner_ids: [user_not_assigned.id]
},
{
count: 8,
name: 'owner+not_assigned',
preferences: {
pending: {
own: true,
not_assigned: true,
}
},
owner_ids: [user.id, user_not_assigned.id]
},
]
tests.each do |test_data|
preferences = defaults_disabled.merge( test_data[:preferences] )
user.preferences[:calendar_subscriptions] = {}
user.preferences[:calendar_subscriptions][:tickets] = preferences
calendar_subscriptions_ticket = CalendarSubscriptions::Tickets.new( user, preferences )
event_data = calendar_subscriptions_ticket.pending
assert_equal( test_data[:count], event_data.length, "#{test_data[:name]} event count" )
calendar_subscriptions = CalendarSubscriptions.new( user )
ical = calendar_subscriptions.all
event_data.each do |event|
contained = false
if ical.match?(/#{event[:summary]}/)
contained = true
end
assert( contained, "#{test_data[:name]} pending ical contains '#{event[:summary]}'" )
end
end
end
test 'escalation' do
tests = [
{
count: 0,
name: 'none',
preferences: {
escalation: {
own: false,
not_assigned: false,
}
},
owner_ids: []
},
{
count: 7,
name: 'owner',
preferences: {
escalation: {
own: true,
not_assigned: false,
}
},
owner_ids: [user.id]
},
{
count: 7,
name: 'not_assigned',
preferences: {
escalation: {
own: false,
not_assigned: true,
}
},
owner_ids: [user_not_assigned.id]
},
{
count: 12,
name: 'owner+not_assigned',
preferences: {
escalation: {
own: true,
not_assigned: true,
}
},
owner_ids: [user.id, user_not_assigned.id]
},
]
tests.each do |test_data|
preferences = defaults_disabled.merge( test_data[:preferences] )
user.preferences[:calendar_subscriptions] = {}
user.preferences[:calendar_subscriptions][:tickets] = preferences
calendar_subscriptions_ticket = CalendarSubscriptions::Tickets.new( user, preferences )
event_data = calendar_subscriptions_ticket.escalation
assert_equal( test_data[:count], event_data.length, "#{test_data[:name]} event count" )
calendar_subscriptions = CalendarSubscriptions.new( user )
ical = calendar_subscriptions.all
event_data.each do |event|
contained = false
if ical.match?(/#{event[:summary]}/)
contained = true
end
assert( contained, "#{test_data[:name]} escalation ical contains '#{event[:summary]}'" )
end
end
end
end