-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: client should not throw when disabled if the config is lacking
- Loading branch information
1 parent
0d474b6
commit a32a30e
Showing
2 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { LiteralClient } from '../src'; | ||
|
||
describe('Literal Ai Config', () => { | ||
it('should not throw when disabled', () => { | ||
let client: LiteralClient | undefined; | ||
expect(() => { | ||
client = new LiteralClient(undefined, undefined, true); | ||
}).not.toThrow(); | ||
|
||
expect(client).toBeDefined(); | ||
|
||
// HACK: This is to access private properties | ||
const { url, apiKey, disabled } = client!.api as any; | ||
expect(url).toBe('https://cloud.getliteral.ai'); | ||
expect(apiKey).toBe(undefined); | ||
expect(disabled).toBe(true); | ||
}); | ||
|
||
it('should not throw when keys given', () => { | ||
let client: LiteralClient | undefined; | ||
expect(() => { | ||
client = new LiteralClient('KEY', 'URL'); | ||
}).not.toThrow(); | ||
|
||
expect(client).toBeDefined(); | ||
|
||
// HACK: This is to access private properties | ||
const { url, apiKey, disabled } = client!.api as any; | ||
expect(url).toBe('URL'); | ||
expect(apiKey).toBe('KEY'); | ||
expect(disabled).toBe(false); | ||
}); | ||
|
||
it('should not throw when keys are in env', () => { | ||
process.env.LITERAL_API_URL = 'URL'; | ||
process.env.LITERAL_API_KEY = 'KEY'; | ||
|
||
let client: LiteralClient | undefined; | ||
expect(() => { | ||
client = new LiteralClient('KEY', 'URL'); | ||
}).not.toThrow(); | ||
|
||
delete process.env.LITERAL_API_URL; | ||
delete process.env.LITERAL_API_KEY; | ||
|
||
expect(client).toBeDefined(); | ||
|
||
// HACK: This is to access private properties | ||
const { url, apiKey, disabled } = client!.api as any; | ||
expect(url).toBe('URL'); | ||
expect(apiKey).toBe('KEY'); | ||
expect(disabled).toBe(false); | ||
}); | ||
|
||
it('should throw when no keys given or found', () => { | ||
let client: LiteralClient | undefined; | ||
expect(() => { | ||
client = new LiteralClient(); | ||
}).toThrow(); | ||
|
||
expect(client).toBeUndefined(); | ||
}); | ||
}); |