fix: Twilio validation over blank messaging_service_sid (#5055)

This commit is contained in:
Tejaswini Chile
2022-07-18 20:02:37 +05:30
committed by GitHub
parent fd44f9f28a
commit 00dc65ef73
4 changed files with 84 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
twilio_channel: {
account_sid: 'sid',
auth_token: 'token',
phone_number: '',
messaging_service_sid: 'MGec8130512b5dd462cfe03095ec1342ed',
name: 'SMS Channel',
medium: 'sms'
@@ -51,6 +52,30 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
expect(json_response['messaging_service_sid']).to eq('MGec8130512b5dd462cfe03095ec1342ed')
end
it 'creates inbox with blank phone number and returns inbox object' do
params = {
twilio_channel: {
account_sid: 'sid-1',
auth_token: 'token-1',
phone_number: '',
messaging_service_sid: 'MGec8130512b5dd462cfe03095ec1111ed',
name: 'SMS Channel',
medium: 'whatsapp'
}
}
allow(twilio_client).to receive(:messages).and_return(message_double)
allow(message_double).to receive(:list).and_return([])
post api_v1_account_channels_twilio_channel_path(account),
params: params,
headers: admin.create_new_auth_token
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
expect(json_response['messaging_service_sid']).to eq('MGec8130512b5dd462cfe03095ec1111ed')
end
context 'with a phone number' do # rubocop:disable RSpec/NestedGroups
let(:params) do
{
@@ -58,13 +83,14 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
account_sid: 'sid',
auth_token: 'token',
phone_number: '+1234567890',
messaging_service_sid: '',
name: 'SMS Channel',
medium: 'sms'
}
}
end
it 'creates inbox and returns inbox object' do
it 'creates inbox with empty messaging service sid and returns inbox object' do
allow(twilio_client).to receive(:messages).and_return(message_double)
allow(message_double).to receive(:list).and_return([])
@@ -78,6 +104,30 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
expect(json_response['name']).to eq('SMS Channel')
expect(json_response['phone_number']).to eq('+1234567890')
end
it 'creates one more inbox with empty messaging service sid' do
params = {
twilio_channel: {
account_sid: 'sid-1',
auth_token: 'token-1',
phone_number: '+1224466880',
messaging_service_sid: '',
name: 'SMS Channel',
medium: 'whatsapp'
}
}
allow(twilio_client).to receive(:messages).and_return(message_double)
allow(message_double).to receive(:list).and_return([])
post api_v1_account_channels_twilio_channel_path(account),
params: params,
headers: admin.create_new_auth_token
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
expect(json_response['phone_number']).to eq('whatsapp:+1224466880')
end
end
it 'return error if Twilio tokens are incorrect' do