fix: use unique names in integration tests to avoid collision

- Add timestamps to test agent/collection names to make them unique
- Fix duplicate UID test to verify auto-suffix behavior instead of rejection
- Use agent id instead of uid for cleanup tracking
This commit is contained in:
Ajax Davis 2026-01-14 01:52:41 +10:00
parent 6880e78f75
commit 56c4df74b7
3 changed files with 47 additions and 31 deletions

View file

@ -15,9 +15,9 @@ describe('Agent Conversations Endpoints', () => {
beforeAll(async () => {
ctx = getTestContext();
// Create a test agent for conversation tests
// Create a test agent for conversation tests with unique name
testAgent = await ctx.factories.agent.create({
name: 'Conversation Test Agent',
name: `Conversation Test Agent ${Date.now()}`,
description: 'Agent for testing conversations',
systemPrompt: 'You are a helpful assistant. Keep responses brief.',
maxToolCallsPerTurn: 5,

View file

@ -29,9 +29,10 @@ describe('Agents CRUD Endpoints', () => {
});
describe('POST /api/agents', () => {
it('should create a new agent with session auth', async () => {
it('should create a new agent with API key auth', async () => {
const uniqueName = `Test CRUD Agent ${Date.now()}`;
const agent = await ctx.factories.agent.create({
name: 'Test CRUD Agent',
name: uniqueName,
description: 'Created via integration test',
provider: 'OPENAI',
modelId: 'gpt-4o-mini',
@ -39,7 +40,7 @@ describe('Agents CRUD Endpoints', () => {
});
expect(agent.id).toBeDefined();
expect(agent.name).toBe('Test CRUD Agent');
expect(agent.name).toBe(uniqueName);
expect(agent.description).toBe('Created via integration test');
expect(agent.provider).toBe('OPENAI');
expect(agent.isPublic).toBe(true);
@ -57,21 +58,29 @@ describe('Agents CRUD Endpoints', () => {
expect(result.status).toBe(401);
});
it('should reject duplicate uids', async () => {
it('should auto-suffix duplicate uids', async () => {
const uid = `test-duplicate-uid-${Date.now()}`;
// Create first agent
await ctx.factories.agent.create({ uid });
const firstAgent = await ctx.factories.agent.create({ uid });
expect(firstAgent.uid).toBe(uid);
// Try to create second with same uid
const result = await ctx.apiKeyClient.post<{ success: boolean; error?: string }>('/api/agents', {
// Create second with same uid - should succeed with modified uid
const result = await ctx.apiKeyClient.post<{ success: boolean; data: { uid: string } }>('/api/agents', {
uid,
name: 'Duplicate UID Agent',
name: `Duplicate UID Agent ${Date.now()}`,
provider: 'OPENAI',
modelId: 'gpt-4o-mini',
});
expect(result.ok).toBe(false);
expect(result.ok).toBe(true);
if (result.ok) {
// The new agent should have a different (auto-suffixed) uid
expect(result.data.data.uid).not.toBe(uid);
expect(result.data.data.uid).toMatch(new RegExp(`^${uid}-`));
// Track for cleanup (use id, not uid)
ctx.tracker.trackAgent((result.data.data as { id: string }).id);
}
});
});
@ -102,8 +111,9 @@ describe('Agents CRUD Endpoints', () => {
describe('GET /api/agents/:id', () => {
it('should get a specific agent', async () => {
const uniqueName = `Specific Agent ${Date.now()}`;
const created = await ctx.factories.agent.create({
name: 'Specific Agent',
name: uniqueName,
});
const result = await ctx.apiKeyClient.get<{
@ -114,7 +124,7 @@ describe('Agents CRUD Endpoints', () => {
expect(result.ok).toBe(true);
if (result.ok) {
expect(result.data.data.id).toBe(created.id);
expect(result.data.data.name).toBe('Specific Agent');
expect(result.data.data.name).toBe(uniqueName);
}
});
@ -128,22 +138,24 @@ describe('Agents CRUD Endpoints', () => {
describe('PATCH /api/agents/:id', () => {
it('should update an agent', async () => {
const timestamp = Date.now();
const created = await ctx.factories.agent.create({
name: 'Before Update',
name: `Before Update ${timestamp}`,
description: 'Original description',
});
const updatedName = `After Update ${timestamp}`;
const result = await ctx.apiKeyClient.patch<{
success: boolean;
data: AgentResponse;
}>(`/api/agents/${created.id}`, {
name: 'After Update',
name: updatedName,
description: 'Updated description',
});
expect(result.ok).toBe(true);
if (result.ok) {
expect(result.data.data.name).toBe('After Update');
expect(result.data.data.name).toBe(updatedName);
expect(result.data.data.description).toBe('Updated description');
}
});

View file

@ -28,15 +28,16 @@ describe('Collections CRUD Endpoints', () => {
});
describe('POST /api/collections', () => {
it('should create a new collection with session auth', async () => {
it('should create a new collection with API key auth', async () => {
const uniqueName = `Test CRUD Collection ${Date.now()}`;
const collection = await ctx.factories.collection.create({
name: 'Test CRUD Collection',
name: uniqueName,
description: 'Created via integration test',
isPublic: true,
});
expect(collection.id).toBeDefined();
expect(collection.name).toBe('Test CRUD Collection');
expect(collection.name).toBe(uniqueName);
expect(collection.description).toBe('Created via integration test');
expect(collection.isPublic).toBe(true);
});
@ -51,19 +52,19 @@ describe('Collections CRUD Endpoints', () => {
expect(result.status).toBe(401);
});
it('should reject duplicate slugs for same user', async () => {
const slug = `test-duplicate-${Date.now()}`;
it('should reject duplicate names for same user', async () => {
const uniqueName = `Duplicate Test ${Date.now()}`;
// Create first collection
await ctx.factories.collection.create({ slug });
await ctx.factories.collection.create({ name: uniqueName });
// Try to create second with same slug
const result = await ctx.apiKeyClient.post<{ success: boolean; error?: string }>('/api/collections', {
slug,
name: 'Duplicate Slug',
// Try to create second with same name
const result = await ctx.apiKeyClient.post<{ success: boolean; error?: { code: string } }>('/api/collections', {
name: uniqueName,
});
expect(result.ok).toBe(false);
expect(result.status).toBe(409);
});
});
@ -94,8 +95,9 @@ describe('Collections CRUD Endpoints', () => {
describe('GET /api/collections/:id', () => {
it('should get a specific collection', async () => {
const uniqueName = `Specific Collection ${Date.now()}`;
const created = await ctx.factories.collection.create({
name: 'Specific Collection',
name: uniqueName,
});
const result = await ctx.apiKeyClient.get<{
@ -106,7 +108,7 @@ describe('Collections CRUD Endpoints', () => {
expect(result.ok).toBe(true);
if (result.ok) {
expect(result.data.data.id).toBe(created.id);
expect(result.data.data.name).toBe('Specific Collection');
expect(result.data.data.name).toBe(uniqueName);
}
});
@ -120,22 +122,24 @@ describe('Collections CRUD Endpoints', () => {
describe('PATCH /api/collections/:id', () => {
it('should update a collection', async () => {
const timestamp = Date.now();
const created = await ctx.factories.collection.create({
name: 'Before Update',
name: `Before Update ${timestamp}`,
description: 'Original description',
});
const updatedName = `After Update ${timestamp}`;
const result = await ctx.apiKeyClient.patch<{
success: boolean;
data: CollectionResponse;
}>(`/api/collections/${created.id}`, {
name: 'After Update',
name: updatedName,
description: 'Updated description',
});
expect(result.ok).toBe(true);
if (result.ok) {
expect(result.data.data.name).toBe('After Update');
expect(result.data.data.name).toBe(updatedName);
expect(result.data.data.description).toBe('Updated description');
}
});