ticket_article_communicate_email_job_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe TicketArticleCommunicateEmailJob, type: :job do
  4. describe '#perform' do
  5. context 'for an email article' do
  6. let(:article) { create(:ticket_article, type_name: 'email') }
  7. let(:recipient_list) { [article.to, article.cc].compact_blank.join(',') }
  8. before { allow(Rails.logger).to receive(:info) }
  9. # What we _really_ want is to expect an email to be sent.
  10. # So why are we testing log messages instead?
  11. #
  12. # Because so far, our attempts to test email dispatch have either
  13. # a) been closely tied to implementation, with lots of ugly mock objects; or
  14. # b) had to test faraway classes like Channel::Driver::Imap.
  15. #
  16. # In other words, this test is NOT set in stone, and very open to improvement.
  17. it 'records outgoing email dispatch to Rails log' do
  18. described_class.perform_now(article.id)
  19. expect(Rails.logger)
  20. .to have_received(:info)
  21. .with("Send email to: '#{recipient_list}' (from #{article.from})")
  22. end
  23. end
  24. end
  25. end