iachat/spec/services/whatsapp/incoming_message_zapi_service_spec.rb
Gabriel Jablonski 8ff5834ee8
fix(zapi): support for LID-only conversations (#123)
* fix: ignore action events

* feat(zapi): allow updating instance ID

* feat: handle `chatLid` field

* test: break down handler specs into separate files

* feat: update send_message method to use recipient_id logic for zapi provider

* fix: use identifier instead of source_id for zapi

* test: fix specs

* feat: prioritize senderName over chatName for contact naming in received callback
2025-10-23 10:12:38 -03:00

40 lines
1.1 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
end
end