test: fix twilio specs (#119)

This commit is contained in:
Gabriel Jablonski 2025-10-14 15:41:12 -03:00 committed by GitHub
parent 9cd3edb497
commit 4cb185c501
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 13 deletions

View File

@ -38,19 +38,19 @@ describe Twilio::OneoffSmsCampaignService do
contact_with_label1.update_labels([label1.title]) contact_with_label1.update_labels([label1.title])
contact_with_label2.update_labels([label2.title]) contact_with_label2.update_labels([label2.title])
contact_with_both_labels.update_labels([label1.title, 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, body: campaign.message,
messaging_service_sid: twilio_sms.messaging_service_sid, messaging_service_sid: twilio_sms.messaging_service_sid,
to: contact_with_label1.phone_number, to: contact_with_label1.phone_number,
status_callback: 'http://localhost:3000/twilio/delivery_status' status_callback: 'http://localhost:3000/twilio/delivery_status'
).once ).once
expect(twilio_messages).to receive(:create!).with( expect(twilio_messages).to receive(:create).with(
body: campaign.message, body: campaign.message,
messaging_service_sid: twilio_sms.messaging_service_sid, messaging_service_sid: twilio_sms.messaging_service_sid,
to: contact_with_label2.phone_number, to: contact_with_label2.phone_number,
status_callback: 'http://localhost:3000/twilio/delivery_status' status_callback: 'http://localhost:3000/twilio/delivery_status'
).once ).once
expect(twilio_messages).to receive(:create!).with( expect(twilio_messages).to receive(:create).with(
body: campaign.message, body: campaign.message,
messaging_service_sid: twilio_sms.messaging_service_sid, messaging_service_sid: twilio_sms.messaging_service_sid,
to: contact_with_both_labels.phone_number, to: contact_with_both_labels.phone_number,
@ -66,7 +66,7 @@ describe Twilio::OneoffSmsCampaignService do
contact.update_labels([label1.title]) contact.update_labels([label1.title])
expect(Liquid::CampaignTemplateService).to receive(:new).with(campaign: campaign, contact: contact).and_call_original 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 sms_campaign_service.perform
end 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.") 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, body: campaign.message,
messaging_service_sid: twilio_sms.messaging_service_sid, messaging_service_sid: twilio_sms.messaging_service_sid,
to: contact_error.phone_number, to: contact_error.phone_number,
status_callback: 'http://localhost:3000/twilio/delivery_status' status_callback: 'http://localhost:3000/twilio/delivery_status'
).and_raise(error) ).and_raise(error)
expect(twilio_messages).to receive(:create!).with( expect(twilio_messages).to receive(:create).with(
body: campaign.message, body: campaign.message,
messaging_service_sid: twilio_sms.messaging_service_sid, messaging_service_sid: twilio_sms.messaging_service_sid,
to: contact_success.phone_number, to: contact_success.phone_number,

View File

@ -53,7 +53,7 @@ describe Twilio::SendOnTwilioService do
context 'with reply' do context 'with reply' do
it 'if message is sent from chatwoot and is outgoing' 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') allow(message_record_double).to receive(:sid).and_return('1234')
outgoing_message = create( outgoing_message = create(
@ -67,7 +67,7 @@ describe Twilio::SendOnTwilioService do
it 'if outgoing message has attachment and is for whatsapp' do it 'if outgoing message has attachment and is for whatsapp' do
# check for message attachment url # 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') allow(message_record_double).to receive(:sid).and_return('1234')
message = build( message = build(
@ -78,12 +78,12 @@ describe Twilio::SendOnTwilioService do
message.save! message.save!
described_class.new(message: message).perform described_class.new(message: message).perform
expect(messages_double).to have_received(:create!) expect(messages_double).to have_received(:create)
end end
it 'if outgoing message has attachment and is for sms' do it 'if outgoing message has attachment and is for sms' do
# check for message attachment url # 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') allow(message_record_double).to receive(:sid).and_return('1234')
message = build( message = build(
@ -94,11 +94,11 @@ describe Twilio::SendOnTwilioService do
message.save! message.save!
described_class.new(message: message).perform described_class.new(message: message).perform
expect(messages_double).to have_received(:create!) expect(messages_double).to have_received(:create)
end end
it 'if message is sent from chatwoot fails' do 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( outgoing_message = create(
:message, message_type: 'outgoing', inbox: twilio_inbox, account: account, conversation: conversation :message, message_type: 'outgoing', inbox: twilio_inbox, account: account, conversation: conversation