From 8a5de1463abf7a1544de562ce2f66c9ac03180cd Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 21 Nov 2014 00:58:37 +0100 Subject: [PATCH] Improved importer. --- lib/import/otrs2.rb | 4 +- test/integration/otrs_import_test.rb | 56 ++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/lib/import/otrs2.rb b/lib/import/otrs2.rb index 02431d76d..4e7dfb540 100644 --- a/lib/import/otrs2.rb +++ b/lib/import/otrs2.rb @@ -428,7 +428,7 @@ module Import::OTRS2 # find owner if ticket_new[:owner] - user = User.lookup( :login => ticket_new[:owner] ) + user = User.lookup( :login => ticket_new[:owner].downcase ) if user ticket_new[:owner_id] = user.id else @@ -439,7 +439,7 @@ module Import::OTRS2 # find customer if ticket_new[:customer] - user = User.lookup( :login => ticket_new[:customer] ) + user = User.lookup( :login => ticket_new[:customer].downcase ) if user ticket_new[:customer_id] = user.id else diff --git a/test/integration/otrs_import_test.rb b/test/integration/otrs_import_test.rb index ff92b300d..d60febe93 100644 --- a/test/integration/otrs_import_test.rb +++ b/test/integration/otrs_import_test.rb @@ -6,7 +6,7 @@ class OtrsImportTest < ActiveSupport::TestCase # check count of imported items test 'check counts' do #agent_count = User.where() - assert_equal( 600, Ticket.count, 'tickets' ) + assert_equal( 603, Ticket.count, 'tickets' ) assert_equal( 10, Ticket::State.count, 'ticket states' ) assert_equal( 24, Group.count, 'groups' ) @@ -88,9 +88,17 @@ class OtrsImportTest < ActiveSupport::TestCase # check all synced states and state types test 'check ticket stats' do - state_new = Ticket::State.find(1) - assert_equal( 'new', state_new.name ) - assert_equal( 'new', state_new.state_type.name ) + 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 ) end # check groups/queues @@ -123,4 +131,44 @@ class OtrsImportTest < ActiveSupport::TestCase organization2 = user2.organization assert( organization2, nil ) end + + # 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 ) + assert_equal( Time.parse('2014-11-20 22:33:41 +0000').gmtime.to_s, ticket.created_at.to_s ) + assert_equal( nil, ticket.close_time ) + + # 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 ) + assert_equal( Time.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.created_at.to_s ) + assert_equal( Time.parse('2014-11-20 23:24:20 +0000').gmtime.to_s, ticket.close_time.to_s ) + + # 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 ) + assert_equal( Time.parse('2014-11-21 00:17:40 +0000').gmtime.to_s, ticket.created_at.to_s ) + assert_equal( Time.parse('2014-11-21 00:21:08 +0000').gmtime.to_s, ticket.close_time.to_s ) + end end \ No newline at end of file