Files
Void-Homelab/tests/db/conversations_global.test.js
2026-06-04 21:04:31 +10:00

20 lines
838 B
JavaScript

import { describe, it, expect, beforeAll } 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';
const owner = { kind: 'user', id: null };
beforeAll(async () => { await resetDb(); await migrateUp(); });
describe('findOrCreateGlobal', () => {
it('creates one space-less open conversation and reuses it', async () => {
const y = await agents.getBySlug('yerin'); // seeded by 011_yerin.sql
const c1 = await conversations.findOrCreateGlobal(y.id, owner);
expect(c1.space_id).toBeNull();
expect(c1.agent_id).toBe(y.id);
const c2 = await conversations.findOrCreateGlobal(y.id, owner);
expect(c2.id).toBe(c1.id);
});
});