2026-02-02 03:55:39 +08:00
|
|
|
import { createWebsearchConfig } from "./websearch"
|
2026-02-02 03:36:55 +08:00
|
|
|
|
2026-02-08 14:56:43 +09:00
|
|
|
declare const describe: (name: string, callback: () => void) => void
|
|
|
|
|
declare const test: (name: string, callback: () => void) => void
|
|
|
|
|
declare const expect: (value: unknown) => {
|
|
|
|
|
toContain: (expected: string) => void
|
|
|
|
|
toBeUndefined: () => void
|
|
|
|
|
}
|
|
|
|
|
declare const process: { env: Record<string, string | undefined> }
|
2026-02-02 03:36:55 +08:00
|
|
|
|
2026-02-08 14:56:43 +09:00
|
|
|
describe("createWebsearchConfig (Exa)", () => {
|
|
|
|
|
test("appends exaApiKey query param when EXA_API_KEY is set", () => {
|
2026-02-02 03:36:55 +08:00
|
|
|
//#given
|
|
|
|
|
const apiKey = "test-exa-key-12345"
|
2026-02-08 14:56:43 +09:00
|
|
|
const originalExaApiKey = process.env.EXA_API_KEY
|
2026-02-02 03:36:55 +08:00
|
|
|
process.env.EXA_API_KEY = apiKey
|
|
|
|
|
|
|
|
|
|
//#when
|
2026-02-02 03:55:39 +08:00
|
|
|
const result = createWebsearchConfig()
|
2026-02-02 03:36:55 +08:00
|
|
|
|
|
|
|
|
//#then
|
2026-02-08 14:19:50 +09:00
|
|
|
expect(result.url).toContain(`exaApiKey=${encodeURIComponent(apiKey)}`)
|
2026-02-08 14:56:43 +09:00
|
|
|
|
|
|
|
|
process.env.EXA_API_KEY = originalExaApiKey
|
2026-02-08 14:19:50 +09:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("does not set x-api-key header when EXA_API_KEY is set", () => {
|
|
|
|
|
//#given
|
|
|
|
|
const apiKey = "test-exa-key-12345"
|
2026-02-08 14:56:43 +09:00
|
|
|
const originalExaApiKey = process.env.EXA_API_KEY
|
2026-02-08 14:19:50 +09:00
|
|
|
process.env.EXA_API_KEY = apiKey
|
|
|
|
|
|
|
|
|
|
//#when
|
|
|
|
|
const result = createWebsearchConfig()
|
|
|
|
|
|
|
|
|
|
//#then
|
|
|
|
|
expect(result.headers).toBeUndefined()
|
2026-02-08 14:56:43 +09:00
|
|
|
if (result.headers) {
|
|
|
|
|
expect(result.headers["x-api-key"]).toBeUndefined()
|
|
|
|
|
}
|
2026-02-02 03:36:55 +08:00
|
|
|
|
2026-02-08 14:56:43 +09:00
|
|
|
process.env.EXA_API_KEY = originalExaApiKey
|
2026-02-02 03:36:55 +08:00
|
|
|
})
|
|
|
|
|
})
|