Added comprehensive Twilio WhatsApp content template support (Phase 1)
enabling text, media, and quick reply templates with proper parameter
conversion, sync capabilities.
**Template Types Supported**
- Basic Text Templates: Simple text with variables ({{1}}, {{2}})
- Media Templates: Image/Video/Document templates with text variables
- Quick Reply Templates: Interactive button templates
Front end changes is available via #12277
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
51 lines
1.7 KiB
Ruby
51 lines
1.7 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Channels::Twilio::TemplatesSyncJob do
|
|
let!(:account) { create(:account) }
|
|
let!(:twilio_channel) { create(:channel_twilio_sms, medium: :whatsapp, account: account) }
|
|
|
|
it 'enqueues the job' do
|
|
expect { described_class.perform_later(twilio_channel) }.to have_enqueued_job(described_class)
|
|
.on_queue('low')
|
|
.with(twilio_channel)
|
|
end
|
|
|
|
describe '#perform' do
|
|
let(:template_sync_service) { instance_double(Twilio::TemplateSyncService) }
|
|
|
|
context 'with successful template sync' do
|
|
it 'creates and calls the template sync service' do
|
|
expect(Twilio::TemplateSyncService).to receive(:new).with(channel: twilio_channel).and_return(template_sync_service)
|
|
expect(template_sync_service).to receive(:call).and_return(true)
|
|
|
|
described_class.perform_now(twilio_channel)
|
|
end
|
|
end
|
|
|
|
context 'with template sync exception' do
|
|
let(:error_message) { 'Twilio API error' }
|
|
|
|
before do
|
|
allow(Twilio::TemplateSyncService).to receive(:new).with(channel: twilio_channel).and_return(template_sync_service)
|
|
allow(template_sync_service).to receive(:call).and_raise(StandardError, error_message)
|
|
end
|
|
|
|
it 'does not suppress the exception' do
|
|
expect { described_class.perform_now(twilio_channel) }.to raise_error(StandardError, error_message)
|
|
end
|
|
end
|
|
|
|
context 'with nil channel' do
|
|
it 'handles nil channel gracefully' do
|
|
expect { described_class.perform_now(nil) }.to raise_error(NoMethodError)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'job configuration' do
|
|
it 'is configured to run on low priority queue' do
|
|
expect(described_class.queue_name).to eq('low')
|
|
end
|
|
end
|
|
end
|