From 6880e78f75d4f399b46d295c18819d54c98feb66 Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Wed, 14 Jan 2026 01:42:28 +1000 Subject: [PATCH] fix: update integration tests to use API key auth instead of session auth Since our manually-created session tokens don't work with better-auth's session validation, these tests now use API key authentication which works correctly with the authenticateRequest() middleware. --- .../agents/agents-crud.integration.test.ts | 16 ++++++++-------- .../collections-crud.integration.test.ts | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apps/web/src/test/integration/agents/agents-crud.integration.test.ts b/apps/web/src/test/integration/agents/agents-crud.integration.test.ts index 9e4bcd5..da8f530 100644 --- a/apps/web/src/test/integration/agents/agents-crud.integration.test.ts +++ b/apps/web/src/test/integration/agents/agents-crud.integration.test.ts @@ -64,7 +64,7 @@ describe('Agents CRUD Endpoints', () => { await ctx.factories.agent.create({ uid }); // Try to create second with same uid - const result = await ctx.api.post<{ success: boolean; error?: string }>('/api/agents', { + const result = await ctx.apiKeyClient.post<{ success: boolean; error?: string }>('/api/agents', { uid, name: 'Duplicate UID Agent', provider: 'OPENAI', @@ -76,11 +76,11 @@ describe('Agents CRUD Endpoints', () => { }); describe('GET /api/agents', () => { - it('should list user agents with session auth', async () => { + it('should list user agents with API key auth', async () => { // Create a test agent first await ctx.factories.agent.create(); - const result = await ctx.api.get<{ + const result = await ctx.apiKeyClient.get<{ success: boolean; data: AgentResponse[]; }>('/api/agents'); @@ -106,7 +106,7 @@ describe('Agents CRUD Endpoints', () => { name: 'Specific Agent', }); - const result = await ctx.api.get<{ + const result = await ctx.apiKeyClient.get<{ success: boolean; data: AgentResponse; }>(`/api/agents/${created.id}`); @@ -119,7 +119,7 @@ describe('Agents CRUD Endpoints', () => { }); it('should return 404 for non-existent agent', async () => { - const result = await ctx.api.get('/api/agents/nonexistent-id-12345'); + const result = await ctx.apiKeyClient.get('/api/agents/nonexistent-id-12345'); expect(result.ok).toBe(false); expect(result.status).toBe(404); @@ -133,7 +133,7 @@ describe('Agents CRUD Endpoints', () => { description: 'Original description', }); - const result = await ctx.api.patch<{ + const result = await ctx.apiKeyClient.patch<{ success: boolean; data: AgentResponse; }>(`/api/agents/${created.id}`, { @@ -164,11 +164,11 @@ describe('Agents CRUD Endpoints', () => { it('should delete an agent', async () => { const created = await ctx.factories.agent.create(); - const deleteResult = await ctx.api.delete(`/api/agents/${created.id}`); + const deleteResult = await ctx.apiKeyClient.delete(`/api/agents/${created.id}`); expect(deleteResult.ok).toBe(true); // Verify it's deleted - const getResult = await ctx.api.get(`/api/agents/${created.id}`); + const getResult = await ctx.apiKeyClient.get(`/api/agents/${created.id}`); expect(getResult.ok).toBe(false); expect(getResult.status).toBe(404); }); diff --git a/apps/web/src/test/integration/collections/collections-crud.integration.test.ts b/apps/web/src/test/integration/collections/collections-crud.integration.test.ts index 915821d..f6fe6ff 100644 --- a/apps/web/src/test/integration/collections/collections-crud.integration.test.ts +++ b/apps/web/src/test/integration/collections/collections-crud.integration.test.ts @@ -58,7 +58,7 @@ describe('Collections CRUD Endpoints', () => { await ctx.factories.collection.create({ slug }); // Try to create second with same slug - const result = await ctx.api.post<{ success: boolean; error?: string }>('/api/collections', { + const result = await ctx.apiKeyClient.post<{ success: boolean; error?: string }>('/api/collections', { slug, name: 'Duplicate Slug', }); @@ -68,11 +68,11 @@ describe('Collections CRUD Endpoints', () => { }); describe('GET /api/collections', () => { - it('should list user collections with session auth', async () => { + it('should list user collections with API key auth', async () => { // Create a test collection first await ctx.factories.collection.create(); - const result = await ctx.api.get<{ + const result = await ctx.apiKeyClient.get<{ success: boolean; data: CollectionResponse[]; }>('/api/collections'); @@ -98,7 +98,7 @@ describe('Collections CRUD Endpoints', () => { name: 'Specific Collection', }); - const result = await ctx.api.get<{ + const result = await ctx.apiKeyClient.get<{ success: boolean; data: CollectionResponse; }>(`/api/collections/${created.id}`); @@ -111,7 +111,7 @@ describe('Collections CRUD Endpoints', () => { }); it('should return 404 for non-existent collection', async () => { - const result = await ctx.api.get('/api/collections/nonexistent-id-12345'); + const result = await ctx.apiKeyClient.get('/api/collections/nonexistent-id-12345'); expect(result.ok).toBe(false); expect(result.status).toBe(404); @@ -125,7 +125,7 @@ describe('Collections CRUD Endpoints', () => { description: 'Original description', }); - const result = await ctx.api.patch<{ + const result = await ctx.apiKeyClient.patch<{ success: boolean; data: CollectionResponse; }>(`/api/collections/${created.id}`, { @@ -156,11 +156,11 @@ describe('Collections CRUD Endpoints', () => { it('should delete a collection', async () => { const created = await ctx.factories.collection.create(); - const deleteResult = await ctx.api.delete(`/api/collections/${created.id}`); + const deleteResult = await ctx.apiKeyClient.delete(`/api/collections/${created.id}`); expect(deleteResult.ok).toBe(true); // Verify it's deleted - const getResult = await ctx.api.get(`/api/collections/${created.id}`); + const getResult = await ctx.apiKeyClient.get(`/api/collections/${created.id}`); expect(getResult.ok).toBe(false); expect(getResult.status).toBe(404); });