Files
ccs/tests/unit/ui-api-client.test.ts
T
Tam Nhu Tran c18adc90c3 fix(ui): harden cliproxy panel and proxy edge handling
- make iframe auto-login/reload flow race-safe and lint-compliant

- normalize API base joins and replace conflict sentinels with typed errors

- tighten proxy port validation and defer cursor preset apply until models load

- add ui api-client unit coverage for path and conflict helpers
2026-02-18 04:18:57 +07:00

33 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'bun:test';
import {
API_BASE_URL,
API_CONFLICT_ERROR_CODE,
ApiConflictError,
isApiConflictError,
withApiBase,
} from '../../ui/src/lib/api-client';
describe('ui api-client helpers', () => {
it('normalizes relative paths with API base prefix', () => {
expect(withApiBase('/cliproxy/status')).toBe('/api/cliproxy/status');
expect(withApiBase('cliproxy/status')).toBe('/api/cliproxy/status');
});
it('preserves paths that already include API base', () => {
expect(withApiBase('/api/cliproxy/status')).toBe('/api/cliproxy/status');
expect(withApiBase('/api')).toBe('/api');
});
it('handles empty and absolute URLs safely', () => {
expect(withApiBase('')).toBe(API_BASE_URL);
expect(withApiBase('https://example.com/api')).toBe('https://example.com/api');
});
it('identifies typed API conflict errors', () => {
const conflict = new ApiConflictError('conflict');
expect(conflict.code).toBe(API_CONFLICT_ERROR_CODE);
expect(isApiConflictError(conflict)).toBe(true);
expect(isApiConflictError(new Error('plain'))).toBe(false);
});
});