forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdk-create-factory.test.ts
More file actions
54 lines (45 loc) · 1.94 KB
/
Copy pathsdk-create-factory.test.ts
File metadata and controls
54 lines (45 loc) · 1.94 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
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { LilySdk } from '../src/sdk';
describe('LilySdk.create()', () => {
const originalEnv = process.env;
beforeEach(() => {
vi.resetModules();
process.env = { ...originalEnv };
});
afterEach(() => {
process.env = originalEnv;
});
it('creates an instance with explicit config', () => {
const sdk = LilySdk.create({ baseUrl: 'https://api.example.com' });
expect(sdk).toBeInstanceOf(LilySdk);
expect(sdk.config.baseUrl.toString()).toBe('https://api.example.com/');
});
it('falls back to LILY_API_URL env var when no baseUrl is provided', () => {
process.env.LILY_API_URL = 'https://env.example.com';
const sdk = LilySdk.create();
expect(sdk.config.baseUrl.toString()).toBe('https://env.example.com/');
});
it('explicit config overrides LILY_API_URL env var', () => {
process.env.LILY_API_URL = 'https://env.example.com';
const sdk = LilySdk.create({ baseUrl: 'https://explicit.example.com' });
expect(sdk.config.baseUrl.toString()).toBe('https://explicit.example.com/');
});
it('reads apiKey from LILY_API_KEY env var', () => {
process.env.LILY_API_URL = 'https://api.example.com';
process.env.LILY_API_KEY = 'env-key';
const sdk = LilySdk.create();
expect(sdk.config.apiKey).toBe('env-key');
});
it('never throws when baseUrl is missing (falls back to DEFAULT_API_URL)', () => {
delete process.env.LILY_API_URL;
delete process.env.LILY_BASE_URL;
expect(() => LilySdk.create()).not.toThrow();
expect(LilySdk.create().config.baseUrl.toString()).toBe('https://api.lilyprotocol.com/');
});
it('LILY_API_URL takes precedence over LILY_BASE_URL', () => {
process.env.LILY_API_URL = 'https://api.example.com';
process.env.LILY_BASE_URL = 'https://base.example.com';
const sdk = LilySdk.create();
expect(sdk.config.baseUrl.toString()).toBe('https://api.example.com/');
});
});