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

describe('env API URL resolution', () => {
  it('uses same-origin when VITE_API_URL is unset (production nginx proxy)', async () => {
    vi.stubEnv('VITE_API_URL', '');
    vi.stubEnv('VITE_ENV', 'production');
    vi.stubEnv('DEV', false);
    vi.stubEnv('PROD', true);
    vi.stubEnv('MODE', 'production');

    vi.resetModules();
    const { env } = await import('./env');
    expect(env.API_URL).toBe('');
  });

  it('honors explicit VITE_API_URL', async () => {
    vi.stubEnv('VITE_API_URL', 'https://api.example.com/');
    vi.stubEnv('VITE_ENV', 'production');
    vi.stubEnv('DEV', false);
    vi.stubEnv('PROD', true);
    vi.stubEnv('MODE', 'production');

    vi.resetModules();
    const { env } = await import('./env');
    expect(env.API_URL).toBe('https://api.example.com');
  });
});
