enqueue_communicate_twitter_job_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Ticket::Article::EnqueueCommunicateTwitterJob, 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(CommunicateTwitterJob)
  9. end
  10. end
  11. shared_examples 'for success' do
  12. it 'enqueues the Twitter background job' do
  13. expect { article }.to have_enqueued_job(CommunicateTwitterJob)
  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 not a tweet' do
  28. let(:factory_options) { { sender_name: 'Agent', type_name: 'email' } }
  29. include_examples 'for no-op'
  30. end
  31. context 'when article is a tweet' do
  32. let(:factory_options) { { sender_name: 'Agent', type_name: 'twitter status' } }
  33. include_examples 'for success'
  34. end
  35. context 'when article is a DM' do
  36. let(:factory_options) { { sender_name: 'Agent', type_name: 'twitter direct-message' } }
  37. include_examples 'for success'
  38. context 'when #to attribute is missing' do
  39. let(:factory_options) { { sender_name: 'Agent', type_name: 'twitter direct-message', to: nil } }
  40. it 'raises an error' do
  41. expect { article }.to raise_error(Exceptions::UnprocessableEntity)
  42. end
  43. end
  44. end
  45. end