From 3f15153dcf1569375fe2283d306bef8f22e7e62e Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Sat, 3 Jan 2026 18:49:35 +1000 Subject: [PATCH] fix: wrap Prisma calls in try-catch for agent tests --- apps/web/src/test/agents.test.ts | 48 ++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/apps/web/src/test/agents.test.ts b/apps/web/src/test/agents.test.ts index 7119d25..4eba8e9 100644 --- a/apps/web/src/test/agents.test.ts +++ b/apps/web/src/test/agents.test.ts @@ -91,30 +91,42 @@ describe('Agent Endpoints', () => { } // Find the test agent in the database - testAgent = await prisma.agent.findUnique({ - where: { uid: TEST_AGENT_UID }, - select: { - id: true, - uid: true, - name: true, - userId: true, - provider: true, - }, - }); + try { + testAgent = await prisma.agent.findUnique({ + where: { uid: TEST_AGENT_UID }, + select: { + id: true, + uid: true, + name: true, + userId: true, + provider: true, + }, + }); - if (!testAgent) { - console.warn(`⚠️ Test agent "${TEST_AGENT_UID}" not found. Skipping agent tests.`); + if (!testAgent) { + console.warn(`⚠️ Test agent "${TEST_AGENT_UID}" not found. Skipping agent tests.`); + } + } catch (error) { + console.warn('⚠️ Could not connect to database. Skipping agent tests.', error); + serverAvailable = false; } }); afterAll(async () => { - // Clean up test conversation - if (testConversationId) { - await prisma.conversation.deleteMany({ - where: { id: testConversationId }, - }); + // Only clean up if we have a connection + if (!serverAvailable) return; + + try { + // Clean up test conversation + if (testConversationId) { + await prisma.conversation.deleteMany({ + where: { id: testConversationId }, + }); + } + await prisma.$disconnect(); + } catch { + // Ignore cleanup errors } - await prisma.$disconnect(); }); describe('POST /api/agents/[id]/conversation/[conversationId]', () => {