restaurant-admin-web/src/api/client.test.ts
2026-03-08 16:06:29 -06:00

42 lines
1.3 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest';
import { getApiBaseUrl, getThalosAuthBaseUrl } 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');
});
});