fix(WAProto): Handle string values in long fields during JSON serialization (#1991)
* feat: add patch-tojson functionality for improved proto serialization * Remove patch-tojson functionality and its import from the main index file to streamline the codebase. * refactor: simplify longToString and longToNumber functions for better readability and performance
This commit is contained in:
committed by
GitHub
parent
432c26a07c
commit
9611a1a982
@@ -0,0 +1,31 @@
|
||||
import '../index.js'
|
||||
import { proto } from '../../WAProto/index.js'
|
||||
|
||||
describe('proto serialization', () => {
|
||||
it('handles string values in long fields gracefully', () => {
|
||||
const message = proto.WebMessageInfo.fromObject({
|
||||
key: {
|
||||
remoteJid: '123@s.whatsapp.net',
|
||||
id: 'ABC123',
|
||||
fromMe: false
|
||||
},
|
||||
messageTimestamp: 1,
|
||||
message: {
|
||||
imageMessage: {
|
||||
fileLength: 42
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const imageMessage = message.message?.imageMessage
|
||||
if (!imageMessage) {
|
||||
throw new Error('imageMessage missing in test setup')
|
||||
}
|
||||
|
||||
;(imageMessage as unknown as { fileLength: unknown }).fileLength = '1234567890123456789'
|
||||
|
||||
expect(() => JSON.stringify(message)).not.toThrow()
|
||||
const json = message.toJSON()
|
||||
expect(json.message?.imageMessage?.fileLength).toBe('1234567890123456789')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user