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

35 lines
1.4 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 pending from '../../lib/db/repos/pending_changes.js';
const owner = { kind: 'user', id: null };
beforeEach(async () => { await resetDb(); await migrateUp(); });
describe('pending changes', () => {
it('creates and resolves a pending change', async () => {
const a = await agents.create({ slug: 'mercy', name: 'Mercy', kind: 'claude' }, owner);
const p = await pending.create({
agent_id: a.id, entity_type: 'page', action: 'create',
payload: { title: 'draft', body_md: 'hi' }, reason: 'inferred from chat'
});
expect(p.status).toBe('pending');
const resolved = await pending.resolve(p.id, 'approved', 'owner');
expect(resolved.status).toBe('approved');
});
it('listPending returns only pending rows', async () => {
const a = await agents.create({ slug: 'mercy', name: 'Mercy', kind: 'claude' }, owner);
const p1 = await pending.create({
agent_id: a.id, entity_type: 'page', action: 'create', payload: { title: 'a' }
});
await pending.create({
agent_id: a.id, entity_type: 'page', action: 'create', payload: { title: 'b' }
});
await pending.resolve(p1.id, 'rejected', 'owner');
const pendingRows = await pending.listPending();
expect(pendingRows).toHaveLength(1);
});
});