import { validationSchema } from '../../config/validation.schema';

describe('reliability environment validation', () => {
  const validEnvironment = {
    NODE_ENV: 'test',
    MONGODB_URI: 'mongodb://127.0.0.1:27017/test',
    JWT_ACCESS_SECRET: 'access-secret-at-least-16',
    JWT_REFRESH_SECRET: 'refresh-secret-at-least-16',
    SUPERADMIN_EMAIL: 'admin@example.com',
    SUPERADMIN_PASSWORD: 'StrongPassword123!',
    SUPERADMIN_ACCESS_SECRET: 'admin-access-secret-at-least-16',
    SUPERADMIN_REFRESH_SECRET: 'admin-refresh-secret-at-least-16',
    STORAGE_PROVIDER: 'local',
    MEDIA_ACCESS_MODE: 'direct',
  };

  it('applies safe reliability defaults', () => {
    const { error, value } = validationSchema.validate(validEnvironment);
    expect(error).toBeUndefined();
    expect(value).toEqual(
      expect.objectContaining({
        HTTP_REQUEST_TIMEOUT_MS: 30_000,
        HTTP_SERVER_REQUEST_TIMEOUT_MS: 120_000,
        HTTP_HEADERS_TIMEOUT_MS: 15_000,
        HTTP_KEEP_ALIVE_TIMEOUT_MS: 5_000,
        SHUTDOWN_GRACE_PERIOD_MS: 30_000,
      }),
    );
  });

  it('rejects unsafe or contradictory timeout settings', () => {
    expect(
      validationSchema.validate({ ...validEnvironment, HTTP_REQUEST_TIMEOUT_MS: 500 }).error,
    ).toBeDefined();
    expect(
      validationSchema.validate({
        ...validEnvironment,
        HTTP_HEADERS_TIMEOUT_MS: 4_000,
        HTTP_KEEP_ALIVE_TIMEOUT_MS: 5_000,
      }).error,
    ).toBeDefined();
  });
});
