otrs_spec.rb 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. # Test a full OTRS import process against a system with known state and compare some expected results.
  4. RSpec.describe 'OTRS import', integration: true, integration_standalone: true, required_envs: %w[IMPORT_OTRS_ENDPOINT IMPORT_OTRS_ENDPOINT_KEY] do # rubocop:disable RSpec/DescribeClass
  5. before :all do # rubocop:disable RSpec/BeforeAfterAll
  6. Setting.set('import_otrs_endpoint', ENV['IMPORT_OTRS_ENDPOINT'])
  7. Setting.set('import_otrs_endpoint_key', ENV['IMPORT_OTRS_ENDPOINT_KEY'])
  8. Setting.set('import_mode', true)
  9. Setting.set('system_init_done', false)
  10. WebMock.disable!
  11. Import::OTRS.start
  12. WebMock.enable!
  13. end
  14. context 'when importing setting' do
  15. let(:protocol) { ENV['IMPORT_OTRS_ENDPOINT'].start_with?('https') ? 'https' : 'http' }
  16. it 'imports correctly' do
  17. expect(Setting.get('system_id')).to be_truthy
  18. expect(Setting.get('http_type')).to eq(protocol)
  19. expect(Setting.get('organization')).to eq('Example Company')
  20. end
  21. end
  22. context 'when importing dynamic fields' do
  23. let(:local_objects) { ObjectManager::Attribute.list_full }
  24. let(:object_attribute_names) do
  25. local_objects.select do |local_object|
  26. local_object[:object] == 'Ticket'
  27. end.pluck('name')
  28. end
  29. let(:expected_object_attribute_names) { %w[vertriebsweg te_test number sugar_crm_remote_no sugar_crm_company_selected_no sugar_crm_company_selection combine title itsm_criticality customer_id itsm_impact itsm_review_required itsm_decision_result organization_id itsm_repair_start_time itsm_recovery_start_time itsm_decision_date 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 textfeld state_id pending_time priority_id tags] }
  30. it 'imports correctly' do
  31. expect(object_attribute_names).to eq(expected_object_attribute_names)
  32. end
  33. end
  34. context 'when importing in general' do
  35. it 'imports the right number of objects' do
  36. expect(Ticket.count).to eq(603)
  37. expect(Ticket::Article.count).to eq(3182)
  38. expect(Store.count).to eq(274)
  39. expect(Ticket::State.count).to eq(10)
  40. expect(Group.count).to eq(24)
  41. end
  42. end
  43. context 'when importing users' do
  44. let(:role_admin) { Role.where(name: 'Admin').first }
  45. let(:role_agent) { Role.where(name: 'Agent').first }
  46. let(:role_customer) { Role.where(name: 'Customer').first }
  47. let(:user1) { User.find(2) }
  48. let(:user2) { User.find(3) }
  49. let(:user3) { User.find(7) }
  50. let(:user4) { User.find(8) }
  51. let(:group_dasa) { Group.where(name: 'dasa').first }
  52. let(:group_raw) { Group.where(name: 'Raw').first }
  53. it 'imports correctly' do
  54. expect(user1).to have_attributes(
  55. {
  56. firstname: 'agent-1 firstname',
  57. lastname: 'agent-1 lastname',
  58. login: 'agent-1',
  59. email: 'agent-1@example.com',
  60. active: true,
  61. }
  62. )
  63. expect(user1.roles).to include(role_agent).and(not_include(role_admin, role_customer))
  64. expect(user1.groups_access('full')).to include(group_raw).and(not_include(group_dasa))
  65. expect(user2).to have_attributes(
  66. {
  67. firstname: 'agent-2 firstname äöüß',
  68. lastname: 'agent-2 lastname äöüß',
  69. login: 'agent-2',
  70. email: 'agent-2@example.com',
  71. active: true,
  72. }
  73. )
  74. expect(user2.roles).to include(role_agent, role_admin).and(not_include(role_customer))
  75. expect(user2.groups_access('full')).to include(group_raw, group_dasa)
  76. expect(user3).to have_attributes(
  77. {
  78. firstname: 'invalid',
  79. lastname: 'invalid',
  80. login: 'invalid',
  81. email: 'invalid@example.com',
  82. active: false,
  83. }
  84. )
  85. expect(user3.roles).to include(role_agent).and(not_include(role_admin, role_customer))
  86. expect(user3.groups_access('full')).to not_include(group_raw, group_dasa)
  87. expect(user4).to have_attributes(
  88. {
  89. firstname: 'invalid-temp',
  90. lastname: 'invalid-temp',
  91. login: 'invalid-temp',
  92. active: false,
  93. }
  94. )
  95. expect(user4.roles).to include(role_agent).and(not_include(role_admin, role_customer))
  96. expect(user4.groups_access('full')).to not_include(group_raw, group_dasa)
  97. end
  98. end
  99. context 'when importing groups' do
  100. let(:group1) { Group.find(1) }
  101. let(:group2) { Group.find(19) }
  102. it 'imports correctly' do
  103. expect(group1).to have_attributes(
  104. {
  105. name: 'Postmaster',
  106. active: true,
  107. }
  108. )
  109. expect(group2).to have_attributes(
  110. {
  111. name: 'UnitTestQueue20668',
  112. active: false,
  113. }
  114. )
  115. end
  116. end
  117. context 'when importing customers / organizations' do
  118. let(:user1) { User.where(login: 'jn').first }
  119. let(:user2) { User.where(login: 'test90133').first }
  120. it 'imports correctly' do
  121. expect(user1).to have_attributes(
  122. {
  123. firstname: 'Johannes',
  124. lastname: 'Nickel',
  125. login: 'jn',
  126. email: 'jn@example.com',
  127. }
  128. )
  129. expect(user1.organization).to have_attributes(
  130. {
  131. name: 'Znuny GmbH Berlin',
  132. note: 'äöüß',
  133. }
  134. )
  135. expect(user2).to have_attributes(
  136. {
  137. firstname: 'test90133',
  138. lastname: 'test90133',
  139. login: 'test90133',
  140. email: 'qa4711@t-online.de',
  141. }
  142. )
  143. expect(user2.organization).to have_attributes(
  144. {
  145. name: 'test554449',
  146. note: 'test554449',
  147. }
  148. )
  149. end
  150. end
  151. context 'when importing ticket states' do
  152. let(:new_state) { Ticket::State.find(1) }
  153. let(:closed_state) { Ticket::State.find(2) }
  154. let(:pending_state) { Ticket::State.find(6) }
  155. it 'imports correctly' do
  156. expect(new_state.name).to eq('new')
  157. expect(new_state.state_type.name).to eq('new')
  158. expect(closed_state.name).to eq('closed successful')
  159. expect(closed_state.state_type.name).to eq('closed')
  160. expect(pending_state.name).to eq('pending reminder')
  161. expect(pending_state.state_type.name).to eq('pending reminder')
  162. end
  163. end
  164. context 'when importing tickets' do
  165. let(:ticket1) { Ticket.find(728) }
  166. let(:ticket2) { Ticket.find(729) }
  167. let(:ticket3) { Ticket.find(730) }
  168. let(:ticket4) { Ticket.find(591) }
  169. it 'imports correctly' do
  170. # ticket1 is open
  171. expect(ticket1.title).to eq('test #1')
  172. expect(ticket1.state.name).to eq('open')
  173. expect(ticket1.group.name).to eq('Misc')
  174. expect(ticket1.priority.name).to eq('4 high')
  175. expect(ticket1.owner.login).to eq('agent-2')
  176. expect(ticket1.customer.login).to eq('partner')
  177. expect(ticket1.organization.name).to eq('Partner der betreut')
  178. expect(ticket1.created_at.to_s).to eq(Time.zone.parse('2014-11-20 22:33:41 +0000').gmtime.to_s)
  179. expect(ticket1.close_at).to be_nil
  180. # ticket2 is created with state closed
  181. expect(ticket2.title).to eq('test #2')
  182. expect(ticket2.state.name).to eq('closed successful')
  183. expect(ticket2.group.name).to eq('Raw')
  184. expect(ticket2.priority.name).to eq('3 normal')
  185. expect(ticket2.owner.login).to eq('agent-2')
  186. expect(ticket2.customer.login).to eq('jn2')
  187. expect(ticket2.organization.name).to eq('Znuny GmbH')
  188. expect(ticket2.created_at.to_s).to eq(Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s)
  189. expect(ticket2.close_at.to_s).to eq(Time.zone.parse('2014-11-20 23:24:20 +0000').gmtime.to_s)
  190. # ticket3 is created open and now closed
  191. expect(ticket3.title).to eq('test #3')
  192. expect(ticket3.state.name).to eq('closed successful')
  193. expect(ticket3.group.name).to eq('Postmaster')
  194. expect(ticket3.priority.name).to eq('3 normal')
  195. expect(ticket3.owner.login).to eq('agent-2')
  196. expect(ticket3.customer.login).to eq('betreuterkunde2')
  197. expect(ticket3.organization.name).to eq('Noch ein betreuter Kunde')
  198. expect(ticket3.created_at.to_s).to eq(Time.zone.parse('2014-11-21 00:17:40 +0000').gmtime.to_s)
  199. expect(ticket3.close_at.to_s).to eq(Time.zone.parse('2014-11-21 00:21:08 +0000').gmtime.to_s)
  200. # ticket dynamic fields
  201. expect(ticket4.title).to eq('Some other smart subject!')
  202. expect(ticket4.vertriebsweg).to eq('488')
  203. expect(ticket4.te_test).to eq(%w[193 194])
  204. expect(ticket4.sugar_crm_remote_no).to eq('358')
  205. expect(ticket4.sugar_crm_company_selected_no).to eq('69')
  206. expect(ticket4.sugar_crm_company_selection).to eq(['382'])
  207. expect(ticket4.topic_no).to eq('310')
  208. expect(ticket4.open_exchange_ticket_number).to eq('495')
  209. expect(ticket4.hostname).to eq('208')
  210. end
  211. end
  212. context 'when importing attachments' do
  213. let(:article1) { Ticket::Article.find(149) }
  214. let(:attachment1) { article1.attachments.first }
  215. let(:article2) { Ticket::Article.find(156) }
  216. let(:attachment2) { article2.attachments.second }
  217. it 'imports correctly' do
  218. expect(article1.attachments.count).to eq(5)
  219. expect(attachment1.preferences['Mime-Type']).to eq('image/jpeg')
  220. expect(attachment1.filename).to eq('Cursor_und_Banners_and_Alerts_und_Paket-Verwaltung_-_Admin_-_otrs336_und_otrs336.jpg')
  221. expect(article2.attachments.count).to eq(2)
  222. expect(attachment2.preferences['Mime-Type']).to eq('application/pdf; name="=?UTF-8?B?5ZSQ6K+X5LiJ55m+6aaWLnBkZg==?="')
  223. expect(attachment2.filename).to eq('唐诗三百首.pdf')
  224. end
  225. end
  226. end