test: fix broken spec file
This commit is contained in:
parent
8e913236e5
commit
5440ab3f13
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user