From 47c880f445183c76efb3a126c6c01af90d523717 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Fri, 16 Dec 2016 11:12:15 +0100 Subject: [PATCH] Fixed issue #548 - Empty created_at of customer user record brakes import. --- lib/import/otrs/customer_user.rb | 7 + .../otrs/customer_user/no_timestamps.json | 348 ++++++++++++++++++ spec/import/otrs/customer_user_spec.rb | 47 ++- spec/rails_helper.rb | 3 + 4 files changed, 404 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/import/otrs/customer_user/no_timestamps.json diff --git a/lib/import/otrs/customer_user.rb b/lib/import/otrs/customer_user.rb index 211b14c8e..cef25f1a0 100644 --- a/lib/import/otrs/customer_user.rb +++ b/lib/import/otrs/customer_user.rb @@ -64,6 +64,13 @@ module Import end def map(customer) + mapped = map_default(customer) + mapped[:created_at] ||= DateTime.current + mapped[:updated_at] ||= DateTime.current + mapped + end + + def map_default(customer) { created_by_id: 1, updated_by_id: 1, diff --git a/spec/fixtures/import/otrs/customer_user/no_timestamps.json b/spec/fixtures/import/otrs/customer_user/no_timestamps.json new file mode 100644 index 000000000..8b112f78a --- /dev/null +++ b/spec/fixtures/import/otrs/customer_user/no_timestamps.json @@ -0,0 +1,348 @@ +{ + "CustomerCompanyCity": "test712259", + "Config": { + "CustomerUserEmailUniqCheck": 1, + "CustomerUserSearchListLimit": 250, + "CustomerCompanySupport": 1, + "CustomerValid": "valid_id", + "CustomerUserSearchFields": [ + "login", + "first_name", + "last_name", + "customer_id" + ], + "CustomerUserSearchPrefix": "*", + "Params": { + "Table": "customer_user", + "CaseSensitive": 0 + }, + "CustomerUserListFields": [ + "first_name", + "last_name", + "email" + ], + "Map": [ + [ + "UserTitle", + "Title", + "title", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserFirstname", + "Firstname", + "first_name", + 1, + 1, + "var", + "", + 0 + ], + [ + "UserLastname", + "Lastname", + "last_name", + 1, + 1, + "var", + "", + 0 + ], + [ + "UserLogin", + "Username", + "login", + 1, + 1, + "var", + "", + 0 + ], + [ + "UserPassword", + "Password", + "pw", + 0, + 0, + "var", + "", + 0 + ], + [ + "UserEmail", + "Email", + "email", + 1, + 1, + "var", + "", + 0 + ], + [ + "UserCustomerID", + "CustomerID", + "customer_id", + 0, + 1, + "var", + "", + 0 + ], + [ + "UserPhone", + "Phone", + "phone", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserFax", + "Fax", + "fax", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserMobile", + "Mobile", + "mobile", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserStreet", + "Street", + "street", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserZip", + "Zip", + "zip", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserCity", + "City", + "city", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserCountry", + "Country", + "country", + 1, + 0, + "var", + "", + 0 + ], + [ + "UserComment", + "Comment", + "comments", + 1, + 0, + "var", + "", + 0 + ], + [ + "ValidID", + "Valid", + "valid_id", + 0, + 1, + "int", + "", + 0 + ] + ], + "CustomerKey": "login", + "CustomerUserSearchSuffix": "*", + "Module": "Kernel::System::CustomerUser::DB", + "CacheTTL": 86400, + "Selections": {}, + "CustomerID": "customer_id", + "Name": "Database Backend", + "CustomerUserPostMasterSearchFields": [ + "email" + ], + "CustomerUserNameFields": [ + "title", + "first_name", + "last_name" + ] + }, + "UserCustomerID": "test712259", + "CustomerCompanyComment": "test712259", + "Source": "CustomerUser", + "UserTitle": "", + "CompanyConfig": { + "CustomerCompanySearchFields": [ + "customer_id", + "name" + ], + "CustomerCompanyListFields": [ + "customer_id", + "name" + ], + "Module": "Kernel::System::CustomerCompany::DB", + "CustomerCompanyKey": "customer_id", + "CustomerCompanySearchSuffix": "*", + "CacheTTL": 86400, + "CustomerCompanySearchListLimit": 250, + "CustomerCompanySearchPrefix": "", + "CustomerCompanyValid": "valid_id", + "Params": { + "Table": "customer_company", + "CaseSensitive": 0 + }, + "Map": [ + [ + "CustomerID", + "CustomerID", + "customer_id", + 0, + 1, + "var", + "", + 0 + ], + [ + "CustomerCompanyName", + "Customer", + "name", + 1, + 1, + "var", + "", + 0 + ], + [ + "CustomerCompanyStreet", + "Street", + "street", + 1, + 0, + "var", + "", + 0 + ], + [ + "CustomerCompanyZIP", + "Zip", + "zip", + 1, + 0, + "var", + "", + 0 + ], + [ + "CustomerCompanyCity", + "City", + "city", + 1, + 0, + "var", + "", + 0 + ], + [ + "CustomerCompanyCountry", + "Country", + "country", + 1, + 0, + "var", + "", + 0 + ], + [ + "CustomerCompanyURL", + "URL", + "url", + 1, + 0, + "var", + "[% Data.CustomerCompanyURL | html %]", + 0 + ], + [ + "CustomerCompanyComment", + "Comment", + "comments", + 1, + 0, + "var", + "", + 0 + ], + [ + "ValidID", + "Valid", + "valid_id", + 0, + 1, + "int", + "", + 0 + ] + ], + "Name": "Database Backend" + }, + "UserZip": null, + "UserLastname": "test669673", + "ChangeBy": "1", + "CreateTime": null, + "UserLogin": "test669673", + "UserPhone": null, + "CustomerID": "test712259", + "CustomerCompanyValidID": "1", + "CustomerCompanyZIP": "test712259", + "UserCountry": null, + "UserPassword": "f8be19af2f25837a31eff9131b0e47a5173290652c04a48b49b86474d48825ee", + "ValidID": "1", + "UserRefreshTime": "0", + "UserEmail": "qa100@t-online.de", + "UserComment": "", + "UserID": "test669673", + "UserFirstname": "test669673", + "CustomerCompanyCountry": "test712259", + "UserFax": null, + "CreateBy": "1", + "ChangeTime": null, + "UserShowTickets": "25", + "UserStreet": null, + "CustomerCompanyURL": "test712259", + "CustomerCompanyName": "test712259", + "UserMobile": null, + "CustomerCompanyStreet": "test712259", + "UserCity": null +} \ No newline at end of file diff --git a/spec/import/otrs/customer_user_spec.rb b/spec/import/otrs/customer_user_spec.rb index 0eb948845..7a69f1430 100644 --- a/spec/import/otrs/customer_user_spec.rb +++ b/spec/import/otrs/customer_user_spec.rb @@ -37,7 +37,7 @@ RSpec.describe Import::OTRS::CustomerUser do let(:organization) { instance_double(Organization) } let(:organization_id) { 1337 } - context 'Customer User' do + context 'regular user' do let(:object_structure) { load_customer_json('default') } let(:zammad_structure) { @@ -73,4 +73,49 @@ RSpec.describe Import::OTRS::CustomerUser do updates_with(zammad_structure) end end + + context 'no timestamps' do + + let(:object_structure) { load_customer_json('no_timestamps') } + let(:zammad_structure) { + { + created_by_id: '1', + updated_by_id: '1', + active: true, + source: 'OTRS Import', + organization_id: 1337, + role_ids: [3], + updated_at: DateTime.current, + created_at: DateTime.current, + note: '', + email: 'qa100@t-online.de', + firstname: 'test669673', + lastname: 'test669673', + login: 'test669673', + password: 'f8be19af2f25837a31eff9131b0e47a5173290652c04a48b49b86474d48825ee', + phone: nil, + fax: nil, + mobile: nil, + street: nil, + zip: nil, + city: nil, + country: nil + }} + + before(:each) do + travel_to DateTime.current + end + + after(:each) do + travel_back + end + + it 'creates' do + creates_with(zammad_structure) + end + + it 'updates' do + updates_with(zammad_structure) + end + end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 7c8bbaf6a..fc688e11d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -31,6 +31,9 @@ RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_path = "#{::Rails.root}/spec/fixtures" + # make usage of time travel helpers possible + config.include ActiveSupport::Testing::TimeHelpers + # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true.