64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import { mkdtempSync, rmSync } from 'fs';
|
|
import { tmpdir } from 'os';
|
|
import { join } from 'path';
|
|
import { buildApp } from '../src/server/index.js';
|
|
import { init } from '../src/cli/commands/init.js';
|
|
|
|
describe('server routes', () => {
|
|
let cwd: string;
|
|
let app: ReturnType<typeof buildApp>;
|
|
|
|
beforeEach(() => {
|
|
cwd = mkdtempSync(join(tmpdir(), 'ah-server-'));
|
|
init(cwd, { projectName: 'server-test', yes: true });
|
|
app = buildApp(cwd);
|
|
});
|
|
|
|
afterEach(() => {
|
|
rmSync(cwd, { recursive: true, force: true });
|
|
});
|
|
|
|
it('creates a task via POST /tasks', async () => {
|
|
const res = await app.inject({
|
|
method: 'POST',
|
|
url: '/tasks',
|
|
payload: { title: 'API task', role: 'implementer' },
|
|
});
|
|
expect(res.statusCode).toBe(200);
|
|
const task = JSON.parse(res.payload);
|
|
expect(task.id).toBe('TSK-0001');
|
|
});
|
|
|
|
it('lists tasks via GET /tasks', async () => {
|
|
await app.inject({ method: 'POST', url: '/tasks', payload: { title: 'A', role: 'implementer' } });
|
|
const res = await app.inject({ method: 'GET', url: '/tasks' });
|
|
expect(JSON.parse(res.payload)).toHaveLength(1);
|
|
});
|
|
|
|
it('returns 404 for unknown task', async () => {
|
|
const res = await app.inject({ method: 'GET', url: '/tasks/TSK-9999' });
|
|
expect(res.statusCode).toBe(404);
|
|
});
|
|
|
|
it('returns 400 for unsupported patch', async () => {
|
|
await app.inject({ method: 'POST', url: '/tasks', payload: { title: 'A', role: 'implementer' } });
|
|
const res = await app.inject({ method: 'PATCH', url: '/tasks/TSK-0001', payload: { status: 'unknown' } });
|
|
expect(res.statusCode).toBe(400);
|
|
});
|
|
|
|
it('updates status via POST /status/update', async () => {
|
|
await app.inject({ method: 'POST', url: '/tasks', payload: { title: 'A', role: 'implementer' } });
|
|
const res = await app.inject({ method: 'POST', url: '/status/update' });
|
|
expect(res.statusCode).toBe(200);
|
|
expect(JSON.parse(res.payload).body).toContain('Active tasks: 1');
|
|
});
|
|
|
|
it('searches memory via GET /memory/search', async () => {
|
|
await app.inject({ method: 'POST', url: '/memory', payload: { title: 'DNS cache', category: 'technical', content: 'Use TTL' } });
|
|
const res = await app.inject({ method: 'GET', url: '/memory/search?q=TTL' });
|
|
expect(res.statusCode).toBe(200);
|
|
expect(JSON.parse(res.payload)).toHaveLength(1);
|
|
});
|
|
});
|