diff --git a/lib/import/otrs/article.rb b/lib/import/otrs/article.rb index 6e3fe422e..888f751c5 100644 --- a/lib/import/otrs/article.rb +++ b/lib/import/otrs/article.rb @@ -36,8 +36,7 @@ module Import def import(article) create_or_update(map(article)) - return if !article['Attachments'] - return if article['Attachments'].empty? + return if article['Attachments'].blank? Import::OTRS::Article::AttachmentFactory.import( attachments: article['Attachments'], @@ -69,6 +68,14 @@ module Import end def map(article) + mapped = map_default(article) + # if no content type is set make sure to remove it + # so Zammad can set the default content type + mapped.delete(:content_type) if mapped[:content_type].blank? + mapped + end + + def map_default(article) { created_by_id: 1, updated_by_id: 1, diff --git a/spec/import/otrs/article_spec.rb b/spec/import/otrs/article_spec.rb index 456fd0c14..5fe789608 100644 --- a/spec/import/otrs/article_spec.rb +++ b/spec/import/otrs/article_spec.rb @@ -60,4 +60,38 @@ RSpec.describe Import::OTRS::Article do updates_with(zammad_structure) end end + + context 'no content type' do + + let(:object_structure) { load_article_json('no_content_type') } + let(:zammad_structure) { + { + created_by_id: '1', + updated_by_id: 1, + ticket_id: '999', + id: '999', + body: "Welcome!\n\nThank you for installing OTRS.\n\nYou will find updates and patches at http://www.otrs.com/open-source/.\nOnline documentation is available at http://doc.otrs.org/.\nYou can also use our mailing lists http://lists.otrs.org/\nor our forums at http://forums.otrs.org/\n\nRegards,\n\nThe OTRS Project\n", + from: 'OTRS Feedback ', + to: 'Your OTRS System ', + cc: nil, + subject: 'Welcome to OTRS!', + in_reply_to: nil, + message_id: '<007@localhost>', + references: nil, + updated_at: '2014-06-24 09:32:14', + created_at: '2010-08-02 14:00:00', + type_id: 1, + internal: false, + sender_id: 2 + } + } + + it 'creates' do + creates_with(zammad_structure) + end + + it 'updates' do + updates_with(zammad_structure) + end + end end