feat: thread QR/status callbacks through session pool; persist to DB in main

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 11:08:51 +05:30
parent 18edce7552
commit 02dad1347c
3 changed files with 45 additions and 0 deletions
@@ -89,4 +89,21 @@ describe('WhatsAppSessionPool', () => {
await capturedOnMessage(fakeMsg);
expect(onMessage).toHaveBeenCalledWith(fakeMsg, 'acc_1');
});
it('add() injects accountId into onQr callback', async () => {
const onQr = jest.fn();
const { createWhatsAppSession } = require('./session');
let capturedOnQr: any;
(createWhatsAppSession as jest.Mock).mockImplementationOnce(
(_id: string, _path: string, _onMsg: any, _onReaction: any, _onGroups: any, _onReconnect: any, qrCb: any) => {
capturedOnQr = qrCb;
return Promise.resolve({ sendMessage: jest.fn(), logout: jest.fn(), end: jest.fn() });
},
);
await pool.add('acc_1', './sessions/1', jest.fn(), jest.fn(), jest.fn(), onQr);
await capturedOnQr('test-qr');
expect(onQr).toHaveBeenCalledWith('test-qr', 'acc_1');
});
});