iachat/spec/services/whatsapp/incoming_message_zapi_service_spec.rb
Gabriel Jablonski c234023a4a
feat(zapi): handle contact messages and ignore notifications (#124)
* chore: skip notification messages

* feat: contact card messages

* fix: notification message handling

* chore: reduce code duplication

* fix: improve contact name handling in attachment

* chore(zapi): promo banner with affiliate link (#126)

* chore(zapi): promo banner with affiliate link

* chore: remove useless comment

* chore(zapi): add note about hardcoded affiliate link

* feat: provider.event_received for raw provider events (#127)

* chore(zapi): promo banner with affiliate link

* chore: remove useless comment

* feat: provider.event_received for raw provider events

* feat: add provider_event_received handling in webhook listener

* feat(baileys): use senderLid as contact identifier (#128)

* chore(zapi): promo banner with affiliate link

* chore: remove useless comment

* feat: provider.event_received for raw provider events

* feat(baileys): use senderLid as contact identifier

* fix: simplify webhook_data method by removing unnecessary fields
2025-10-26 10:48:06 -03:00

55 lines
1.5 KiB
Ruby

require 'rails_helper'
describe Whatsapp::IncomingMessageZapiService do
describe '#perform' do
let!(:whatsapp_channel) do
create(:channel_whatsapp, provider: 'zapi', validate_provider_config: false, received_messages: false)
end
let(:inbox) { whatsapp_channel.inbox }
context 'when type is blank' do
it 'does nothing' do
params = { type: '' }
expect do
described_class.new(inbox: inbox, params: params).perform
end.not_to change(Message, :count)
end
it 'does nothing when type is nil' do
params = {}
expect do
described_class.new(inbox: inbox, params: params).perform
end.not_to change(Message, :count)
end
end
context 'when event type is unsupported' do
it 'logs a warning message' do
params = { type: 'unsupported_event' }
allow(Rails.logger).to receive(:warn)
described_class.new(inbox: inbox, params: params).perform
expect(Rails.logger).to have_received(:warn).with(/Z-API unsupported event/)
end
end
it 'dispatches the provider.event_received event' do
params = { type: 'some_event' }
allow(Rails.configuration.dispatcher).to receive(:dispatch)
described_class.new(inbox: inbox, params: params).perform
expect(Rails.configuration.dispatcher).to have_received(:dispatch).with(
Events::Types::PROVIDER_EVENT_RECEIVED,
kind_of(Time),
inbox: inbox,
event: params[:type],
payload: params
)
end
end
end