update_cti_logs_by_caller_job_spec.rb 1005 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe UpdateCtiLogsByCallerJob, type: :job do
  4. let(:phone) { '1234567890' }
  5. let!(:logs) { create_list(:cti_log, 5, direction: :in, from: phone) }
  6. let(:log_prefs) { logs.each(&:reload).map { |log| log.preferences[:from] } }
  7. it 'accepts a phone number' do
  8. expect { described_class.perform_now(phone) }
  9. .not_to raise_error
  10. end
  11. context 'with no user matching provided phone number' do
  12. it 'updates Cti::Logs from that number with "preferences" => {}' do
  13. described_class.perform_now(phone)
  14. expect(log_prefs).to eq(Array.new(5) { nil })
  15. end
  16. end
  17. context 'with existing user matching provided phone number' do
  18. before { create(:user, phone: phone) }
  19. it 'updates Cti::Logs from that number with valid "preferences" hash' do
  20. described_class.perform_now(phone)
  21. expect(log_prefs).not_to eq(Array.new(5) { nil })
  22. end
  23. end
  24. end