otrs_import_test.rb 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. require 'integration_test_helper'
  2. class OtrsImportTest < ActiveSupport::TestCase
  3. if !ENV['IMPORT_OTRS_ENDPOINT']
  4. raise "ERROR: Need IMPORT_OTRS_ENDPOINT - hint IMPORT_OTRS_ENDPOINT='http://vz305.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator'"
  5. end
  6. if !ENV['IMPORT_OTRS_ENDPOINT_KEY']
  7. raise "ERROR: Need IMPORT_OTRS_ENDPOINT_KEY - hint IMPORT_OTRS_ENDPOINT_KEY='01234567899876543210'"
  8. end
  9. Setting.set('import_otrs_endpoint', ENV['IMPORT_OTRS_ENDPOINT'])
  10. Setting.set('import_otrs_endpoint_key', ENV['IMPORT_OTRS_ENDPOINT_KEY'])
  11. Setting.set('import_mode', true)
  12. Setting.set('system_init_done', false)
  13. Import::OTRS.start
  14. # check settings items
  15. test 'check settings' do
  16. http = nil
  17. if ENV['IMPORT_OTRS_ENDPOINT'] =~ %r{^(http|https)://}
  18. http = $1
  19. end
  20. assert( Setting.get('system_id'), 'system_id' )
  21. assert_equal( http, Setting.get('http_type'), 'http_type' )
  22. assert_equal( 'Example Company', Setting.get('organization'), 'organization' )
  23. end
  24. test 'check dynamic fields' do
  25. local_objects = ObjectManager::Attribute.list_full
  26. object_attribute_names = local_objects.select do |local_object|
  27. local_object[:object] == 'Ticket'
  28. end.collect do |local_object|
  29. local_object['name']
  30. end
  31. 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]
  32. assert_equal(expected_object_attribute_names, object_attribute_names, 'dynamic field names')
  33. end
  34. # check count of imported items
  35. test 'check counts' do
  36. assert_equal( 603, Ticket.count, 'tickets' )
  37. assert_equal( 3182, Ticket::Article.count, 'ticket articles' )
  38. assert_equal( 274, Store.count, 'ticket article attachments' )
  39. assert_equal( 10, Ticket::State.count, 'ticket states' )
  40. assert_equal( 24, Group.count, 'groups' )
  41. end
  42. # check imported users and permission
  43. test 'check users' do
  44. role_admin = Role.where( name: 'Admin' ).first
  45. role_agent = Role.where( name: 'Agent' ).first
  46. role_customer = Role.where( name: 'Customer' ).first
  47. #role_report = Role.where( :name => 'Report' ).first
  48. user1 = User.find(2)
  49. assert_equal( 'agent-1 firstname', user1.firstname )
  50. assert_equal( 'agent-1 lastname', user1.lastname )
  51. assert_equal( 'agent-1', user1.login )
  52. assert_equal( 'agent-1@example.com', user1.email )
  53. assert_equal( true, user1.active )
  54. assert( user1.roles.include?( role_agent ) )
  55. assert_not( user1.roles.include?( role_admin ) )
  56. assert_not( user1.roles.include?( role_customer ) )
  57. #assert_not( user1.roles.include?( role_report ) )
  58. group_dasa = Group.where( name: 'dasa' ).first
  59. group_raw = Group.where( name: 'Raw' ).first
  60. assert_not( user1.groups_access('full').include?( group_dasa ) )
  61. assert( user1.groups_access('full').include?( group_raw ) )
  62. user2 = User.find(3)
  63. assert_equal( 'agent-2 firstname äöüß', user2.firstname )
  64. assert_equal( 'agent-2 lastname äöüß', user2.lastname )
  65. assert_equal( 'agent-2', user2.login )
  66. assert_equal( 'agent-2@example.com', user2.email )
  67. assert_equal( true, user2.active )
  68. assert( user2.roles.include?( role_agent ) )
  69. assert( user2.roles.include?( role_admin ) )
  70. assert_not( user2.roles.include?( role_customer ) )
  71. #assert( user2.roles.include?( role_report ) )
  72. assert( user2.groups_access('full').include?( group_dasa ) )
  73. assert( user2.groups_access('full').include?( group_raw ) )
  74. user3 = User.find(7)
  75. assert_equal( 'invalid', user3.firstname )
  76. assert_equal( 'invalid', user3.lastname )
  77. assert_equal( 'invalid', user3.login )
  78. assert_equal( 'invalid@example.com', user3.email )
  79. assert_equal( false, user3.active )
  80. assert( user3.roles.include?( role_agent ) )
  81. assert_not( user3.roles.include?( role_admin ) )
  82. assert_not( user3.roles.include?( role_customer ) )
  83. #assert( user3.roles.include?( role_report ) )
  84. assert_not( user3.groups_access('full').include?( group_dasa ) )
  85. assert_not( user3.groups_access('full').include?( group_raw ) )
  86. user4 = User.find(8)
  87. assert_equal( 'invalid-temp', user4.firstname )
  88. assert_equal( 'invalid-temp', user4.lastname )
  89. assert_equal( 'invalid-temp', user4.login )
  90. assert_equal( 'invalid-temp@example.com', user4.email )
  91. assert_equal( false, user4.active )
  92. assert( user4.roles.include?( role_agent ) )
  93. assert_not( user4.roles.include?( role_admin ) )
  94. assert_not( user4.roles.include?( role_customer ) )
  95. #assert( user4.roles.include?( role_report ) )
  96. assert_not( user4.groups_access('full').include?( group_dasa ) )
  97. assert_not( user4.groups_access('full').include?( group_raw ) )
  98. end
  99. # check all synced states and state types
  100. test 'check ticket stats' do
  101. state = Ticket::State.find(1)
  102. assert_equal( 'new', state.name )
  103. assert_equal( 'new', state.state_type.name )
  104. state = Ticket::State.find(2)
  105. assert_equal( 'closed successful', state.name )
  106. assert_equal( 'closed', state.state_type.name )
  107. state = Ticket::State.find(6)
  108. assert_equal( 'pending reminder', state.name )
  109. assert_equal( 'pending reminder', state.state_type.name )
  110. end
  111. # check groups/queues
  112. test 'check groups' do
  113. group1 = Group.find(1)
  114. assert_equal( 'Postmaster', group1.name )
  115. assert_equal( true, group1.active )
  116. group2 = Group.find(19)
  117. assert_equal( 'UnitTestQueue20668', group2.name )
  118. assert_equal( false, group2.active )
  119. end
  120. # check imported customers and organization relation
  121. test 'check customers / organizations' do
  122. user1 = User.where( login: 'jn' ).first
  123. assert_equal( 'Johannes', user1.firstname )
  124. assert_equal( 'Nickel', user1.lastname )
  125. assert_equal( 'jn', user1.login )
  126. assert_equal( 'jn@example.com', user1.email )
  127. organization1 = user1.organization
  128. assert_equal( 'Znuny GmbH Berlin', organization1.name )
  129. assert_equal( 'äöüß', organization1.note )
  130. user2 = User.where( login: 'test90133' ).first
  131. assert_equal( 'test90133', user2.firstname )
  132. assert_equal( 'test90133', user2.lastname )
  133. assert_equal( 'test90133', user2.login )
  134. assert_equal( 'qa4711@t-online.de', user2.email )
  135. organization2 = user2.organization
  136. assert( organization2, nil )
  137. end
  138. # check imported tickets
  139. test 'check tickets' do
  140. # ticket is open
  141. ticket = Ticket.find(728)
  142. assert_equal( 'test #1', ticket.title )
  143. assert_equal( 'open', ticket.state.name )
  144. assert_equal( 'Misc', ticket.group.name )
  145. assert_equal( '4 high', ticket.priority.name )
  146. assert_equal( 'agent-2', ticket.owner.login )
  147. assert_equal( 'partner', ticket.customer.login )
  148. assert_equal( 'Partner der betreut', ticket.organization.name )
  149. assert_equal( Time.zone.parse('2014-11-20 22:33:41 +0000').gmtime.to_s, ticket.created_at.to_s )
  150. assert_nil( ticket.close_at )
  151. # check history
  152. # - create entry
  153. # ticket is created with state closed
  154. ticket = Ticket.find(729)
  155. assert_equal( 'test #2', ticket.title )
  156. assert_equal( 'closed successful', ticket.state.name )
  157. assert_equal( 'Raw', ticket.group.name )
  158. assert_equal( '3 normal', ticket.priority.name )
  159. assert_equal( 'agent-2', ticket.owner.login )
  160. assert_equal( 'jn2', ticket.customer.login )
  161. assert_equal( 'Znuny GmbH', ticket.organization.name )
  162. assert_equal( Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.created_at.to_s )
  163. assert_equal( Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.close_at.to_s )
  164. # check history
  165. # - create entry
  166. # ticket is created open and now closed
  167. ticket = Ticket.find(730)
  168. assert_equal( 'test #3', ticket.title )
  169. assert_equal( 'closed successful', ticket.state.name )
  170. assert_equal( 'Postmaster', ticket.group.name )
  171. assert_equal( '3 normal', ticket.priority.name )
  172. assert_equal( 'agent-2', ticket.owner.login )
  173. assert_equal( 'betreuterkunde2', ticket.customer.login )
  174. assert_equal( 'Noch ein betreuter Kunde', ticket.organization.name )
  175. assert_equal( Time.zone.parse('2014-11-21 00:17:40 +0000').gmtime.to_s, ticket.created_at.to_s )
  176. assert_equal( Time.zone.parse('2014-11-21 00:21:08 +0000').gmtime.to_s, ticket.close_at.to_s )
  177. # ticket dynamic fields
  178. ticket = Ticket.find(591)
  179. assert_equal( 'Some other smart subject!', ticket.title )
  180. assert_equal( '488', ticket.vertriebsweg )
  181. assert_equal( '["193"]', ticket.te_test ) # TODO: multiselect
  182. assert_equal( '358', ticket.sugar_crm_remote_no )
  183. assert_equal( '69', ticket.sugar_crm_company_selected_no )
  184. assert_equal( '["382"]', ticket.sugar_crm_company_selection ) # TODO: multiselect
  185. assert_equal( '310', ticket.topic_no )
  186. assert_equal( '495', ticket.open_exchange_ticket_number )
  187. assert_equal( '208', ticket.hostname )
  188. # check history
  189. # - create entry
  190. # - state change entry
  191. end
  192. test 'check article attachments' do
  193. article = Ticket::Article.find(149)
  194. assert_equal( 5, article.attachments.count )
  195. attachment = article.attachments.first
  196. assert_equal( 'image/jpeg', attachment[:preferences]['Mime-Type'] )
  197. assert_equal( 'Cursor_und_Banners_and_Alerts_und_Paket-Verwaltung_-_Admin_-_otrs336_und_otrs336.jpg', attachment.filename )
  198. article = Ticket::Article.find(156)
  199. assert_equal( 2, article.attachments.count )
  200. attachment = article.attachments.second
  201. assert_equal( 'application/pdf; name="=?UTF-8?B?5ZSQ6K+X5LiJ55m+6aaWLnBkZg==?="', attachment[:preferences]['Mime-Type'] )
  202. assert_equal( '唐诗三百首.pdf', attachment.filename )
  203. end
  204. end