enqueue_communicate_sms_job_spec.rb 1.2 KB

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