feat(api): conversations + messages routes
Add conversations CRUD-lite (list, create, get, PATCH status, PATCH summary which flips status to summarized) and conversation-scoped messages (append, list ordered by created_at). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
41
tests/api/conversations.test.js
Normal file
41
tests/api/conversations.test.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { describe, it, expect, beforeAll } from 'vitest';
|
||||
import request from 'supertest';
|
||||
import { setup } from './helpers.js';
|
||||
|
||||
let app, ownerHeaders;
|
||||
beforeAll(async () => { ({ app, ownerHeaders } = await setup()); });
|
||||
|
||||
describe('conversations + messages routes', () => {
|
||||
it('POST creates and GET returns', async () => {
|
||||
const c = await request(app).post('/api/conversations').set(ownerHeaders)
|
||||
.send({ title: 'chat' });
|
||||
expect(c.status).toBe(201);
|
||||
const get = await request(app).get(`/api/conversations/${c.body.id}`).set(ownerHeaders);
|
||||
expect(get.body.id).toBe(c.body.id);
|
||||
});
|
||||
|
||||
it('append + list messages in order', async () => {
|
||||
const c = await request(app).post('/api/conversations').set(ownerHeaders).send({});
|
||||
await request(app).post(`/api/conversations/${c.body.id}/messages`).set(ownerHeaders)
|
||||
.send({ role: 'user', body: 'one' });
|
||||
await request(app).post(`/api/conversations/${c.body.id}/messages`).set(ownerHeaders)
|
||||
.send({ role: 'assistant', body: 'two' });
|
||||
const list = await request(app).get(`/api/conversations/${c.body.id}/messages`).set(ownerHeaders);
|
||||
expect(list.body.map(m => m.body)).toEqual(['one', 'two']);
|
||||
});
|
||||
|
||||
it('PATCH /:id/summary flips status to summarized', async () => {
|
||||
const c = await request(app).post('/api/conversations').set(ownerHeaders).send({});
|
||||
const res = await request(app).patch(`/api/conversations/${c.body.id}/summary`).set(ownerHeaders)
|
||||
.send({ summary: 'tldr' });
|
||||
expect(res.body.status).toBe('summarized');
|
||||
expect(res.body.summary).toBe('tldr');
|
||||
});
|
||||
|
||||
it('append on missing conv → 404', async () => {
|
||||
const res = await request(app)
|
||||
.post('/api/conversations/00000000-0000-0000-0000-000000000000/messages').set(ownerHeaders)
|
||||
.send({ role: 'user', body: 'x' });
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user