diff --git a/src/app/api/swarm/archetypes/route.ts b/src/app/api/swarm/archetypes/route.ts new file mode 100644 index 0000000..36b147e --- /dev/null +++ b/src/app/api/swarm/archetypes/route.ts @@ -0,0 +1,7 @@ +import { NextResponse } from 'next/server'; +import { getArchetypes } from '../../../../lib/server/beads-fs'; + +export async function GET() { + const data = await getArchetypes(); + return NextResponse.json(data); +} diff --git a/tests/api/swarm/archetypes.test.ts b/tests/api/swarm/archetypes.test.ts new file mode 100644 index 0000000..b4d6ba6 --- /dev/null +++ b/tests/api/swarm/archetypes.test.ts @@ -0,0 +1,20 @@ +import { expect, test, describe, mock } from 'bun:test'; +import { GET } from '../../../src/app/api/swarm/archetypes/route'; + +// Mock the dependency +mock.module('../../../src/lib/server/beads-fs', () => ({ + getArchetypes: async () => [ + { id: 'test-arch', name: 'Test', isBuiltIn: true } + ] +})); + +describe('/api/swarm/archetypes GET', () => { + test('returns 200 and a JSON array of archetypes', async () => { + const response = await GET(); + expect(response.status).toBe(200); + + const data = await response.json(); + expect(Array.isArray(data)).toBe(true); + expect(data[0].id).toBe('test-arch'); + }); +});