fix: Twilio multiple attachment fix (#11452)
This commit is contained in:
committed by
GitHub
parent
bce1f58e86
commit
e9cda40b71
@@ -173,7 +173,7 @@ describe Twilio::IncomingMessageService do
|
||||
context 'when a message with an attachment is received' do
|
||||
before do
|
||||
stub_request(:get, 'https://chatwoot-assets.local/sample.png')
|
||||
.to_return(status: 200, body: 'image data', headers: {})
|
||||
.to_return(status: 200, body: 'image data', headers: { 'Content-Type' => 'image/png' })
|
||||
end
|
||||
|
||||
let(:params_with_attachment) do
|
||||
@@ -203,7 +203,7 @@ describe Twilio::IncomingMessageService do
|
||||
.to_raise(Down::Error.new('Download error'))
|
||||
|
||||
stub_request(:get, 'https://chatwoot-assets.local/sample.png')
|
||||
.to_return(status: 200, body: 'image data', headers: {})
|
||||
.to_return(status: 200, body: 'image data', headers: { 'Content-Type' => 'image/png' })
|
||||
end
|
||||
|
||||
let(:params_with_attachment_error) do
|
||||
@@ -229,5 +229,36 @@ describe Twilio::IncomingMessageService do
|
||||
expect(conversation.reload.messages.last.attachments.first.file_type).to eq('image')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a message with multiple attachments is received' do
|
||||
before do
|
||||
stub_request(:get, 'https://chatwoot-assets.local/sample.png')
|
||||
.to_return(status: 200, body: 'image data 1', headers: { 'Content-Type' => 'image/png' })
|
||||
stub_request(:get, 'https://chatwoot-assets.local/sample.jpg')
|
||||
.to_return(status: 200, body: 'image data 2', headers: { 'Content-Type' => 'image/jpeg' })
|
||||
end
|
||||
|
||||
let(:params_with_multiple_attachments) do
|
||||
{
|
||||
SmsSid: 'SMxx',
|
||||
From: '+12345',
|
||||
AccountSid: 'ACxxx',
|
||||
MessagingServiceSid: twilio_channel.messaging_service_sid,
|
||||
Body: 'testing multiple media',
|
||||
NumMedia: '2',
|
||||
MediaContentType0: 'image/png',
|
||||
MediaUrl0: 'https://chatwoot-assets.local/sample.png',
|
||||
MediaContentType1: 'image/jpeg',
|
||||
MediaUrl1: 'https://chatwoot-assets.local/sample.jpg'
|
||||
}
|
||||
end
|
||||
|
||||
it 'creates a new message with multiple media attachments in existing conversation' do
|
||||
described_class.new(params: params_with_multiple_attachments).perform
|
||||
expect(conversation.reload.messages.last.content).to eq('testing multiple media')
|
||||
expect(conversation.reload.messages.last.attachments.count).to eq(2)
|
||||
expect(conversation.reload.messages.last.attachments.map(&:file_type)).to contain_exactly('image', 'image')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user