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

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

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

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

    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', 'dataroom');
    });
  });

  describe('POST /deals', () => {
    it('should require authentication', async () => {
      const response = await api.post('/deals', {
        name: 'Test Deal',
      });

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

  describe('GET /deals/:dealId', () => {
    it('should require authentication', async () => {
      const response = await api.get('/deals/test-id');

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

