test: cover lid batch and jid normalization
This commit is contained in:
@@ -44,4 +44,42 @@ describe('LIDMappingStore', () => {
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getLIDsForPNs', () => {
|
||||
it('should resolve multiple PNs in a single batch', async () => {
|
||||
const pnOne = '11111@s.whatsapp.net'
|
||||
const pnTwo = '22222:5@s.whatsapp.net'
|
||||
|
||||
// @ts-ignore
|
||||
mockKeys.get.mockResolvedValue({ '11111': 'aaaaa', '22222': 'bbbbb' } as SignalDataTypeMap['lid-mapping'])
|
||||
|
||||
const result = await lidMappingStore.getLIDsForPNs([pnOne, pnTwo])
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.arrayContaining([
|
||||
{ pn: pnOne, lid: 'aaaaa@lid' },
|
||||
{ pn: pnTwo, lid: 'bbbbb:5@lid' }
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getPNsForLIDs', () => {
|
||||
it('should resolve multiple LIDs in a single batch', async () => {
|
||||
const lidOne = '33333@lid'
|
||||
const lidTwo = '44444:99@hosted.lid'
|
||||
|
||||
// @ts-ignore
|
||||
mockKeys.get.mockResolvedValue({ '33333_reverse': '77777', '44444_reverse': '88888' } as SignalDataTypeMap['lid-mapping'])
|
||||
|
||||
const result = await lidMappingStore.getPNsForLIDs([lidOne, lidTwo])
|
||||
|
||||
expect(result).toEqual(
|
||||
expect.arrayContaining([
|
||||
{ lid: lidOne, pn: '77777@s.whatsapp.net' },
|
||||
{ lid: lidTwo, pn: '88888:99@hosted' }
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { WAMessage } from '../../Types'
|
||||
import { cleanMessage } from '../../Utils/process-message'
|
||||
import type { SignalRepositoryWithLIDStore } from '../../Types'
|
||||
import { cleanMessage, normalizeMessageJids } from '../../Utils/process-message'
|
||||
|
||||
const createBaseMessage = (key: Partial<WAMessage['key']>, message?: Partial<WAMessage['message']>): WAMessage => {
|
||||
return {
|
||||
@@ -136,3 +137,51 @@ describe('cleanMessage', () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('normalizeMessageJids', () => {
|
||||
const signalRepository = {
|
||||
lidMapping: {
|
||||
getPNForLID: jest.fn()
|
||||
}
|
||||
} as unknown as SignalRepositoryWithLIDStore
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should resolve remoteJid LID to PN when mapping exists', async () => {
|
||||
const message = createBaseMessage({
|
||||
remoteJid: '123456789@lid'
|
||||
})
|
||||
|
||||
signalRepository.lidMapping.getPNForLID = jest.fn().mockResolvedValue('5511999999999@s.whatsapp.net')
|
||||
|
||||
await normalizeMessageJids(message, signalRepository)
|
||||
|
||||
expect(message.key.remoteJid).toBe('5511999999999@s.whatsapp.net')
|
||||
})
|
||||
|
||||
it('should keep LID when no PN mapping exists', async () => {
|
||||
const message = createBaseMessage({
|
||||
remoteJid: '123456789@lid'
|
||||
})
|
||||
|
||||
signalRepository.lidMapping.getPNForLID = jest.fn().mockResolvedValue(null)
|
||||
|
||||
await normalizeMessageJids(message, signalRepository)
|
||||
|
||||
expect(message.key.remoteJid).toBe('123456789@lid')
|
||||
})
|
||||
|
||||
it('should resolve participant LID to PN when mapping exists', async () => {
|
||||
const message = createBaseMessage({
|
||||
participant: '999999999@lid'
|
||||
})
|
||||
|
||||
signalRepository.lidMapping.getPNForLID = jest.fn().mockResolvedValue('5511888888888@s.whatsapp.net')
|
||||
|
||||
await normalizeMessageJids(message, signalRepository)
|
||||
|
||||
expect(message.key.participant).toBe('5511888888888@s.whatsapp.net')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user