fix: compact message content in send_message method and add test for empty caption
This commit is contained in:
parent
34becba25f
commit
fd8e099f4d
@ -107,7 +107,7 @@ class Whatsapp::Providers::WhatsappBaileysService < Whatsapp::Providers::BaseSer
|
|||||||
content[:video] = buffer
|
content[:video] = buffer
|
||||||
end
|
end
|
||||||
|
|
||||||
content
|
content.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_text_message
|
def send_text_message
|
||||||
|
|||||||
@ -126,6 +126,27 @@ describe Whatsapp::Providers::WhatsappBaileysService do
|
|||||||
expect(result).to eq('msg_123')
|
expect(result).to eq('msg_123')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'omits caption if message content is empty' do
|
||||||
|
message.update!(content: nil)
|
||||||
|
stub_request(:post, "#{whatsapp_channel.provider_config['provider_url']}/connections/#{whatsapp_channel.phone_number}/send-message")
|
||||||
|
.with(
|
||||||
|
headers: stub_headers(whatsapp_channel),
|
||||||
|
body: {
|
||||||
|
recipient: test_send_phone_number,
|
||||||
|
messageContent: { fileName: 'image.png', image: base64_image }
|
||||||
|
}.to_json
|
||||||
|
)
|
||||||
|
.to_return(
|
||||||
|
status: 200,
|
||||||
|
headers: { 'Content-Type' => 'application/json' },
|
||||||
|
body: { 'data' => { 'key' => { 'id' => 'msg_123' } } }.to_json
|
||||||
|
)
|
||||||
|
|
||||||
|
result = service.send_message(test_send_phone_number, message)
|
||||||
|
|
||||||
|
expect(result).to eq('msg_123')
|
||||||
|
end
|
||||||
|
|
||||||
context 'when request is unsuccessful' do
|
context 'when request is unsuccessful' do
|
||||||
it 'raises MessageNotSentError' do
|
it 'raises MessageNotSentError' do
|
||||||
stub_request(:post, "#{whatsapp_channel.provider_config['provider_url']}/connections/#{whatsapp_channel.phone_number}/send-message")
|
stub_request(:post, "#{whatsapp_channel.provider_config['provider_url']}/connections/#{whatsapp_channel.phone_number}/send-message")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user