import { describe, expect, it } from 'vitest';
import { buildApp } from '../build-app.js';

describe('composition root', () => {
  it('exposes GET /health through the wired app', async () => {
    const app = await buildApp();
    const response = await app.inject({ method: 'GET', url: '/health' });

    expect(response.statusCode).toBe(200);
    expect(response.json()).toEqual({ status: 'ok' });
    await app.close();
  });

  it('returns 404 JSON envelope for unknown routes without leaking internals', async () => {
    const app = await buildApp();
    const response = await app.inject({ method: 'GET', url: '/does-not-exist' });

    expect(response.statusCode).toBe(404);
    const body = response.json() as { error: { statusCode: number; message: string } };
    expect(body.error.statusCode).toBe(404);
    expect(body.error.message).toBe('Not Found');
    expect(response.body).not.toContain('stack');
    await app.close();
  });
});
