import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { MemoryDatastoreProvider } from '@bytelyst/datastore';
import { _resetDatastoreProvider, setProvider } from '../../lib/datastore.js';
import * as repo from './repository.js';

describe('reviews repository', () => {
  beforeEach(() => {
    setProvider(new MemoryDatastoreProvider());
  });

  afterEach(() => {
    _resetDatastoreProvider();
  });

  it('creates and filters review items', async () => {
    await repo.create({
      id: 'rev_1',
      productId: 'lysnrai',
      title: 'Approve outbound action',
      description: 'Agent wants to send a customer-facing message.',
      category: 'agent_action',
      status: 'pending',
      priority: 'high',
      scope: 'org',
      orgId: 'org_1',
      requestedBy: 'user_1',
      source: 'mcp.a2a',
      actionType: 'send_message',
      createdAt: '2026-03-15T00:00:00.000Z',
      updatedAt: '2026-03-15T00:00:00.000Z',
    });

    const reviews = await repo.list('lysnrai', { limit: 20, status: 'pending' });
    expect(reviews).toHaveLength(1);
    expect(reviews[0].category).toBe('agent_action');
  });
});
