attachment_factory_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'rails_helper'
  2. require 'lib/import/import_factory_examples'
  3. RSpec.describe Import::OTRS::Article::AttachmentFactory do
  4. it_behaves_like 'Import factory'
  5. def load_attachment_json(file)
  6. json_fixture("import/otrs/article/attachment/#{file}")
  7. end
  8. let(:local_article) { instance_double(Ticket::Article, ticket_id: 1337, id: 42) }
  9. let(:attachments) do
  10. [
  11. load_attachment_json('default'),
  12. load_attachment_json('default'),
  13. load_attachment_json('default')
  14. ]
  15. end
  16. let(:start_import) do
  17. described_class.import(
  18. attachments: attachments,
  19. local_article: local_article
  20. )
  21. end
  22. def import_expectations
  23. expect(Store).to receive(:add).exactly(3).times.with(hash_including(
  24. object: 'Ticket::Article',
  25. o_id: local_article.id,
  26. ))
  27. end
  28. def article_attachment_expectations(article_attachments)
  29. expect(local_article).to receive(:attachments).and_return(article_attachments)
  30. end
  31. it 'imports' do
  32. article_attachment_expectations([])
  33. import_expectations
  34. start_import
  35. end
  36. it 'deletes old and reimports' do
  37. dummy_attachment = double()
  38. expect(dummy_attachment).to receive(:delete)
  39. article_attachment_expectations([dummy_attachment])
  40. import_expectations
  41. start_import
  42. end
  43. it 'skips import for same count' do
  44. article_attachment_expectations([1, 2, 3])
  45. expect(Store).not_to receive(:add)
  46. start_import
  47. end
  48. end