Sha256: 88b8b07e2457da5a0ee164e72b211bc5845b57d8057902f4ad3d5071cdbc8bc5

Contents?: true

Size: 1.85 KB

Versions: 2

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

RSpec.describe TwilioBase::PhoneNumber do
  describe '.find_or_create' do
    before do
      ENV['COUNTRY_CODE'] = 'GB'
    end

    after do
      ENV['COUNTRY_CODE'] = nil
    end

    context 'phone number exists' do
      it 'does not create a new phone number' do
        number = FactoryBot.generate(:phone_number)
        phone_number = TwilioBase::Fake::IncomingPhoneNumber
          .new.create(phone_number: number)

        expect { described_class.find_or_create(phone_number.phone_number) }
          .not_to(
            change { TwilioBase::Fake::IncomingPhoneNumber.phone_numbers.count }
          )
      end

      it 'returns the phone number' do
        number = FactoryBot.generate(:phone_number)
        phone_number = TwilioBase::Fake::IncomingPhoneNumber
          .new.create(phone_number: number)

        expect(described_class.find_or_create(phone_number.phone_number))
          .to eq phone_number
      end
    end

    context 'phone number does not exist' do
      it 'does creates a new phone number' do
        expect { described_class.find_or_create(nil) }
          .to change {
            TwilioBase::Fake::IncomingPhoneNumber.phone_numbers.count
          }.by(1)
      end

      it 'returns the phone number' do
        expect(described_class.find_or_create(nil))
          .to eq TwilioBase::Fake::IncomingPhoneNumber.phone_numbers.last
      end
    end
  end

  describe '.incoming_phone_number_list' do
    it 'returns active numbers' do
      phone_numbers = []
      3.times do
        phone_numbers << TwilioBase::Fake::IncomingPhoneNumber::PhoneNumber.new(
          Faker::PhoneNumber.phone_number
        )
      end
      TwilioBase::Fake::IncomingPhoneNumber.phone_numbers = phone_numbers

      expect(described_class.incoming_phone_number_list)
        .to match_array(phone_numbers)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twilio_base-1.11.1101 spec/services/twilio_base/phone_number_spec.rb
twilio_base-1.11.11 spec/services/twilio_base/phone_number_spec.rb