update_cti_logs_by_caller_job_spec.rb 911 B

123456789101112131415161718192021222324252627282930
  1. require 'rails_helper'
  2. RSpec.describe UpdateCtiLogsByCallerJob, type: :job do
  3. let(:phone) { '1234567890' }
  4. let!(:logs) { create_list(:cti_log, 5, direction: :in, from: phone) }
  5. let(:log_prefs) { logs.each(&:reload).map(&:preferences) }
  6. it 'accepts a phone number' do
  7. expect { described_class.perform_now(phone) }
  8. .not_to raise_error
  9. end
  10. context 'with no user matching provided phone number' do
  11. it 'updates Cti::Logs from that number with "preferences" => {}' do
  12. described_class.perform_now(phone)
  13. expect(log_prefs).to all(be_empty)
  14. end
  15. end
  16. context 'with existing user matching provided phone number' do
  17. before { create(:user, phone: phone) }
  18. it 'updates Cti::Logs from that number with valid "preferences" hash' do
  19. described_class.perform_now(phone)
  20. expect(log_prefs).to all(include('from' => a_kind_of(Array)))
  21. end
  22. end
  23. end