forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig-credentials.test.ts
More file actions
39 lines (31 loc) · 1.43 KB
/
Copy pathconfig-credentials.test.ts
File metadata and controls
39 lines (31 loc) · 1.43 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
import { describe, it, expect } from 'vitest';
import { resolveLilySdkConfig } from '../src/config/resolve-config.js';
import { LilyConfigError } from '../src/errors/sdk-error.js';
describe('resolveLilySdkConfig credential validation', () => {
const base = { baseUrl: 'https://api.example.com' };
it('accepts valid non-empty apiKey', () => {
const config = resolveLilySdkConfig({ ...base, apiKey: 'sk-valid' });
expect(config.apiKey).toBe('sk-valid');
});
it('accepts valid non-empty authToken', () => {
const config = resolveLilySdkConfig({ ...base, authToken: 'tok-valid' });
expect(config.authToken).toBe('tok-valid');
});
it('accepts absent credentials', () => {
const config = resolveLilySdkConfig(base);
expect(config.apiKey).toBeUndefined();
expect(config.authToken).toBeUndefined();
});
it('rejects empty-string apiKey', () => {
expect(() => resolveLilySdkConfig({ ...base, apiKey: '' })).toThrow(LilyConfigError);
});
it('rejects empty-string authToken', () => {
expect(() => resolveLilySdkConfig({ ...base, authToken: '' })).toThrow(LilyConfigError);
});
it('rejects non-string apiKey', () => {
expect(() => resolveLilySdkConfig({ ...base, apiKey: 123 as unknown as string })).toThrow(LilyConfigError);
});
it('rejects non-string authToken', () => {
expect(() => resolveLilySdkConfig({ ...base, authToken: null as unknown as string })).toThrow(LilyConfigError);
});
});