forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaseurl-path-prefix.test.ts
More file actions
52 lines (44 loc) · 2.06 KB
/
Copy pathbaseurl-path-prefix.test.ts
File metadata and controls
52 lines (44 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { describe, it, expect } from 'vitest';
import { resolveLilySdkConfig } from '../src/config/resolve-config';
import type { LilySdkConfig } from '../src/config/types';
describe('baseUrl path-prefix handling', () => {
it('appends a trailing slash if missing', () => {
const config: LilySdkConfig = { baseUrl: 'https://api.lily.dev' };
const resolved = resolveLilySdkConfig(config);
expect(resolved.baseUrl.href).toBe('https://api.lily.dev/');
});
it('preserves an existing trailing slash', () => {
const config: LilySdkConfig = { baseUrl: 'https://api.lily.dev/' };
const resolved = resolveLilySdkConfig(config);
expect(resolved.baseUrl.href).toBe('https://api.lily.dev/');
});
it('preserves a path prefix in baseUrl', () => {
const config: LilySdkConfig = { baseUrl: 'https://api.lily.dev/v1' };
const resolved = resolveLilySdkConfig(config);
expect(resolved.baseUrl.href).toBe('https://api.lily.dev/v1/');
});
it('preserves a path prefix with trailing slash', () => {
const config: LilySdkConfig = { baseUrl: 'https://api.lily.dev/v1/' };
const resolved = resolveLilySdkConfig(config);
expect(resolved.baseUrl.href).toBe('https://api.lily.dev/v1/');
});
it('rejects non-HTTP schemes', () => {
const config: LilySdkConfig = { baseUrl: 'ftp://example.com' };
expect(() => resolveLilySdkConfig(config)).toThrow();
});
it('rejects relative URLs', () => {
const config: LilySdkConfig = { baseUrl: '/api' };
expect(() => resolveLilySdkConfig(config)).toThrow();
});
it('accepts localhost with http', () => {
const config: LilySdkConfig = { baseUrl: 'http://localhost:3000' };
const resolved = resolveLilySdkConfig(config);
expect(resolved.baseUrl.href).toBe('http://localhost:3000/');
});
it('normalizes a double-slash path prefix', () => {
const config: LilySdkConfig = { baseUrl: 'https://api.lily.dev//v1' };
const resolved = resolveLilySdkConfig(config);
// URL constructor normalizes double slashes in path
expect(resolved.baseUrl.href).toContain('api.lily.dev');
});
});