From dc9884e27e6f091f52393e96e7df05c11a98722a Mon Sep 17 00:00:00 2001 From: Dorian Date: Fri, 13 Mar 2026 09:33:50 +0000 Subject: [PATCH] test: verify wallet disconnect wipes connection data from DB Add test confirming disconnect-wallet deletes walletConnections rows and sets hasWallet=false on the bot record. Co-Authored-By: Claude Opus 4.6 --- server/src/routes/payments.test.ts | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) 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', {