chore: don't provision Twiml app if sid present
This commit is contained in:
@@ -66,6 +66,8 @@ module Enterprise::Channel::TwilioSms
|
||||
end
|
||||
|
||||
def provision_twiml_app
|
||||
return if twiml_app_sid.present?
|
||||
|
||||
validate_voice_capability!
|
||||
service = ::Twilio::VoiceWebhookSetupService.new(channel: self)
|
||||
self.twiml_app_sid = service.perform
|
||||
|
||||
@@ -57,6 +57,9 @@ RSpec.describe Channel::TwilioSms do
|
||||
|
||||
describe 'provisioning on create' do
|
||||
it 'stores twiml_app_sid from the webhook setup service' do
|
||||
stub_request(:get, %r{api.twilio.com/2010-04-01/Accounts/.*/IncomingPhoneNumbers.json})
|
||||
.to_return(status: 200, body: { incoming_phone_numbers: [{ capabilities: { 'voice' => true } }] }.to_json,
|
||||
headers: { 'Content-Type' => 'application/json' })
|
||||
channel = create(:channel_twilio_sms, :with_voice, twiml_app_sid: nil)
|
||||
expect(channel.twiml_app_sid).to eq(twiml_app_sid)
|
||||
end
|
||||
@@ -89,8 +92,7 @@ RSpec.describe Channel::TwilioSms do
|
||||
end
|
||||
|
||||
it 'does not fail if Twilio API errors' do
|
||||
error_response = instance_double(Twilio::HTTP::Response, status_code: 404, body: {})
|
||||
allow(app_context).to receive(:delete).and_raise(Twilio::REST::RestError.new('Not found', error_response))
|
||||
allow(app_context).to receive(:delete).and_raise(StandardError.new('Not found'))
|
||||
|
||||
expect { channel.update!(voice_enabled: false) }.not_to raise_error
|
||||
expect(channel.reload.twiml_app_sid).to be_nil
|
||||
|
||||
Reference in New Issue
Block a user