// {{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

import { afterEach, describe, expect, it } from 'vitest';

import { loadConfig } from '../../../src/core/config-manager.js';

const ENV_PREFIX = '{{ tool_prefix_env }}';
const SAMPLE_AUTH_METHOD = '{{ auth_method_keys.0 }}';

describe('loadConfig', () => {
  afterEach(() => {
    delete process.env[`${ENV_PREFIX}_URL`];
    delete process.env[`${ENV_PREFIX}_AUTH_METHOD`];
  });

  it('resolves values from environment variables', () => {
    process.env[`${ENV_PREFIX}_URL`] = 'https://example.com';
    process.env[`${ENV_PREFIX}_AUTH_METHOD`] = SAMPLE_AUTH_METHOD;

    const config = loadConfig();

    expect(config.url).toBe('https://example.com');
    expect(config.auth_method).toBe(SAMPLE_AUTH_METHOD);
  });

  it('CLI flags take priority over environment variables', () => {
    process.env[`${ENV_PREFIX}_URL`] = 'https://from-env.example.com';
    process.env[`${ENV_PREFIX}_AUTH_METHOD`] = SAMPLE_AUTH_METHOD;

    const config = loadConfig({ url: 'https://from-cli.example.com' });

    expect(config.url).toBe('https://from-cli.example.com');
  });

  it('applies built-in defaults for unset optional fields', () => {
    process.env[`${ENV_PREFIX}_URL`] = 'https://example.com';
    process.env[`${ENV_PREFIX}_AUTH_METHOD`] = SAMPLE_AUTH_METHOD;

    const config = loadConfig();

    expect(config.log_level).toBe('info');
    expect(config.transport).toBe('stdio');
    expect(config.rate_limit).toBe(100);
  });

  it('rejects a missing required url', () => {
    delete process.env[`${ENV_PREFIX}_URL`];
    process.env[`${ENV_PREFIX}_AUTH_METHOD`] = SAMPLE_AUTH_METHOD;

    expect(() => loadConfig()).toThrow();
  });
});
