From 5440ab3f1380b9bbda7d5cb510f33e38aa84915d Mon Sep 17 00:00:00 2001 From: gabrieljablonski Date: Tue, 29 Apr 2025 21:43:14 -0300 Subject: [PATCH] test: fix broken spec file --- .../whatsapp_baileys_service_spec.rb | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/spec/services/whatsapp/providers/whatsapp_baileys_service_spec.rb b/spec/services/whatsapp/providers/whatsapp_baileys_service_spec.rb index e42c03d3c..ec0d1e01f 100644 --- a/spec/services/whatsapp/providers/whatsapp_baileys_service_spec.rb +++ b/spec/services/whatsapp/providers/whatsapp_baileys_service_spec.rb @@ -92,39 +92,6 @@ describe Whatsapp::Providers::WhatsappBaileysService do end describe '#send_message' do - context 'when message is a reaction' do - let(:inbox) { whatsapp_channel.inbox } - let(:contact) { create(:contact, account: inbox.account, name: 'John Doe', phone_number: "+#{test_send_phone_number}") } - let(:contact_inbox) { create(:contact_inbox, inbox: inbox, contact: contact, source_id: test_send_phone_number) } - let(:conversation) { create(:conversation, inbox: inbox, contact_inbox: contact_inbox) } - let!(:message) { create(:message, inbox: inbox, conversation: conversation, sender: contact, source_id: 'msg_123') } - let(:reaction) do - create(:message, inbox: inbox, conversation: conversation, sender: contact, content: '👍', - content_attributes: { is_reaction: true, in_reply_to: message.id }) - end - - it 'sends the reaction message' do - stub_request(:post, "#{whatsapp_channel.provider_config['provider_url']}/connections/#{whatsapp_channel.phone_number}/send-message") - .with( - headers: stub_headers(whatsapp_channel), - body: { - jid: test_send_jid, - messageContent: { react: { key: { id: message.source_id, - remoteJid: test_send_jid, - fromMe: true }, - text: '👍' } } - }.to_json - ) - .to_return( - status: 200, - headers: { 'Content-Type' => 'application/json' }, - body: { 'data' => { 'key' => { 'id' => 'reaction_123' } } }.to_json - ) - - result = service.send_message(test_send_phone_number, reaction) - - expect(result).to eq('reaction_123') - context 'when message does not have content nor attachments' do it 'updates the message with content attribute is_unsupported' do message.update!(content: nil) @@ -235,6 +202,41 @@ describe Whatsapp::Providers::WhatsappBaileysService do end.to raise_error(Whatsapp::Providers::WhatsappBaileysService::MessageNotSentError) end end + + context 'when message is a reaction' do + let(:inbox) { whatsapp_channel.inbox } + let(:contact) { create(:contact, account: inbox.account, name: 'John Doe', phone_number: "+#{test_send_phone_number}") } + let(:contact_inbox) { create(:contact_inbox, inbox: inbox, contact: contact, source_id: test_send_phone_number) } + let(:conversation) { create(:conversation, inbox: inbox, contact_inbox: contact_inbox) } + let!(:message) { create(:message, inbox: inbox, conversation: conversation, sender: contact, source_id: 'msg_123') } + let(:reaction) do + create(:message, inbox: inbox, conversation: conversation, sender: contact, content: '👍', + content_attributes: { is_reaction: true, in_reply_to: message.id }) + end + + it 'sends the reaction message' do + stub_request(:post, "#{whatsapp_channel.provider_config['provider_url']}/connections/#{whatsapp_channel.phone_number}/send-message") + .with( + headers: stub_headers(whatsapp_channel), + body: { + jid: test_send_jid, + messageContent: { react: { key: { id: message.source_id, + remoteJid: test_send_jid, + fromMe: true }, + text: '👍' } } + }.to_json + ) + .to_return( + status: 200, + headers: { 'Content-Type' => 'application/json' }, + body: { 'data' => { 'key' => { 'id' => 'reaction_123' } } }.to_json + ) + + result = service.send_message(test_send_phone_number, reaction) + + expect(result).to eq('reaction_123') + end + end end describe '#api_headers' do