feat: whatsapp duplicate message (#7004)
This commit is contained in:
@@ -308,5 +308,36 @@ describe Whatsapp::IncomingMessageService do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when message processing is in progress' do
|
||||
it 'ignores the current message creation request' do
|
||||
params = { 'contacts' => [{ 'profile' => { 'name' => 'Kedar' }, 'wa_id' => '919746334593' }],
|
||||
'messages' => [{ 'from' => '919446284490',
|
||||
'id' => 'wamid.SDFADSf23sfasdafasdfa',
|
||||
'timestamp' => '1675823265',
|
||||
'type' => 'contacts',
|
||||
'contacts' => [
|
||||
{
|
||||
'name' => { 'formatted_name' => 'Apple Inc.' },
|
||||
'phones' => [{ 'phone' => '+911800', 'type' => 'MAIN' }]
|
||||
},
|
||||
{ 'name' => { 'first_name' => 'Chatwoot', 'formatted_name' => 'Chatwoot' },
|
||||
'phones' => [{ 'phone' => '+1 (415) 341-8386' }] }
|
||||
] }] }.with_indifferent_access
|
||||
|
||||
expect(Message.find_by(source_id: 'wamid.SDFADSf23sfasdafasdfa')).not_to be_present
|
||||
key = format(Redis::RedisKeys::MESSAGE_SOURCE_KEY, id: 'wamid.SDFADSf23sfasdafasdfa')
|
||||
|
||||
::Redis::Alfred.setex(key, true)
|
||||
expect(::Redis::Alfred.get(key)).to be_truthy
|
||||
|
||||
described_class.new(inbox: whatsapp_channel.inbox, params: params).perform
|
||||
expect(whatsapp_channel.inbox.messages.count).to eq(0)
|
||||
expect(Message.find_by(source_id: 'wamid.SDFADSf23sfasdafasdfa')).not_to be_present
|
||||
|
||||
expect(::Redis::Alfred.get(key)).to be_truthy
|
||||
::Redis::Alfred.delete(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user