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.
This commit is contained in:
parent
d524d2ca16
commit
6880e78f75
2 changed files with 16 additions and 16 deletions
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue