From 4cb185c501bb91fdb82b8880f1fa13ac278984f9 Mon Sep 17 00:00:00 2001 From: Gabriel Jablonski Date: Tue, 14 Oct 2025 15:41:12 -0300 Subject: [PATCH] test: fix twilio specs (#119) --- .../twilio/oneoff_sms_campaign_service_spec.rb | 14 +++++++------- .../services/twilio/send_on_twilio_service_spec.rb | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/services/twilio/oneoff_sms_campaign_service_spec.rb b/spec/services/twilio/oneoff_sms_campaign_service_spec.rb index a95887c9c..90636a439 100644 --- a/spec/services/twilio/oneoff_sms_campaign_service_spec.rb +++ b/spec/services/twilio/oneoff_sms_campaign_service_spec.rb @@ -38,19 +38,19 @@ describe Twilio::OneoffSmsCampaignService do contact_with_label1.update_labels([label1.title]) contact_with_label2.update_labels([label2.title]) contact_with_both_labels.update_labels([label1.title, label2.title]) - expect(twilio_messages).to receive(:create!).with( + expect(twilio_messages).to receive(:create).with( body: campaign.message, messaging_service_sid: twilio_sms.messaging_service_sid, to: contact_with_label1.phone_number, status_callback: 'http://localhost:3000/twilio/delivery_status' ).once - expect(twilio_messages).to receive(:create!).with( + expect(twilio_messages).to receive(:create).with( body: campaign.message, messaging_service_sid: twilio_sms.messaging_service_sid, to: contact_with_label2.phone_number, status_callback: 'http://localhost:3000/twilio/delivery_status' ).once - expect(twilio_messages).to receive(:create!).with( + expect(twilio_messages).to receive(:create).with( body: campaign.message, messaging_service_sid: twilio_sms.messaging_service_sid, to: contact_with_both_labels.phone_number, @@ -66,7 +66,7 @@ describe Twilio::OneoffSmsCampaignService do contact.update_labels([label1.title]) expect(Liquid::CampaignTemplateService).to receive(:new).with(campaign: campaign, contact: contact).and_call_original - expect(twilio_messages).to receive(:create!).once + expect(twilio_messages).to receive(:create).once sms_campaign_service.perform end @@ -78,16 +78,16 @@ describe Twilio::OneoffSmsCampaignService do error = Twilio::REST::TwilioError.new("The 'To' number #{contact_error.phone_number} is not a valid phone number.") - allow(twilio_messages).to receive(:create!).and_return(nil) + allow(twilio_messages).to receive(:create).and_return(nil) - expect(twilio_messages).to receive(:create!).with( + expect(twilio_messages).to receive(:create).with( body: campaign.message, messaging_service_sid: twilio_sms.messaging_service_sid, to: contact_error.phone_number, status_callback: 'http://localhost:3000/twilio/delivery_status' ).and_raise(error) - expect(twilio_messages).to receive(:create!).with( + expect(twilio_messages).to receive(:create).with( body: campaign.message, messaging_service_sid: twilio_sms.messaging_service_sid, to: contact_success.phone_number, diff --git a/spec/services/twilio/send_on_twilio_service_spec.rb b/spec/services/twilio/send_on_twilio_service_spec.rb index bbb26c582..1e66d2643 100644 --- a/spec/services/twilio/send_on_twilio_service_spec.rb +++ b/spec/services/twilio/send_on_twilio_service_spec.rb @@ -53,7 +53,7 @@ describe Twilio::SendOnTwilioService do context 'with reply' do it 'if message is sent from chatwoot and is outgoing' do - allow(messages_double).to receive(:create!).and_return(message_record_double) + allow(messages_double).to receive(:create).and_return(message_record_double) allow(message_record_double).to receive(:sid).and_return('1234') outgoing_message = create( @@ -67,7 +67,7 @@ describe Twilio::SendOnTwilioService do it 'if outgoing message has attachment and is for whatsapp' do # check for message attachment url - allow(messages_double).to receive(:create!).with(hash_including(media_url: [anything])).and_return(message_record_double) + allow(messages_double).to receive(:create).with(hash_including(media_url: [anything])).and_return(message_record_double) allow(message_record_double).to receive(:sid).and_return('1234') message = build( @@ -78,12 +78,12 @@ describe Twilio::SendOnTwilioService do message.save! described_class.new(message: message).perform - expect(messages_double).to have_received(:create!) + expect(messages_double).to have_received(:create) end it 'if outgoing message has attachment and is for sms' do # check for message attachment url - allow(messages_double).to receive(:create!).with(hash_including(media_url: [anything])).and_return(message_record_double) + allow(messages_double).to receive(:create).with(hash_including(media_url: [anything])).and_return(message_record_double) allow(message_record_double).to receive(:sid).and_return('1234') message = build( @@ -94,11 +94,11 @@ describe Twilio::SendOnTwilioService do message.save! described_class.new(message: message).perform - expect(messages_double).to have_received(:create!) + expect(messages_double).to have_received(:create) end it 'if message is sent from chatwoot fails' do - allow(messages_double).to receive(:create!).and_raise(Twilio::REST::TwilioError) + allow(messages_double).to receive(:create).and_raise(Twilio::REST::TwilioError) outgoing_message = create( :message, message_type: 'outgoing', inbox: twilio_inbox, account: account, conversation: conversation