enqueue_communicate_email_job_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'rails_helper'
  2. RSpec.describe Ticket::Article::EnqueueCommunicateEmailJob, performs_jobs: true do
  3. before { allow(Delayed::Job).to receive(:enqueue).and_call_original }
  4. let(:article) { create(:ticket_article, **(try(:factory_options) || {})) }
  5. shared_examples 'for no-op' do
  6. it 'is a no-op' do
  7. expect { article }.not_to have_enqueued_job(TicketArticleCommunicateEmailJob)
  8. end
  9. end
  10. shared_examples 'for success' do
  11. it 'enqueues the Email background job' do
  12. expect { article }.to have_enqueued_job(TicketArticleCommunicateEmailJob)
  13. end
  14. end
  15. context 'when in Import Mode' do
  16. before { Setting.set('import_mode', true) }
  17. include_examples 'for no-op'
  18. end
  19. context 'when article is created during Channel::EmailParser#process', application_handle: 'scheduler.postmaster' do
  20. include_examples 'for no-op'
  21. end
  22. context 'when article is from a customer' do
  23. let(:factory_options) { { sender_name: 'Customer' } }
  24. include_examples 'for no-op'
  25. end
  26. context 'when article is an email' do
  27. let(:factory_options) { { sender_name: 'Agent', type_name: 'email' } }
  28. include_examples 'for success'
  29. end
  30. end