fix: resolve TypeScript errors in merged code
- Add null check for decoded in getLIDsForPNs loop - Fix jest mock typing in process-message.test.ts
This commit is contained in:
@@ -522,7 +522,7 @@ export class LIDMappingStore {
|
||||
for (const [pnUser, items] of pendingByPnUser.entries()) {
|
||||
const lidUser = this.mappingCache.get(`pn:${pnUser}`)
|
||||
for (const { pn, decoded } of items) {
|
||||
if (lidUser) {
|
||||
if (lidUser && decoded) {
|
||||
const lidUserString = lidUser.toString()
|
||||
if (!lidUserString) {
|
||||
this.logger.warn({ pn, lidUser }, 'Invalid or empty LID user')
|
||||
@@ -548,6 +548,8 @@ export class LIDMappingStore {
|
||||
failedPns.add(pn)
|
||||
}
|
||||
|
||||
if (!decoded) continue
|
||||
|
||||
// Need to fetch from USync
|
||||
if (this.config.debugLogging) {
|
||||
this.logger.trace({ pnUser }, 'No LID mapping found, queuing for USync')
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { jest } from '@jest/globals'
|
||||
import type { WAMessage } from '../../Types'
|
||||
import type { SignalRepositoryWithLIDStore } from '../../Types'
|
||||
import { cleanMessage, normalizeMessageJids } from '../../Utils/process-message'
|
||||
@@ -139,14 +140,17 @@ describe('cleanMessage', () => {
|
||||
})
|
||||
|
||||
describe('normalizeMessageJids', () => {
|
||||
const signalRepository = {
|
||||
lidMapping: {
|
||||
getPNForLID: jest.fn()
|
||||
}
|
||||
} as unknown as SignalRepositoryWithLIDStore
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let mockGetPNForLID: any
|
||||
let signalRepository: SignalRepositoryWithLIDStore
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
mockGetPNForLID = jest.fn()
|
||||
signalRepository = {
|
||||
lidMapping: {
|
||||
getPNForLID: mockGetPNForLID
|
||||
}
|
||||
} as unknown as SignalRepositoryWithLIDStore
|
||||
})
|
||||
|
||||
it('should resolve remoteJid LID to PN when mapping exists', async () => {
|
||||
@@ -154,7 +158,7 @@ describe('normalizeMessageJids', () => {
|
||||
remoteJid: '123456789@lid'
|
||||
})
|
||||
|
||||
signalRepository.lidMapping.getPNForLID = jest.fn().mockResolvedValue('5511999999999@s.whatsapp.net')
|
||||
mockGetPNForLID.mockResolvedValue('5511999999999@s.whatsapp.net')
|
||||
|
||||
await normalizeMessageJids(message, signalRepository)
|
||||
|
||||
@@ -166,7 +170,7 @@ describe('normalizeMessageJids', () => {
|
||||
remoteJid: '123456789@lid'
|
||||
})
|
||||
|
||||
signalRepository.lidMapping.getPNForLID = jest.fn().mockResolvedValue(null)
|
||||
mockGetPNForLID.mockResolvedValue(null)
|
||||
|
||||
await normalizeMessageJids(message, signalRepository)
|
||||
|
||||
@@ -178,7 +182,7 @@ describe('normalizeMessageJids', () => {
|
||||
participant: '999999999@lid'
|
||||
})
|
||||
|
||||
signalRepository.lidMapping.getPNForLID = jest.fn().mockResolvedValue('5511888888888@s.whatsapp.net')
|
||||
mockGetPNForLID.mockResolvedValue('5511888888888@s.whatsapp.net')
|
||||
|
||||
await normalizeMessageJids(message, signalRepository)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user