fix: use type-only Baileys import and raw status code to fix Jest ESM issue
Replaces DisconnectReason enum import with type-only WASocket import and uses 401 directly instead of DisconnectReason.loggedOut. Baileys is an ES module that cannot be executed in Jest's CommonJS mode, so removing the value import (keeping only type imports) prevents ts-jest from trying to execute the module. Also updated session-pool.test.ts to verify end() is called with the expected Boom error object instead of undefined. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,11 +16,13 @@
|
||||
"@tower/types": "workspace:*",
|
||||
"@whiskeysockets/baileys": "7.0.0-rc13",
|
||||
"bullmq": "^5.0.0",
|
||||
"ioredis": "^5.0.0"
|
||||
"ioredis": "^5.0.0",
|
||||
"qrcode-terminal": "^0.12.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.0.0",
|
||||
"@types/node": "^22.0.0",
|
||||
"@types/qrcode-terminal": "^0.12.2",
|
||||
"dotenv": "^17.4.2",
|
||||
"jest": "^29.0.0",
|
||||
"prisma": "^6.0.0",
|
||||
|
||||
@@ -66,8 +66,8 @@ describe('WhatsAppSessionPool', () => {
|
||||
|
||||
await pool.closeAll();
|
||||
|
||||
expect(sock1.end).toHaveBeenCalledWith(undefined);
|
||||
expect(sock2.end).toHaveBeenCalledWith(undefined);
|
||||
expect(sock1.end).toHaveBeenCalledWith(expect.objectContaining({ message: 'Shutdown' }));
|
||||
expect(sock2.end).toHaveBeenCalledWith(expect.objectContaining({ message: 'Shutdown' }));
|
||||
expect(pool.getAll().size).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { WASocket, DisconnectReason } from '@whiskeysockets/baileys';
|
||||
import type { WASocket } from '@whiskeysockets/baileys';
|
||||
import { Boom } from '@hapi/boom';
|
||||
import { NormalizedMessage, NormalizedReaction } from '@tower/types';
|
||||
import { createWhatsAppSession } from './session';
|
||||
@@ -67,7 +67,7 @@ export class WhatsAppSessionPool {
|
||||
logger.info({ count: this.sessions.size }, 'Closing all WhatsApp sessions');
|
||||
for (const [accountId, sock] of this.sessions) {
|
||||
try {
|
||||
sock.end(new Boom('Shutdown', { statusCode: DisconnectReason.loggedOut }));
|
||||
sock.end(new Boom('Shutdown', { statusCode: 401 }));
|
||||
logger.info({ accountId }, 'Session closed');
|
||||
} catch (err) {
|
||||
logger.error({ accountId, err }, 'Error closing session');
|
||||
|
||||
Reference in New Issue
Block a user