article_spec.rb 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. require 'rails_helper'
  2. RSpec.describe Import::OTRS::Article do
  3. def creates_with(zammad_structure)
  4. expect(import_object).to receive(:new).with(zammad_structure).and_call_original
  5. expect_any_instance_of(import_object).to receive(:save)
  6. expect_any_instance_of(described_class).to receive(:reset_primary_key_sequence)
  7. start_import_test
  8. end
  9. def updates_with(zammad_structure)
  10. expect(import_object).to receive(:find_by).and_return(existing_object)
  11. expect(existing_object).to receive(:update!).with(zammad_structure)
  12. expect(import_object).not_to receive(:new)
  13. start_import_test
  14. end
  15. def load_article_json(file)
  16. json_fixture("import/otrs/article/#{file}")
  17. end
  18. let(:import_object) { Ticket::Article }
  19. let(:existing_object) { instance_double(import_object) }
  20. let(:start_import_test) { described_class.new(object_structure) }
  21. context 'customer phone' do
  22. let(:object_structure) { load_article_json('customer_phone_attachment') }
  23. let(:zammad_structure) do
  24. {
  25. created_by_id: '3',
  26. updated_by_id: 1,
  27. ticket_id: '730',
  28. id: '3970',
  29. body: 'test #3',
  30. from: '"Betreuter Kunde" <kunde2@kunde.de>,',
  31. to: 'Postmaster',
  32. cc: '',
  33. content_type: 'text/plain',
  34. subject: 'test #3',
  35. in_reply_to: '',
  36. message_id: '',
  37. references: '',
  38. updated_at: '2014-11-21 00:21:08',
  39. created_at: '2014-11-21 00:17:41',
  40. type_id: 5,
  41. internal: false,
  42. sender_id: 2
  43. }
  44. end
  45. it 'creates' do
  46. expect(Import::OTRS::Article::AttachmentFactory).to receive(:import)
  47. creates_with(zammad_structure)
  48. end
  49. it 'updates' do
  50. expect(Import::OTRS::Article::AttachmentFactory).to receive(:import)
  51. updates_with(zammad_structure)
  52. end
  53. end
  54. context 'content type with comma' do
  55. let(:object_structure) { load_article_json('content_type_comma') }
  56. let(:zammad_structure) do
  57. {
  58. created_by_id: '3',
  59. updated_by_id: 1,
  60. ticket_id: '730',
  61. id: '3970',
  62. body: 'test #3',
  63. from: '"Betreuter Kunde" <kunde2@kunde.de>,',
  64. to: 'Postmaster',
  65. cc: '',
  66. content_type: 'text/plain',
  67. subject: 'test #3',
  68. in_reply_to: '',
  69. message_id: '',
  70. references: '',
  71. updated_at: '2014-11-21 00:21:08',
  72. created_at: '2014-11-21 00:17:41',
  73. type_id: 5,
  74. internal: false,
  75. sender_id: 2
  76. }
  77. end
  78. it 'creates' do
  79. expect(Import::OTRS::Article::AttachmentFactory).to receive(:import)
  80. creates_with(zammad_structure)
  81. end
  82. it 'updates' do
  83. expect(Import::OTRS::Article::AttachmentFactory).to receive(:import)
  84. updates_with(zammad_structure)
  85. end
  86. end
  87. context 'no content type' do
  88. let(:object_structure) { load_article_json('no_content_type') }
  89. let(:zammad_structure) do
  90. {
  91. created_by_id: '1',
  92. updated_by_id: 1,
  93. ticket_id: '999',
  94. id: '999',
  95. 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",
  96. from: 'OTRS Feedback <feedback@otrs.org>',
  97. to: 'Your OTRS System <otrs@localhost>',
  98. cc: nil,
  99. subject: 'Welcome to OTRS!',
  100. in_reply_to: nil,
  101. message_id: '<007@localhost>',
  102. references: nil,
  103. updated_at: '2014-06-24 09:32:14',
  104. created_at: '2010-08-02 14:00:00',
  105. type_id: 1,
  106. internal: false,
  107. sender_id: 2
  108. }
  109. end
  110. it 'creates' do
  111. creates_with(zammad_structure)
  112. end
  113. it 'updates' do
  114. updates_with(zammad_structure)
  115. end
  116. end
  117. context 'no article body' do
  118. let(:object_structure) { load_article_json('customer_phone_no_body') }
  119. let(:zammad_structure) do
  120. {
  121. created_by_id: '3',
  122. updated_by_id: 1,
  123. ticket_id: '730',
  124. id: '3970',
  125. body: '',
  126. from: '"Betreuter Kunde" <kunde2@kunde.de>,',
  127. to: 'Postmaster',
  128. cc: '',
  129. content_type: 'text/plain',
  130. subject: 'test #3',
  131. in_reply_to: '',
  132. message_id: '',
  133. references: '',
  134. updated_at: '2014-11-21 00:21:08',
  135. created_at: '2014-11-21 00:17:41',
  136. type_id: 5,
  137. internal: false,
  138. sender_id: 2
  139. }
  140. end
  141. it 'creates' do
  142. creates_with(zammad_structure)
  143. end
  144. it 'updates' do
  145. updates_with(zammad_structure)
  146. end
  147. end
  148. end