diff --git a/server/src/routes/payments.test.ts b/server/src/routes/payments.test.ts index 687f3da..3d985f6 100644 --- a/server/src/routes/payments.test.ts +++ b/server/src/routes/payments.test.ts @@ -170,6 +170,38 @@ describe('payments routes', () => { expect(res.status).toBe(400) }) + it('disconnect-wallet wipes connection data and sets hasWallet=false', async () => { + const mockDb = db as any + // Mock: find bot by pubkey + mockDb.select.mockReturnValueOnce({ + from: () => ({ + where: () => ({ + limit: () => Promise.resolve([{ id: 'bot_wallet_1' }]), + }), + }), + }) + + const app = makeApp() + const res = await app.request('/api/payments/disconnect-wallet', { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ pubkey: 'a'.repeat(64) }), + }) + expect(res.status).toBe(200) + const json = await res.json() as { success: boolean } + expect(json.success).toBe(true) + + // Verify db.delete was called (wallet connections wiped) + expect(mockDb.delete).toHaveBeenCalled() + // Verify db.update was called to set hasWallet: false + expect(mockDb.update).toHaveBeenCalled() + const updateArgs = mockDb.update.mock.results + // The set() call should include hasWallet: false + const setCalls = mockDb.update.mock.results.map((r: any) => r.value.set.mock.calls).flat() + const hasWalletUpdate = setCalls.find((args: any[]) => args[0]?.hasWallet === false) + expect(hasWalletUpdate).toBeDefined() + }) + it('zap returns 400 for invalid amountSats', async () => { const app = makeApp() const res = await app.request('/api/payments/zap', {