import { afterEach, describe, expect, it, vi } from 'vitest'; import { getApiBaseUrl, getThalosAuthBaseUrl, getThalosDefaultReturnUrl, getThalosDefaultTenantId } from './client'; describe('client runtime base URLs', () => { afterEach(() => { delete window.__APP_CONFIG__; vi.unstubAllEnvs(); }); it('uses runtime-config API base URL when present', () => { window.__APP_CONFIG__ = { API_BASE_URL: 'http://runtime.example' }; vi.stubEnv('VITE_API_BASE_URL', 'http://env.example'); expect(getApiBaseUrl()).toBe('http://runtime.example'); }); it('falls back to VITE_API_BASE_URL when runtime-config is missing', () => { vi.stubEnv('VITE_API_BASE_URL', 'http://env.example'); expect(getApiBaseUrl()).toBe('http://env.example'); }); it('uses THALOS auth base URL from runtime config when present', () => { window.__APP_CONFIG__ = { API_BASE_URL: 'http://api.example', THALOS_AUTH_BASE_URL: 'http://thalos.example' }; expect(getThalosAuthBaseUrl()).toBe('http://thalos.example'); }); it('falls back to API base URL when THALOS auth base URL is missing', () => { window.__APP_CONFIG__ = { API_BASE_URL: 'http://api.example' }; expect(getThalosAuthBaseUrl()).toBe('http://api.example'); }); it('falls back to localhost default when both runtime and env are missing', () => { expect(getApiBaseUrl()).toBe('http://localhost:8080'); }); it('uses runtime defaults for return URL and tenant when present', () => { window.__APP_CONFIG__ = { THALOS_DEFAULT_RETURN_URL: 'https://waiter-floor-demo.dream-views.com/assignments', THALOS_DEFAULT_TENANT_ID: 'tenant-1' }; expect(getThalosDefaultReturnUrl()).toBe('https://waiter-floor-demo.dream-views.com/assignments'); expect(getThalosDefaultTenantId()).toBe('tenant-1'); }); });