2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
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) }
|
2021-05-12 10:31:00 +00:00
|
|
|
let(:log_prefs) { logs.each(&:reload).map { |log| log.preferences[:from] } }
|
2018-07-23 08:24:23 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-05-12 10:31:00 +00:00
|
|
|
expect(log_prefs).to eq(Array.new(5) { nil })
|
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)
|
|
|
|
|
2021-05-12 10:31:00 +00:00
|
|
|
expect(log_prefs).not_to eq(Array.new(5) { nil })
|
2018-07-23 08:24:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|