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:
João Lucas de Oliveira Lopes
2026-01-14 03:33:45 -03:00
committed by GitHub
parent 432c26a07c
commit 9611a1a982
3 changed files with 298 additions and 178 deletions
+31
View File
@@ -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')
})
})