2014-11-14 06:42:39 +00:00
|
|
|
require 'integration_test_helper'
|
|
|
|
|
|
|
|
class OtrsImportTest < ActiveSupport::TestCase
|
2014-11-18 14:52:19 +00:00
|
|
|
|
2015-04-10 14:27:03 +00:00
|
|
|
if !ENV['IMPORT_OTRS_ENDPOINT']
|
2016-03-01 14:26:46 +00:00
|
|
|
raise "ERROR: Need IMPORT_OTRS_ENDPOINT - hint IMPORT_OTRS_ENDPOINT='http://vz305.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator'"
|
2015-04-10 14:27:03 +00:00
|
|
|
end
|
|
|
|
if !ENV['IMPORT_OTRS_ENDPOINT_KEY']
|
2016-03-01 14:26:46 +00:00
|
|
|
raise "ERROR: Need IMPORT_OTRS_ENDPOINT_KEY - hint IMPORT_OTRS_ENDPOINT_KEY='01234567899876543210'"
|
2015-04-10 14:27:03 +00:00
|
|
|
end
|
|
|
|
|
2015-04-27 12:51:43 +00:00
|
|
|
Setting.set('import_otrs_endpoint', ENV['IMPORT_OTRS_ENDPOINT'])
|
|
|
|
Setting.set('import_otrs_endpoint_key', ENV['IMPORT_OTRS_ENDPOINT_KEY'])
|
|
|
|
Setting.set('import_mode', true)
|
2017-03-27 13:22:07 +00:00
|
|
|
Setting.set('system_init_done', false)
|
2015-05-07 11:57:19 +00:00
|
|
|
Import::OTRS.start
|
2014-12-01 12:06:15 +00:00
|
|
|
|
2014-11-23 13:01:08 +00:00
|
|
|
# check settings items
|
|
|
|
test 'check settings' do
|
2015-04-10 14:27:03 +00:00
|
|
|
http = nil
|
|
|
|
system_id = nil
|
2015-04-27 19:56:07 +00:00
|
|
|
if ENV['IMPORT_OTRS_ENDPOINT'] =~ %r{^(http|https)://((.+?)\..+?)/}
|
|
|
|
http = $1
|
|
|
|
system_id = $3
|
2021-05-12 11:37:44 +00:00
|
|
|
system_id.gsub!(%r{[A-z]}, '') # strip chars
|
2015-04-10 14:27:03 +00:00
|
|
|
end
|
|
|
|
assert_equal( system_id, Setting.get('system_id'), 'system_id' )
|
|
|
|
assert_equal( http, Setting.get('http_type'), 'http_type' )
|
|
|
|
assert_equal( 'Example Company', Setting.get('organization'), 'organization' )
|
2016-09-13 08:53:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'check dynamic fields' do
|
|
|
|
local_objects = ObjectManager::Attribute.list_full
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
object_attribute_names = local_objects.select do |local_object|
|
|
|
|
local_object[:object] == 'Ticket'
|
2017-10-01 12:25:52 +00:00
|
|
|
end.collect do |local_object|
|
2016-09-13 08:53:16 +00:00
|
|
|
local_object['name']
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-11-23 08:09:44 +00:00
|
|
|
expected_object_attribute_names = %w[vertriebsweg te_test sugar_crm_remote_no sugar_crm_company_selected_no sugar_crm_company_selection combine itsm_criticality customer_id itsm_impact itsm_review_required itsm_decision_result itsm_repair_start_time itsm_recovery_start_time itsm_decision_date title itsm_due_date topic_no open_exchange_ticket_number hostname ticket_free_key11 type ticket_free_text11 open_exchange_tn topic zarafa_tn group_id scom_hostname checkbox_example scom_uuid scom_state scom_service location owner_id department customer_location state_id pending_time priority_id tags]
|
2016-09-13 08:53:16 +00:00
|
|
|
|
|
|
|
assert_equal(expected_object_attribute_names, object_attribute_names, 'dynamic field names')
|
2014-11-23 13:01:08 +00:00
|
|
|
end
|
|
|
|
|
2014-11-18 14:52:19 +00:00
|
|
|
# check count of imported items
|
2014-11-14 06:42:39 +00:00
|
|
|
test 'check counts' do
|
2014-11-20 23:58:37 +00:00
|
|
|
assert_equal( 603, Ticket.count, 'tickets' )
|
2015-04-10 19:37:36 +00:00
|
|
|
assert_equal( 3182, Ticket::Article.count, 'ticket articles' )
|
2015-07-21 17:21:21 +00:00
|
|
|
assert_equal( 274, Store.count, 'ticket article attachments' )
|
2014-11-14 06:42:39 +00:00
|
|
|
assert_equal( 10, Ticket::State.count, 'ticket states' )
|
|
|
|
assert_equal( 24, Group.count, 'groups' )
|
|
|
|
end
|
|
|
|
|
2014-11-18 14:52:19 +00:00
|
|
|
# check imported users and permission
|
2014-11-14 06:42:39 +00:00
|
|
|
test 'check users' do
|
2015-04-27 13:42:53 +00:00
|
|
|
role_admin = Role.where( name: 'Admin' ).first
|
|
|
|
role_agent = Role.where( name: 'Agent' ).first
|
|
|
|
role_customer = Role.where( name: 'Customer' ).first
|
2014-11-14 06:42:39 +00:00
|
|
|
#role_report = Role.where( :name => 'Report' ).first
|
|
|
|
|
|
|
|
user1 = User.find(2)
|
|
|
|
assert_equal( 'agent-1 firstname', user1.firstname )
|
|
|
|
assert_equal( 'agent-1 lastname', user1.lastname )
|
|
|
|
assert_equal( 'agent-1', user1.login )
|
|
|
|
assert_equal( 'agent-1@example.com', user1.email )
|
|
|
|
assert_equal( true, user1.active )
|
|
|
|
|
|
|
|
assert( user1.roles.include?( role_agent ) )
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_not( user1.roles.include?( role_admin ) )
|
|
|
|
assert_not( user1.roles.include?( role_customer ) )
|
|
|
|
#assert_not( user1.roles.include?( role_report ) )
|
2014-11-14 06:42:39 +00:00
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_dasa = Group.where( name: 'dasa' ).first
|
|
|
|
group_raw = Group.where( name: 'Raw' ).first
|
2014-11-14 06:42:39 +00:00
|
|
|
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_not( user1.groups_access('full').include?( group_dasa ) )
|
|
|
|
assert( user1.groups_access('full').include?( group_raw ) )
|
2014-11-14 06:42:39 +00:00
|
|
|
|
|
|
|
user2 = User.find(3)
|
|
|
|
assert_equal( 'agent-2 firstname äöüß', user2.firstname )
|
|
|
|
assert_equal( 'agent-2 lastname äöüß', user2.lastname )
|
|
|
|
assert_equal( 'agent-2', user2.login )
|
|
|
|
assert_equal( 'agent-2@example.com', user2.email )
|
|
|
|
assert_equal( true, user2.active )
|
|
|
|
|
|
|
|
assert( user2.roles.include?( role_agent ) )
|
|
|
|
assert( user2.roles.include?( role_admin ) )
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_not( user2.roles.include?( role_customer ) )
|
2014-11-14 06:42:39 +00:00
|
|
|
#assert( user2.roles.include?( role_report ) )
|
|
|
|
|
2017-06-16 20:43:09 +00:00
|
|
|
assert( user2.groups_access('full').include?( group_dasa ) )
|
|
|
|
assert( user2.groups_access('full').include?( group_raw ) )
|
2014-11-14 06:42:39 +00:00
|
|
|
|
|
|
|
user3 = User.find(7)
|
|
|
|
assert_equal( 'invalid', user3.firstname )
|
|
|
|
assert_equal( 'invalid', user3.lastname )
|
|
|
|
assert_equal( 'invalid', user3.login )
|
|
|
|
assert_equal( 'invalid@example.com', user3.email )
|
|
|
|
assert_equal( false, user3.active )
|
|
|
|
|
|
|
|
assert( user3.roles.include?( role_agent ) )
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_not( user3.roles.include?( role_admin ) )
|
|
|
|
assert_not( user3.roles.include?( role_customer ) )
|
2014-11-14 06:42:39 +00:00
|
|
|
#assert( user3.roles.include?( role_report ) )
|
|
|
|
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_not( user3.groups_access('full').include?( group_dasa ) )
|
|
|
|
assert_not( user3.groups_access('full').include?( group_raw ) )
|
2014-11-14 06:42:39 +00:00
|
|
|
|
|
|
|
user4 = User.find(8)
|
|
|
|
assert_equal( 'invalid-temp', user4.firstname )
|
|
|
|
assert_equal( 'invalid-temp', user4.lastname )
|
|
|
|
assert_equal( 'invalid-temp', user4.login )
|
|
|
|
assert_equal( 'invalid-temp@example.com', user4.email )
|
|
|
|
assert_equal( false, user4.active )
|
|
|
|
|
|
|
|
assert( user4.roles.include?( role_agent ) )
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_not( user4.roles.include?( role_admin ) )
|
|
|
|
assert_not( user4.roles.include?( role_customer ) )
|
2014-11-14 06:42:39 +00:00
|
|
|
#assert( user4.roles.include?( role_report ) )
|
|
|
|
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_not( user4.groups_access('full').include?( group_dasa ) )
|
|
|
|
assert_not( user4.groups_access('full').include?( group_raw ) )
|
2014-11-14 06:42:39 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-11-18 14:52:19 +00:00
|
|
|
# check all synced states and state types
|
2014-11-14 06:42:39 +00:00
|
|
|
test 'check ticket stats' do
|
2014-11-20 23:58:37 +00:00
|
|
|
state = Ticket::State.find(1)
|
|
|
|
assert_equal( 'new', state.name )
|
|
|
|
assert_equal( 'new', state.state_type.name )
|
|
|
|
|
|
|
|
state = Ticket::State.find(2)
|
|
|
|
assert_equal( 'closed successful', state.name )
|
|
|
|
assert_equal( 'closed', state.state_type.name )
|
|
|
|
|
|
|
|
state = Ticket::State.find(6)
|
|
|
|
assert_equal( 'pending reminder', state.name )
|
|
|
|
assert_equal( 'pending reminder', state.state_type.name )
|
2014-11-14 06:42:39 +00:00
|
|
|
end
|
|
|
|
|
2014-11-18 14:52:19 +00:00
|
|
|
# check groups/queues
|
2014-11-14 06:42:39 +00:00
|
|
|
test 'check groups' do
|
|
|
|
group1 = Group.find(1)
|
|
|
|
assert_equal( 'Postmaster', group1.name )
|
|
|
|
assert_equal( true, group1.active )
|
|
|
|
|
|
|
|
group2 = Group.find(19)
|
|
|
|
assert_equal( 'UnitTestQueue20668', group2.name )
|
|
|
|
assert_equal( false, group2.active )
|
|
|
|
end
|
|
|
|
|
2014-11-18 14:52:19 +00:00
|
|
|
# check imported customers and organization relation
|
2014-11-14 06:42:39 +00:00
|
|
|
test 'check customers / organizations' do
|
2015-04-27 13:42:53 +00:00
|
|
|
user1 = User.where( login: 'jn' ).first
|
2014-11-14 06:42:39 +00:00
|
|
|
assert_equal( 'Johannes', user1.firstname )
|
|
|
|
assert_equal( 'Nickel', user1.lastname )
|
|
|
|
assert_equal( 'jn', user1.login )
|
|
|
|
assert_equal( 'jn@example.com', user1.email )
|
|
|
|
organization1 = user1.organization
|
|
|
|
assert_equal( 'Znuny GmbH Berlin', organization1.name )
|
|
|
|
assert_equal( 'äöüß', organization1.note )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
user2 = User.where( login: 'test90133' ).first
|
2014-11-14 06:42:39 +00:00
|
|
|
assert_equal( 'test90133', user2.firstname )
|
|
|
|
assert_equal( 'test90133', user2.lastname )
|
|
|
|
assert_equal( 'test90133', user2.login )
|
|
|
|
assert_equal( 'qa4711@t-online.de', user2.email )
|
|
|
|
organization2 = user2.organization
|
|
|
|
assert( organization2, nil )
|
|
|
|
end
|
2014-11-20 23:58:37 +00:00
|
|
|
|
|
|
|
# check imported tickets
|
|
|
|
test 'check tickets' do
|
|
|
|
|
|
|
|
# ticket is open
|
|
|
|
ticket = Ticket.find(728)
|
|
|
|
assert_equal( 'test #1', ticket.title )
|
|
|
|
assert_equal( 'open', ticket.state.name )
|
|
|
|
assert_equal( 'Misc', ticket.group.name )
|
|
|
|
assert_equal( '4 high', ticket.priority.name )
|
|
|
|
assert_equal( 'agent-2', ticket.owner.login )
|
|
|
|
assert_equal( 'partner', ticket.customer.login )
|
|
|
|
assert_equal( 'Partner der betreut', ticket.organization.name )
|
2015-04-27 19:56:07 +00:00
|
|
|
assert_equal( Time.zone.parse('2014-11-20 22:33:41 +0000').gmtime.to_s, ticket.created_at.to_s )
|
2017-04-19 22:11:39 +00:00
|
|
|
assert_nil( ticket.close_at )
|
2014-11-20 23:58:37 +00:00
|
|
|
|
2014-11-23 13:01:08 +00:00
|
|
|
# check history
|
2015-04-27 19:56:07 +00:00
|
|
|
# - create entry
|
2014-11-23 13:01:08 +00:00
|
|
|
|
2014-11-20 23:58:37 +00:00
|
|
|
# ticket is created with state closed
|
|
|
|
ticket = Ticket.find(729)
|
|
|
|
assert_equal( 'test #2', ticket.title )
|
|
|
|
assert_equal( 'closed successful', ticket.state.name )
|
|
|
|
assert_equal( 'Raw', ticket.group.name )
|
|
|
|
assert_equal( '3 normal', ticket.priority.name )
|
|
|
|
assert_equal( 'agent-2', ticket.owner.login )
|
|
|
|
assert_equal( 'jn2', ticket.customer.login )
|
|
|
|
assert_equal( 'Znuny GmbH', ticket.organization.name )
|
2015-04-27 19:56:07 +00:00
|
|
|
assert_equal( Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.created_at.to_s )
|
2016-09-14 07:15:30 +00:00
|
|
|
assert_equal( Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.close_at.to_s )
|
2014-11-20 23:58:37 +00:00
|
|
|
|
2014-11-23 13:01:08 +00:00
|
|
|
# check history
|
2015-04-27 19:56:07 +00:00
|
|
|
# - create entry
|
2014-11-23 13:01:08 +00:00
|
|
|
|
2014-11-20 23:58:37 +00:00
|
|
|
# ticket is created open and now closed
|
|
|
|
ticket = Ticket.find(730)
|
|
|
|
assert_equal( 'test #3', ticket.title )
|
|
|
|
assert_equal( 'closed successful', ticket.state.name )
|
|
|
|
assert_equal( 'Postmaster', ticket.group.name )
|
|
|
|
assert_equal( '3 normal', ticket.priority.name )
|
|
|
|
assert_equal( 'agent-2', ticket.owner.login )
|
|
|
|
assert_equal( 'betreuterkunde2', ticket.customer.login )
|
|
|
|
assert_equal( 'Noch ein betreuter Kunde', ticket.organization.name )
|
2015-04-27 19:56:07 +00:00
|
|
|
assert_equal( Time.zone.parse('2014-11-21 00:17:40 +0000').gmtime.to_s, ticket.created_at.to_s )
|
2016-09-14 07:15:30 +00:00
|
|
|
assert_equal( Time.zone.parse('2014-11-21 00:21:08 +0000').gmtime.to_s, ticket.close_at.to_s )
|
2014-11-23 13:01:08 +00:00
|
|
|
|
2016-09-13 08:53:16 +00:00
|
|
|
# ticket dynamic fields
|
|
|
|
ticket = Ticket.find(591)
|
|
|
|
assert_equal( 'Some other smart subject!', ticket.title )
|
|
|
|
assert_equal( '488', ticket.vertriebsweg )
|
|
|
|
assert_equal( '["193"]', ticket.te_test ) # TODO: multiselect
|
|
|
|
assert_equal( '358', ticket.sugar_crm_remote_no )
|
|
|
|
assert_equal( '69', ticket.sugar_crm_company_selected_no )
|
|
|
|
assert_equal( '["382"]', ticket.sugar_crm_company_selection ) # TODO: multiselect
|
|
|
|
assert_equal( '310', ticket.topic_no )
|
|
|
|
assert_equal( '495', ticket.open_exchange_ticket_number )
|
|
|
|
assert_equal( '208', ticket.hostname )
|
|
|
|
|
2014-11-23 13:01:08 +00:00
|
|
|
# check history
|
2015-04-27 19:56:07 +00:00
|
|
|
# - create entry
|
|
|
|
# - state change entry
|
2014-11-20 23:58:37 +00:00
|
|
|
end
|
2015-07-21 17:21:21 +00:00
|
|
|
|
|
|
|
test 'check article attachments' do
|
|
|
|
|
|
|
|
article = Ticket::Article.find(149)
|
|
|
|
assert_equal( 5, article.attachments.count )
|
|
|
|
|
|
|
|
attachment = article.attachments.first
|
2015-07-22 08:33:29 +00:00
|
|
|
assert_equal( 'image/jpeg', attachment[:preferences]['Mime-Type'] )
|
2015-07-21 17:21:21 +00:00
|
|
|
assert_equal( 'Cursor_und_Banners_and_Alerts_und_Paket-Verwaltung_-_Admin_-_otrs336_und_otrs336.jpg', attachment.filename )
|
|
|
|
|
|
|
|
article = Ticket::Article.find(156)
|
|
|
|
assert_equal( 2, article.attachments.count )
|
|
|
|
|
|
|
|
attachment = article.attachments.second
|
2015-07-22 08:33:29 +00:00
|
|
|
assert_equal( 'application/pdf; name="=?UTF-8?B?5ZSQ6K+X5LiJ55m+6aaWLnBkZg==?="', attachment[:preferences]['Mime-Type'] )
|
2015-07-21 17:21:21 +00:00
|
|
|
assert_equal( '唐诗三百首.pdf', attachment.filename )
|
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|