2016-11-25 16:10:37 +00:00
require 'rails_helper'
RSpec . describe Import :: OTRS :: Article do
def creates_with ( zammad_structure )
expect ( import_object ) . to receive ( :new ) . with ( zammad_structure ) . and_call_original
expect_any_instance_of ( import_object ) . to receive ( :save )
expect_any_instance_of ( described_class ) . to receive ( :reset_primary_key_sequence )
start_import_test
end
def updates_with ( zammad_structure )
expect ( import_object ) . to receive ( :find_by ) . and_return ( existing_object )
2017-09-11 11:16:08 +00:00
expect ( existing_object ) . to receive ( :update! ) . with ( zammad_structure )
2016-11-25 16:10:37 +00:00
expect ( import_object ) . not_to receive ( :new )
start_import_test
end
def load_article_json ( file )
json_fixture ( " import/otrs/article/ #{ file } " )
end
let ( :import_object ) { Ticket :: Article }
let ( :existing_object ) { instance_double ( import_object ) }
let ( :start_import_test ) { described_class . new ( object_structure ) }
context 'customer phone' do
let ( :object_structure ) { load_article_json ( 'customer_phone_attachment' ) }
2016-12-09 12:16:33 +00:00
let ( :zammad_structure ) {
2017-01-16 09:01:20 +00:00
{
created_by_id : '3' ,
updated_by_id : 1 ,
ticket_id : '730' ,
id : '3970' ,
body : 'test #3' ,
from : '"Betreuter Kunde" <kunde2@kunde.de>,' ,
to : 'Postmaster' ,
cc : '' ,
content_type : 'text/plain' ,
subject : 'test #3' ,
in_reply_to : '' ,
message_id : '' ,
references : '' ,
updated_at : '2014-11-21 00:21:08' ,
created_at : '2014-11-21 00:17:41' ,
type_id : 5 ,
internal : false ,
sender_id : 2
}
}
it 'creates' do
expect ( Import :: OTRS :: Article :: AttachmentFactory ) . to receive ( :import )
creates_with ( zammad_structure )
end
it 'updates' do
expect ( Import :: OTRS :: Article :: AttachmentFactory ) . to receive ( :import )
updates_with ( zammad_structure )
end
end
context 'content type with comma' do
let ( :object_structure ) { load_article_json ( 'content_type_comma' ) }
let ( :zammad_structure ) {
2016-12-09 12:16:33 +00:00
{
2016-11-25 16:10:37 +00:00
created_by_id : '3' ,
updated_by_id : 1 ,
ticket_id : '730' ,
id : '3970' ,
body : 'test #3' ,
from : '"Betreuter Kunde" <kunde2@kunde.de>,' ,
to : 'Postmaster' ,
cc : '' ,
2017-01-13 08:20:38 +00:00
content_type : 'text/plain' ,
2016-11-25 16:10:37 +00:00
subject : 'test #3' ,
in_reply_to : '' ,
message_id : '' ,
references : '' ,
updated_at : '2014-11-21 00:21:08' ,
created_at : '2014-11-21 00:17:41' ,
type_id : 5 ,
internal : false ,
sender_id : 2
}
2016-12-09 12:16:33 +00:00
}
it 'creates' do
2016-11-25 16:10:37 +00:00
expect ( Import :: OTRS :: Article :: AttachmentFactory ) . to receive ( :import )
creates_with ( zammad_structure )
end
it 'updates' do
expect ( Import :: OTRS :: Article :: AttachmentFactory ) . to receive ( :import )
updates_with ( zammad_structure )
end
end
2016-12-09 12:54:50 +00:00
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 \n Thank you for installing OTRS. \n \n You will find updates and patches at http://www.otrs.com/open-source/. \n Online documentation is available at http://doc.otrs.org/. \n You can also use our mailing lists http://lists.otrs.org/ \n or our forums at http://forums.otrs.org/ \n \n Regards, \n \n The OTRS Project \n " ,
from : 'OTRS Feedback <feedback@otrs.org>' ,
to : 'Your OTRS System <otrs@localhost>' ,
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
2017-03-27 10:10:52 +00:00
context 'no article body' do
let ( :object_structure ) { load_article_json ( 'customer_phone_no_body' ) }
let ( :zammad_structure ) {
{
created_by_id : '3' ,
updated_by_id : 1 ,
ticket_id : '730' ,
id : '3970' ,
body : '' ,
from : '"Betreuter Kunde" <kunde2@kunde.de>,' ,
to : 'Postmaster' ,
cc : '' ,
content_type : 'text/plain' ,
subject : 'test #3' ,
in_reply_to : '' ,
message_id : '' ,
references : '' ,
updated_at : '2014-11-21 00:21:08' ,
created_at : '2014-11-21 00:17:41' ,
type_id : 5 ,
internal : false ,
sender_id : 2
}
}
it 'creates' do
creates_with ( zammad_structure )
end
it 'updates' do
updates_with ( zammad_structure )
end
end
2016-11-25 16:10:37 +00:00
end