iachat/spec/services/wuzapi/client_interactive_spec.rb
Rodribm10 7a203ccb6d feat(wuzapi): add send_buttons, send_list, send_url_button methods
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 01:28:00 -03:00

68 lines
2.4 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Wuzapi::Client do
let(:base_url) { 'https://wuzapi.test' }
let(:client) { described_class.new(base_url) }
let(:user_token) { 'tok' }
let(:phone) { '5561999999999' }
describe '#send_buttons' do
it 'POSTs to /chat/sendbuttons with buttons payload' do
stub = stub_request(:post, "#{base_url}/chat/sendbuttons")
.with(
headers: { 'Token' => user_token },
body: hash_including(
Phone: phone,
Text: 'Curtiu?',
Buttons: [
{ DisplayText: 'Sim' },
{ DisplayText: 'Não' }
]
)
)
.to_return(status: 200, body: { Id: 'msg-1' }.to_json, headers: { 'Content-Type' => 'application/json' })
response = client.send_buttons(
user_token, phone, 'Curtiu?',
[{ text: 'Sim' }, { text: 'Não' }]
)
expect(response).to be_a(Hash)
expect(stub).to have_been_requested
end
end
describe '#send_list' do
it 'POSTs to /chat/sendlist with sections' do
stub = stub_request(:post, "#{base_url}/chat/sendlist")
.with(headers: { 'Token' => user_token })
.to_return(status: 200, body: { Id: 'msg-2' }.to_json, headers: { 'Content-Type' => 'application/json' })
response = client.send_list(
user_token, phone,
text: 'Cardápio',
button_text: 'Ver opções',
sections: [{ title: 'Bebidas', rows: [{ title: 'Água', row_id: 'agua' }] }]
)
expect(response).to be_a(Hash)
expect(stub).to have_been_requested
end
end
describe '#send_url_button' do
it 'POSTs to /chat/sendbuttons with URL button' do
stub = stub_request(:post, "#{base_url}/chat/sendbuttons")
.with(body: hash_including('Buttons' => array_including(hash_including('Type' => 'url'))))
.to_return(status: 200, body: { Id: 'msg-3' }.to_json, headers: { 'Content-Type' => 'application/json' })
response = client.send_url_button(user_token, phone,
text: 'Avalie no Google',
button_text: 'Avaliar',
url: 'https://g.page/r/XYZ')
expect(response).to be_a(Hash)
expect(stub).to have_been_requested
end
end
end