jan/core/src/browser/extensions/engines/RemoteOAIEngine.test.ts
Louis 302b73ae73
test: add web helpers, services, utils tests (#3669)
* test: add web helpers tests

* fix: coverage report

* test: add more tests

* test: add more generated tests

* chore: add more tests

* test: add more tests
2024-09-20 14:24:51 +07:00

44 lines
1.1 KiB
TypeScript

/**
* @jest-environment jsdom
*/
import { RemoteOAIEngine } from './'
class TestRemoteOAIEngine extends RemoteOAIEngine {
inferenceUrl: string = ''
provider: string = 'TestRemoteOAIEngine'
}
describe('RemoteOAIEngine', () => {
let engine: TestRemoteOAIEngine
beforeEach(() => {
engine = new TestRemoteOAIEngine('', '')
})
test('should call onLoad and super.onLoad', () => {
const onLoadSpy = jest.spyOn(engine, 'onLoad')
const superOnLoadSpy = jest.spyOn(Object.getPrototypeOf(RemoteOAIEngine.prototype), 'onLoad')
engine.onLoad()
expect(onLoadSpy).toHaveBeenCalled()
expect(superOnLoadSpy).toHaveBeenCalled()
})
test('should return headers with apiKey', async () => {
engine.apiKey = 'test-api-key'
const headers = await engine.headers()
expect(headers).toEqual({
'Authorization': 'Bearer test-api-key',
'api-key': 'test-api-key',
})
})
test('should return empty headers when apiKey is not set', async () => {
engine.apiKey = undefined
const headers = await engine.headers()
expect(headers).toEqual({})
})
})