2018-07-23 08:24:23 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe UpdateCtiLogsByCallerJob, type: :job do
|
|
|
|
let(:phone) { '1234567890' }
|
|
|
|
let!(:logs) { create_list(:cti_log, 5, direction: :in, from: phone) }
|
|
|
|
let(:log_prefs) { logs.each(&:reload).map(&:preferences) }
|
|
|
|
|
|
|
|
it 'accepts a phone number' do
|
|
|
|
expect { described_class.perform_now(phone) }
|
|
|
|
.not_to raise_error
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no user matching provided phone number' do
|
|
|
|
it 'updates Cti::Logs from that number with "preferences" => {}' do
|
|
|
|
described_class.perform_now(phone)
|
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(log_prefs).to all(be_empty)
|
2018-07-23 08:24:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with existing user matching provided phone number' do
|
|
|
|
before { create(:user, phone: phone) }
|
|
|
|
|
|
|
|
it 'updates Cti::Logs from that number with valid "preferences" hash' do
|
|
|
|
described_class.perform_now(phone)
|
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(log_prefs).to all(include('from' => a_kind_of(Array)))
|
2018-07-23 08:24:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|