Files
Void-Homelab/tests/repos/conversations.test.js

22 lines
1.0 KiB
JavaScript

import { describe, it, expect, beforeEach } from 'vitest';
import { resetDb } from '../helpers/db.js';
import { migrateUp } from '../../lib/db/migrate.js';
import * as agents from '../../lib/db/repos/agents.js';
import * as conversations from '../../lib/db/repos/conversations.js';
import * as messages from '../../lib/db/repos/messages.js';
const owner = { kind: 'user', id: null };
beforeEach(async () => { await resetDb(); await migrateUp(); });
describe('conversations + messages', () => {
it('creates a conversation and appends messages', async () => {
const a = await agents.create({ slug: 'mercy', name: 'Mercy', kind: 'claude' }, owner);
const c = await conversations.create({ title: 'hi', agent_id: a.id }, owner);
const m1 = await messages.append(c.id, { role: 'user', body: 'hello' });
const m2 = await messages.append(c.id, { role: 'assistant', body: 'hi', agent_id: a.id });
const list = await messages.listByConversation(c.id);
expect(list).toHaveLength(2);
expect(list[0].id).toBe(m1.id);
});
});