test(inboxes): cover webhook setup automation

This commit is contained in:
Sojan Jose
2026-02-13 16:47:23 -08:00
parent 1f66034750
commit 672f81f3a8
3 changed files with 24 additions and 1 deletions
@@ -123,7 +123,6 @@
},
"TWILIO": {
"TITLE": "Twilio SMS/WhatsApp Channel",
"DESC": "Integrate Twilio and start supporting your customers via SMS or WhatsApp. Chatwoot automatically configures the required callback URLs for you.",
"ACCOUNT_SID": {
"LABEL": "Account SID",
"PLACEHOLDER": "Please enter your Twilio Account SID",
@@ -38,6 +38,8 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
context 'when user is logged in' do
context 'with user as administrator' do
it 'creates inbox and returns inbox object' do
expect(Twilio::WebhookSetupService).to receive(:new).and_return(twilio_webhook_setup_service)
expect(twilio_webhook_setup_service).to receive(:perform)
allow(twilio_client).to receive(:messages).and_return(message_double)
allow(message_double).to receive(:list).and_return([])
@@ -131,6 +133,8 @@ RSpec.describe '/api/v1/accounts/{account.id}/channels/twilio_channel', type: :r
end
it 'return error if Twilio tokens are incorrect' do
expect(twilio_webhook_setup_service).not_to receive(:perform)
expect(Twilio::WebhookSetupService).not_to receive(:new)
allow(twilio_client).to receive(:messages).and_return(message_double)
allow(message_double).to receive(:list).and_raise(Twilio::REST::TwilioError)
@@ -60,6 +60,26 @@ describe Twilio::WebhookSetupService do
sms_url: twilio_callback_index_url
)
end
it 'strips whatsapp prefix before looking up phone number' do
phone_channel = create(
:channel_twilio_sms,
:with_phone_number,
:whatsapp,
phone_number: 'whatsapp:+1234567890',
messaging_service_sid: nil
)
allow(twilio_client).to receive(:incoming_phone_numbers).and_return(phone_double)
allow(phone_double).to receive(:list).and_return([phone_record_double])
allow(phone_record_double).to receive(:sid).and_return('1234')
described_class.new(inbox: phone_channel.inbox).perform
expect(phone_double).to have_received(:list).with(
phone_number: '+1234567890'
)
end
end
end
end