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 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-13 09:33:50 +00:00
co-authored by Claude Opus 4.6
parent b1e86843a7
commit dc9884e27e
+32
View File
@@ -170,6 +170,38 @@ describe('payments routes', () => {
expect(res.status).toBe(400) 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 () => { it('zap returns 400 for invalid amountSats', async () => {
const app = makeApp() const app = makeApp()
const res = await app.request('/api/payments/zap', { const res = await app.request('/api/payments/zap', {