enqueue_communicate_twitter_job_spec.rb 1.7 KB

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