import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import Fastify, { FastifyInstance } from 'fastify';
import { createApiHelpers } from '@the-order/test-utils';

describe('Intake Service', () => {
  let app: FastifyInstance;
  let api: ReturnType<typeof createApiHelpers>;

  beforeEach(async () => {
    app = Fastify({
      logger: false,
    });

    app.get('/health', async () => {
      return { status: 'ok', service: 'intake' };
    });

    await app.ready();
    api = createApiHelpers(app);
  });

  afterEach(async () => {
    if (app) {
      await app.close();
    }
  });

  describe('GET /health', () => {
    it('should return health status', async () => {
      const response = await api.get('/health');
      expect(response.status).toBe(200);
      expect(response.body).toHaveProperty('status');
      expect(response.body).toHaveProperty('service', 'intake');
    });
  });

  describe('POST /ingest', () => {
    it('should require authentication', async () => {
      const response = await api.post('/ingest', {
        title: 'Test Document',
        type: 'legal',
      });

      expect([401, 500]).toContain(response.status);
    });
  });
});

