Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(engine): check extractMessageContent in the image smoke test

Yudhi Armyndharis093e4ea73ae6
diff --git a/scripts/smoke-test-engine-libs.sh b/scripts/smoke-test-engine-libs.sh
index bd9db5f72..4ec97d741 100755
--- a/scripts/smoke-test-engine-libs.sh
+++ b/scripts/smoke-test-engine-libs.sh
@@ -27,8 +27,9 @@ docker run --rm "$@" -e ENGINE_TYPE=baileys "$IMAGE" node -e "
import('@whiskeysockets/baileys')
.then(m => {
const used = ['default', 'initAuthCreds', 'makeCacheableSignalKeyStore', 'fetchLatestBaileysVersion',
- 'fetchLatestWaWebVersion', 'normalizeMessageContent', 'getContentType', 'downloadMediaMessage', 'BufferJSON',
- 'proto', 'DisconnectReason', 'S_WHATSAPP_NET', 'ALL_WA_PATCH_NAMES', 'CALL_VIDEO_PREFIX', 'CALL_AUDIO_PREFIX'];
+ 'fetchLatestWaWebVersion', 'normalizeMessageContent', 'extractMessageContent', 'getContentType',
+ 'downloadMediaMessage', 'BufferJSON', 'proto', 'DisconnectReason', 'S_WHATSAPP_NET', 'ALL_WA_PATCH_NAMES',
+ 'CALL_VIDEO_PREFIX', 'CALL_AUDIO_PREFIX'];
const missing = used.filter(name => m[name] === undefined);
if (missing.length > 0 || typeof m.default !== 'function') throw new Error('missing exports: ' + missing.join(', '));
console.log('PASS: Baileys loaded with every export the adapter uses');
diff --git a/src/engine/adapters/baileys-auth-store.spec.ts b/src/engine/adapters/baileys-auth-store.spec.ts
index 135f3e7fb..eee2d4b6f 100644
--- a/src/engine/adapters/baileys-auth-store.spec.ts
+++ b/src/engine/adapters/baileys-auth-store.spec.ts
@@ -185,25 +185,24 @@ describe('engine library smoke export list', () => {
const script = fs.readFileSync(path.join(root, 'scripts', 'smoke-test-engine-libs.sh'), 'utf8');
const used = [.../const used = \[([^\]]*)\]/.exec(script)![1].matchAll(/'([^']+)'/g)].map(m => m[1]);
- it('covers every export the auth store takes from the module', () => {
- const source = fs.readFileSync(path.join(__dirname, 'baileys-auth-store.ts'), 'utf8');
- const picked = /Pick<typeof BaileysLib, ([^>]+)>/
- .exec(source)![1]
- .match(/'[^']+'/g)!
- .map(n => n.slice(1, -1));
- expect(picked.length).toBeGreaterThan(0);
+ const dir = path.join(root, 'src', 'engine');
+ const code = fs
+ .readdirSync(dir, { recursive: true, encoding: 'utf8' })
+ .filter(f => f.endsWith('.ts') && !f.endsWith('.spec.ts'))
+ .map(f => fs.readFileSync(path.join(dir, f), 'utf8'))
+ .join('\n')
+ .replace(/\/\*[\s\S]*?\*\//g, '')
+ .replace(/^\s*\/\/.*$/gm, '');
+
+ it('covers every export the engine code picks from the module', () => {
+ const picked = [...code.matchAll(/Pick<typeof BaileysLib, ([^>]+)>/g)].flatMap(m =>
+ m[1].match(/'[^']+'/g)!.map(n => n.slice(1, -1)),
+ );
+ expect(picked).toEqual(expect.arrayContaining(['initAuthCreds', 'extractMessageContent']));
expect(used).toEqual(expect.arrayContaining(picked));
});
it('lists only exports the engine code still uses', () => {
- const dir = path.join(root, 'src', 'engine');
- const code = fs
- .readdirSync(dir, { recursive: true, encoding: 'utf8' })
- .filter(f => f.endsWith('.ts') && !f.endsWith('.spec.ts'))
- .map(f => fs.readFileSync(path.join(dir, f), 'utf8'))
- .join('\n')
- .replace(/\/\*[\s\S]*?\*\//g, '')
- .replace(/^\s*\/\/.*$/gm, '');
expect(used.filter(name => name !== 'default' && !new RegExp(`\\b${name}\\b`).test(code))).toEqual([]);
});
});