|
1 | | -import { describe, expect, test } from 'bun:test' |
| 1 | +import { describe, expect, test, beforeEach, afterEach } from 'bun:test' |
2 | 2 | import { extractHits } from './custom.js' |
3 | 3 |
|
4 | 4 | // --------------------------------------------------------------------------- |
@@ -83,3 +83,41 @@ describe('extractHits', () => { |
83 | 83 | expect(hits).toHaveLength(1) |
84 | 84 | }) |
85 | 85 | }) |
| 86 | + |
| 87 | +// --------------------------------------------------------------------------- |
| 88 | +// buildAuthHeadersForPreset — tested indirectly via env vars |
| 89 | +// --------------------------------------------------------------------------- |
| 90 | + |
| 91 | +describe('buildAuthHeadersForPreset auth header behavior', () => { |
| 92 | + const savedEnv: Record<string, string | undefined> = {} |
| 93 | + |
| 94 | + beforeEach(() => { |
| 95 | + for (const k of ['WEB_KEY', 'WEB_AUTH_HEADER', 'WEB_AUTH_SCHEME']) { |
| 96 | + savedEnv[k] = process.env[k] |
| 97 | + } |
| 98 | + }) |
| 99 | + |
| 100 | + afterEach(() => { |
| 101 | + for (const [k, v] of Object.entries(savedEnv)) { |
| 102 | + if (v === undefined) delete process.env[k] |
| 103 | + else process.env[k] = v |
| 104 | + } |
| 105 | + }) |
| 106 | + |
| 107 | + // We test isConfigured() which depends on WEB_SEARCH_API/WEB_PROVIDER/WEB_URL_TEMPLATE |
| 108 | + // and the auth behavior through the public search() interface |
| 109 | + test('custom provider is configured when WEB_URL_TEMPLATE is set', () => { |
| 110 | + process.env.WEB_URL_TEMPLATE = 'https://example.com/search?q={query}' |
| 111 | + const { customProvider } = require('./custom.js') |
| 112 | + expect(customProvider.isConfigured()).toBe(true) |
| 113 | + delete process.env.WEB_URL_TEMPLATE |
| 114 | + }) |
| 115 | + |
| 116 | + test('custom provider is NOT configured when no env vars are set', () => { |
| 117 | + delete process.env.WEB_URL_TEMPLATE |
| 118 | + delete process.env.WEB_SEARCH_API |
| 119 | + delete process.env.WEB_PROVIDER |
| 120 | + const { customProvider } = require('./custom.js') |
| 121 | + expect(customProvider.isConfigured()).toBe(false) |
| 122 | + }) |
| 123 | +}) |
0 commit comments