aboutsummaryrefslogtreecommitdiffstats
path: root/test/compat.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/compat.test.js')
-rw-r--r--test/compat.test.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/compat.test.js b/test/compat.test.js
new file mode 100644
index 0000000..d5a3d65
--- /dev/null
+++ b/test/compat.test.js
@@ -0,0 +1,25 @@
+import assert from 'node:assert/strict';
+import { createRequire } from 'node:module';
+import test from 'node:test';
+import { patchStructures } from '../src/compat.js';
+import * as ser from '../src/serialize.js';
+
+const require = createRequire(import.meta.url);
+
+test('MsgKey with $1 (WA Web 2.3000.104x) recovers _serialized in Message and Reaction', () => {
+ patchStructures();
+ patchStructures(); // idempotent
+ const S = require('whatsapp-web.js/src/structures/index.js');
+ const key = { fromMe: false, remote: '5491122334455@c.us', id: '3EB0AAA1', self: 'in', $1: 'false_5491122334455@c.us_3EB0AAA1' };
+
+ const m = new S.Message(null, { id: { ...key }, body: 'hola', t: 1789500000, type: 'chat', from: key.remote, to: 'yo@c.us' });
+ assert.equal(m.id._serialized, key.$1);
+ assert.equal(ser.message(m).id, key.$1);
+
+ const r = new S.Reaction(null, { msgKey: { ...key, $1: 'x' }, parentMsgKey: { ...key }, reactionText: '๐Ÿ‘', timestamp: 1 });
+ assert.equal(r.msgId._serialized, key.$1);
+
+ // IDs that already have _serialized are left alone
+ const old = new S.Message(null, { id: { ...key, _serialized: 'old' }, body: '', t: 1, type: 'chat' });
+ assert.equal(old.id._serialized, 'old');
+});