forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapikey-only-config.test.ts
More file actions
69 lines (62 loc) · 2.08 KB
/
Copy pathapikey-only-config.test.ts
File metadata and controls
69 lines (62 loc) · 2.08 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { describe, it, expect } from 'vitest';
import { resolveLilySdkConfig } from '../src/config/resolve-config';
import type { LilySdkConfig } from '../src/config/types';
describe('apiKey-only configuration', () => {
it('resolves config with only apiKey', () => {
const config: LilySdkConfig = {
baseUrl: 'https://api.lily.dev',
apiKey: 'test-api-key',
};
const resolved = resolveLilySdkConfig(config);
expect(resolved.apiKey).toBe('test-api-key');
expect(resolved.authToken).toBeUndefined();
});
it('does not set authToken when only apiKey is provided', () => {
const config: LilySdkConfig = {
baseUrl: 'https://api.lily.dev',
apiKey: 'k',
};
const resolved = resolveLilySdkConfig(config);
expect(resolved).not.toHaveProperty('authToken');
});
it('does not set apiKey when only authToken is provided', () => {
const config: LilySdkConfig = {
baseUrl: 'https://api.lily.dev',
authToken: 'Bearer token',
};
const resolved = resolveLilySdkConfig(config);
expect(resolved.authToken).toBe('Bearer token');
expect(resolved).not.toHaveProperty('apiKey');
});
it('sets both when both are provided', () => {
const config: LilySdkConfig = {
baseUrl: 'https://api.lily.dev',
apiKey: 'k',
authToken: 'Bearer t',
};
const resolved = resolveLilySdkConfig(config);
expect(resolved.apiKey).toBe('k');
expect(resolved.authToken).toBe('Bearer t');
});
it('rejects empty-string apiKey', () => {
const config: LilySdkConfig = {
baseUrl: 'https://api.lily.dev',
apiKey: '',
};
expect(() => resolveLilySdkConfig(config)).toThrow();
});
it('rejects empty-string authToken', () => {
const config: LilySdkConfig = {
baseUrl: 'https://api.lily.dev',
authToken: '',
};
expect(() => resolveLilySdkConfig(config)).toThrow();
});
it('rejects whitespace-only apiKey', () => {
const config: LilySdkConfig = {
baseUrl: 'https://api.lily.dev',
apiKey: ' ',
};
expect(() => resolveLilySdkConfig(config)).toThrow();
});
});