| | import { webSearchAuth } from '@librechat/data-schemas'; |
| | import { SafeSearchTypes, AuthType } from 'librechat-data-provider'; |
| | import type { |
| | ScraperProviders, |
| | TWebSearchConfig, |
| | SearchProviders, |
| | TCustomConfig, |
| | RerankerTypes, |
| | } from 'librechat-data-provider'; |
| | import { loadWebSearchAuth, extractWebSearchEnvVars } from './web'; |
| |
|
| | |
| | jest.mock('../utils', () => ({ |
| | extractVariableName: (value: string) => { |
| | if (!value || typeof value !== 'string') return null; |
| | const match = value.match(/^\${(.+)}$/); |
| | return match ? match[1] : null; |
| | }, |
| | })); |
| |
|
| | describe('web.ts', () => { |
| | describe('extractWebSearchEnvVars', () => { |
| | it('should return empty array if config is undefined', () => { |
| | const result = extractWebSearchEnvVars({ |
| | keys: ['serperApiKey', 'jinaApiKey'], |
| | config: undefined, |
| | }); |
| |
|
| | expect(result).toEqual([]); |
| | }); |
| |
|
| | it('should extract environment variable names from config values', () => { |
| | const config: Partial<TWebSearchConfig> = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | cohereApiKey: 'actual-api-key', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | }; |
| |
|
| | const result = extractWebSearchEnvVars({ |
| | keys: ['serperApiKey', 'jinaApiKey', 'cohereApiKey'], |
| | config: config as TWebSearchConfig, |
| | }); |
| |
|
| | expect(result).toEqual(['SERPER_API_KEY', 'JINA_API_KEY']); |
| | }); |
| |
|
| | it('should only extract variables for keys that exist in the config', () => { |
| | const config: Partial<TWebSearchConfig> = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | }; |
| |
|
| | const result = extractWebSearchEnvVars({ |
| | keys: ['serperApiKey', 'firecrawlApiKey'], |
| | config: config as TWebSearchConfig, |
| | }); |
| |
|
| | expect(result).toEqual(['SERPER_API_KEY']); |
| | }); |
| | }); |
| |
|
| | describe('loadWebSearchAuth', () => { |
| | |
| | const userId = 'test-user-id'; |
| | let mockLoadAuthValues: jest.Mock; |
| | let webSearchConfig: TCustomConfig['webSearch']; |
| |
|
| | beforeEach(() => { |
| | |
| | jest.clearAllMocks(); |
| |
|
| | |
| | mockLoadAuthValues = jest.fn(); |
| |
|
| | |
| | webSearchConfig = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | }; |
| | }); |
| |
|
| | it('should return authenticated=true when all required categories are authenticated', async () => { |
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authTypes).toHaveLength(3); |
| | expect(result.authResult).toHaveProperty('serperApiKey', 'test-api-key'); |
| | expect(result.authResult).toHaveProperty('firecrawlApiKey', 'test-api-key'); |
| |
|
| | |
| | |
| | if (result.authResult.rerankerType === 'jina') { |
| | expect(result.authResult).toHaveProperty('jinaApiKey', 'test-api-key'); |
| | } else { |
| | expect(result.authResult).toHaveProperty('cohereApiKey', 'test-api-key'); |
| | } |
| |
|
| | expect(result.authResult).toHaveProperty('searchProvider', 'serper'); |
| | expect(result.authResult).toHaveProperty('scraperProvider', 'firecrawl'); |
| | expect(['jina', 'cohere']).toContain(result.authResult.rerankerType as string); |
| | }); |
| |
|
| | it('should return authenticated=false when a required category is not authenticated', async () => { |
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | |
| | if (field !== 'SERPER_API_KEY' && field !== 'SEARXNG_INSTANCE_URL') { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | } |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(false); |
| | |
| | expect(result.authTypes.some(([category]) => category === 'providers')).toBe(true); |
| | }); |
| |
|
| | it('should handle exceptions from loadAuthValues', async () => { |
| | |
| | mockLoadAuthValues.mockImplementation(() => { |
| | throw new Error('Authentication failed'); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | throwError: false, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(false); |
| | }); |
| |
|
| | it('should correctly identify user-provided vs system-defined auth', async () => { |
| | |
| | const originalEnv = process.env; |
| | process.env = { |
| | ...originalEnv, |
| | SERPER_API_KEY: 'system-api-key', |
| | FIRECRAWL_API_KEY: 'system-api-key', |
| | JINA_API_KEY: 'system-api-key', |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | if (field === 'SERPER_API_KEY') { |
| | |
| | result[field] = 'system-api-key'; |
| | } else if (field === 'FIRECRAWL_API_KEY') { |
| | |
| | result[field] = 'user-api-key'; |
| | } else if (field === 'FIRECRAWL_API_URL') { |
| | result[field] = 'https://api.firecrawl.dev'; |
| | } else if (field === 'JINA_API_KEY') { |
| | |
| | result[field] = 'system-api-key'; |
| | } else { |
| | result[field] = 'test-api-key'; |
| | } |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | |
| | const providersAuthType = result.authTypes.find( |
| | ([category]) => category === 'providers', |
| | )?.[1]; |
| | const scrapersAuthType = result.authTypes.find(([category]) => category === 'scrapers')?.[1]; |
| |
|
| | expect(providersAuthType).toBe(AuthType.SYSTEM_DEFINED); |
| | expect(scrapersAuthType).toBe(AuthType.USER_PROVIDED); |
| |
|
| | |
| | process.env = originalEnv; |
| | }); |
| |
|
| | it('should handle optional fields correctly', async () => { |
| | |
| | const configWithoutOptional = { ...webSearchConfig } as Partial<TWebSearchConfig>; |
| | delete configWithoutOptional.firecrawlApiUrl; |
| |
|
| | mockLoadAuthValues.mockImplementation(({ authFields, optional }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | |
| | if (!optional?.has(field)) { |
| | result[field] = 'test-api-key'; |
| | } |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig: configWithoutOptional as TWebSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult).toHaveProperty('firecrawlApiKey', 'test-api-key'); |
| | |
| | expect(result.authResult.firecrawlApiUrl).toBeUndefined(); |
| | }); |
| |
|
| | it('should preserve safeSearch setting from webSearchConfig', async () => { |
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | |
| | const configWithSafeSearchOff = { |
| | ...webSearchConfig, |
| | safeSearch: SafeSearchTypes.OFF, |
| | } as TWebSearchConfig; |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig: configWithSafeSearchOff, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authResult).toHaveProperty('safeSearch', SafeSearchTypes.OFF); |
| | }); |
| |
|
| | it('should set the correct service types in authResult', async () => { |
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | |
| | expect(result.authResult.searchProvider).toBe('serper' as SearchProviders); |
| | expect(result.authResult.scraperProvider).toBe('firecrawl' as ScraperProviders); |
| | |
| | expect(['jina', 'cohere']).toContain(result.authResult.rerankerType as string); |
| | }); |
| |
|
| | it('should check all services if none are specified', async () => { |
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| |
|
| | |
| | expect(result.authTypes).toHaveLength(3); |
| |
|
| | |
| | expect(result.authResult.searchProvider).toBeDefined(); |
| | expect(result.authResult.scraperProvider).toBeDefined(); |
| | expect(result.authResult.rerankerType).toBeDefined(); |
| | }); |
| |
|
| | it('should correctly identify authTypes based on specific configurations', async () => { |
| | |
| | const originalEnv = process.env; |
| | process.env = { |
| | ...originalEnv, |
| | SERPER_API_KEY: 'system-serper-key', |
| | FIRECRAWL_API_KEY: 'system-firecrawl-key', |
| | FIRECRAWL_API_URL: 'https://api.firecrawl.dev', |
| | JINA_API_KEY: 'system-jina-key', |
| | COHERE_API_KEY: 'system-cohere-key', |
| | }; |
| |
|
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | |
| | searchProvider: 'serper' as SearchProviders, |
| | scraperProvider: 'firecrawl' as ScraperProviders, |
| | rerankerType: 'jina' as RerankerTypes, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | if (field === 'SERPER_API_KEY') { |
| | result[field] = 'system-serper-key'; |
| | } else if (field === 'FIRECRAWL_API_KEY') { |
| | result[field] = 'system-firecrawl-key'; |
| | } else if (field === 'FIRECRAWL_API_URL') { |
| | result[field] = 'https://api.firecrawl.dev'; |
| | } else if (field === 'JINA_API_KEY') { |
| | result[field] = 'system-jina-key'; |
| | } else if (field === 'COHERE_API_KEY') { |
| | result[field] = 'system-cohere-key'; |
| | } |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | |
| | expect(result.authResult).toHaveProperty('serperApiKey'); |
| | expect(result.authResult).toHaveProperty('firecrawlApiKey'); |
| | expect(result.authResult).toHaveProperty('firecrawlApiUrl'); |
| | expect(result.authResult).toHaveProperty('jinaApiKey'); |
| | expect(result.authResult).toHaveProperty('searchProvider'); |
| | expect(result.authResult).toHaveProperty('scraperProvider'); |
| | expect(result.authResult).toHaveProperty('rerankerType'); |
| |
|
| | expect(result.authenticated).toBe(true); |
| |
|
| | |
| | const providersAuthType = result.authTypes.find( |
| | ([category]) => category === 'providers', |
| | )?.[1]; |
| | const scrapersAuthType = result.authTypes.find(([category]) => category === 'scrapers')?.[1]; |
| | const rerankersAuthType = result.authTypes.find( |
| | ([category]) => category === 'rerankers', |
| | )?.[1]; |
| |
|
| | |
| | expect(providersAuthType).toBe(AuthType.SYSTEM_DEFINED); |
| | expect(scrapersAuthType).toBe(AuthType.SYSTEM_DEFINED); |
| | expect(rerankersAuthType).toBe(AuthType.SYSTEM_DEFINED); |
| |
|
| | |
| | expect(result.authResult).toHaveProperty('serperApiKey', 'system-serper-key'); |
| | expect(result.authResult).toHaveProperty('firecrawlApiKey', 'system-firecrawl-key'); |
| | expect(result.authResult).toHaveProperty('firecrawlApiUrl', 'https://api.firecrawl.dev'); |
| | expect(result.authResult).toHaveProperty('jinaApiKey', 'system-jina-key'); |
| | expect(result.authResult).toHaveProperty('searchProvider', 'serper'); |
| | expect(result.authResult).toHaveProperty('scraperProvider', 'firecrawl'); |
| | expect(result.authResult).toHaveProperty('rerankerType', 'jina'); |
| |
|
| | |
| | process.env = originalEnv; |
| | }); |
| |
|
| | it('should handle custom variable names in environment variables', async () => { |
| | |
| | const originalEnv = process.env; |
| | process.env = { |
| | ...originalEnv, |
| | CUSTOM_SERPER_KEY: 'custom-serper-key', |
| | CUSTOM_FIRECRAWL_KEY: 'custom-firecrawl-key', |
| | CUSTOM_FIRECRAWL_URL: 'https://custom.firecrawl.dev', |
| | CUSTOM_JINA_KEY: 'custom-jina-key', |
| | CUSTOM_COHERE_KEY: 'custom-cohere-key', |
| | CUSTOM_JINA_URL: 'https://custom.jina.ai', |
| | }; |
| |
|
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${CUSTOM_SERPER_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${CUSTOM_FIRECRAWL_KEY}', |
| | firecrawlApiUrl: '${CUSTOM_FIRECRAWL_URL}', |
| | jinaApiKey: '${CUSTOM_JINA_KEY}', |
| | jinaApiUrl: '${CUSTOM_JINA_URL}', |
| | cohereApiKey: '${CUSTOM_COHERE_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | |
| | searchProvider: 'serper' as SearchProviders, |
| | scraperProvider: 'firecrawl' as ScraperProviders, |
| | rerankerType: 'jina' as RerankerTypes, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | if (field === 'CUSTOM_SERPER_KEY') { |
| | result[field] = 'custom-serper-key'; |
| | } else if (field === 'CUSTOM_FIRECRAWL_KEY') { |
| | result[field] = 'custom-firecrawl-key'; |
| | } else if (field === 'CUSTOM_FIRECRAWL_URL') { |
| | result[field] = 'https://custom.firecrawl.dev'; |
| | } else if (field === 'CUSTOM_JINA_KEY') { |
| | result[field] = 'custom-jina-key'; |
| | } |
| | |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| |
|
| | |
| | expect(result.authResult).toHaveProperty('serperApiKey', 'custom-serper-key'); |
| | expect(result.authResult).toHaveProperty('firecrawlApiKey', 'custom-firecrawl-key'); |
| | expect(result.authResult).toHaveProperty('firecrawlApiUrl', 'https://custom.firecrawl.dev'); |
| | expect(result.authResult).toHaveProperty('jinaApiKey', 'custom-jina-key'); |
| | |
| | expect(result.authResult).not.toHaveProperty('cohereApiKey'); |
| |
|
| | |
| | expect(result.authResult).toHaveProperty('searchProvider', 'serper'); |
| | expect(result.authResult).toHaveProperty('scraperProvider', 'firecrawl'); |
| | expect(result.authResult).toHaveProperty('rerankerType', 'jina'); |
| |
|
| | |
| | process.env = originalEnv; |
| | }); |
| |
|
| | it('should always return authTypes array with exactly 3 categories', async () => { |
| | |
| | const originalEnv = process.env; |
| | process.env = { |
| | ...originalEnv, |
| | SERPER_API_KEY: 'test-key', |
| | FIRECRAWL_API_KEY: 'test-key', |
| | FIRECRAWL_API_URL: 'https://api.firecrawl.dev', |
| | JINA_API_KEY: 'test-key', |
| | }; |
| |
|
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | |
| | const expectedCategoryCount = Object.keys(webSearchAuth).length; |
| |
|
| | |
| | expect(result.authTypes).toHaveLength(expectedCategoryCount); |
| |
|
| | |
| | const categories = result.authTypes.map(([category]) => category); |
| | Object.keys(webSearchAuth).forEach((category) => { |
| | expect(categories).toContain(category); |
| | }); |
| |
|
| | |
| | expect(new Set(categories).size).toBe(expectedCategoryCount); |
| |
|
| | |
| | result.authTypes.forEach(([category, authType]) => { |
| | expect(typeof category).toBe('string'); |
| | expect([AuthType.SYSTEM_DEFINED, AuthType.USER_PROVIDED]).toContain(authType); |
| | }); |
| |
|
| | |
| | process.env = originalEnv; |
| | }); |
| |
|
| | it('should maintain authTypes array structure even when authentication fails', async () => { |
| | |
| | const originalEnv = process.env; |
| | process.env = { |
| | ...originalEnv, |
| | SERPER_API_KEY: 'test-key', |
| | |
| | }; |
| |
|
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | if (field === 'SERPER_API_KEY') { |
| | result[field] = 'test-key'; |
| | } |
| | |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | |
| | const expectedCategoryCount = Object.keys(webSearchAuth).length; |
| |
|
| | |
| | expect(result.authenticated).toBe(false); |
| |
|
| | |
| | expect(result.authTypes).toHaveLength(expectedCategoryCount); |
| |
|
| | |
| | const categories = result.authTypes.map(([category]) => category); |
| | Object.keys(webSearchAuth).forEach((category) => { |
| | expect(categories).toContain(category); |
| | }); |
| |
|
| | |
| | expect(new Set(categories).size).toBe(expectedCategoryCount); |
| |
|
| | |
| | result.authTypes.forEach(([category, authType]) => { |
| | expect(typeof category).toBe('string'); |
| | expect([AuthType.SYSTEM_DEFINED, AuthType.USER_PROVIDED]).toContain(authType); |
| | }); |
| |
|
| | |
| | process.env = originalEnv; |
| | }); |
| | }); |
| |
|
| | describe('webSearchAuth', () => { |
| | it('should have the expected structure', () => { |
| | |
| | expect(webSearchAuth).toHaveProperty('providers'); |
| | expect(webSearchAuth).toHaveProperty('scrapers'); |
| | expect(webSearchAuth).toHaveProperty('rerankers'); |
| |
|
| | |
| | expect(webSearchAuth.providers).toHaveProperty('serper'); |
| | expect(webSearchAuth.providers.serper).toHaveProperty('serperApiKey', 1); |
| |
|
| | |
| | expect(webSearchAuth.scrapers).toHaveProperty('firecrawl'); |
| | expect(webSearchAuth.scrapers.firecrawl).toHaveProperty('firecrawlApiKey', 1); |
| | expect(webSearchAuth.scrapers.firecrawl).toHaveProperty('firecrawlApiUrl', 0); |
| |
|
| | |
| | expect(webSearchAuth.rerankers).toHaveProperty('jina'); |
| | expect(webSearchAuth.rerankers.jina).toHaveProperty('jinaApiKey', 1); |
| | expect(webSearchAuth.rerankers).toHaveProperty('cohere'); |
| | expect(webSearchAuth.rerankers.cohere).toHaveProperty('cohereApiKey', 1); |
| | }); |
| |
|
| | it('should mark required keys with value 1', () => { |
| | |
| | expect(webSearchAuth.providers.serper.serperApiKey).toBe(1); |
| | expect(webSearchAuth.scrapers.firecrawl.firecrawlApiKey).toBe(1); |
| | expect(webSearchAuth.rerankers.jina.jinaApiKey).toBe(1); |
| | expect(webSearchAuth.rerankers.cohere.cohereApiKey).toBe(1); |
| | }); |
| |
|
| | it('should mark optional keys with value 0', () => { |
| | |
| | expect(webSearchAuth.scrapers.firecrawl.firecrawlApiUrl).toBe(0); |
| | }); |
| | }); |
| | describe('loadWebSearchAuth with specific services', () => { |
| | |
| | const userId = 'test-user-id'; |
| | let mockLoadAuthValues: jest.Mock; |
| |
|
| | beforeEach(() => { |
| | |
| | jest.clearAllMocks(); |
| |
|
| | |
| | mockLoadAuthValues = jest.fn(); |
| | }); |
| |
|
| | it('should only check the specified searchProvider', async () => { |
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | searchProvider: 'serper' as SearchProviders, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.searchProvider).toBe('serper'); |
| |
|
| | |
| | const providerCalls = mockLoadAuthValues.mock.calls.filter((call) => |
| | call[0].authFields.includes('SERPER_API_KEY'), |
| | ); |
| | expect(providerCalls.length).toBe(1); |
| | }); |
| |
|
| | it('should only check the specified scraperProvider', async () => { |
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | scraperProvider: 'firecrawl' as ScraperProviders, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.scraperProvider).toBe('firecrawl'); |
| |
|
| | |
| | const scraperCalls = mockLoadAuthValues.mock.calls.filter((call) => |
| | call[0].authFields.includes('FIRECRAWL_API_KEY'), |
| | ); |
| | expect(scraperCalls.length).toBe(1); |
| | }); |
| |
|
| | it('should only check the specified rerankerType', async () => { |
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | rerankerType: 'jina' as RerankerTypes, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.rerankerType).toBe('jina'); |
| |
|
| | |
| | const rerankerCalls = mockLoadAuthValues.mock.calls.filter((call) => |
| | call[0].authFields.includes('JINA_API_KEY'), |
| | ); |
| | expect(rerankerCalls.length).toBe(1); |
| |
|
| | |
| | const cohereCalls = mockLoadAuthValues.mock.calls.filter((call) => |
| | call[0].authFields.includes('COHERE_API_KEY'), |
| | ); |
| | expect(cohereCalls.length).toBe(0); |
| | }); |
| |
|
| | it('should handle invalid specified service gracefully', async () => { |
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | searchProvider: 'invalid-provider' as SearchProviders, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | |
| | expect(result.authenticated).toBe(false); |
| | }); |
| |
|
| | it('should fail authentication when specified service is not authenticated but others are', async () => { |
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | rerankerType: 'jina' as RerankerTypes, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | |
| | if (field !== 'JINA_API_KEY') { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | } |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | |
| | |
| | expect(result.authenticated).toBe(false); |
| |
|
| | |
| | const jinaApiKeyCalls = mockLoadAuthValues.mock.calls.filter((call) => |
| | call[0].authFields.includes('JINA_API_KEY'), |
| | ); |
| | expect(jinaApiKeyCalls.length).toBe(1); |
| |
|
| | |
| | const cohereApiKeyCalls = mockLoadAuthValues.mock.calls.filter((call) => |
| | call[0].authFields.includes('COHERE_API_KEY'), |
| | ); |
| | expect(cohereApiKeyCalls.length).toBe(0); |
| | }); |
| |
|
| | it('should check all services if none are specified', async () => { |
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| |
|
| | |
| | expect(result.authTypes).toHaveLength(3); |
| |
|
| | |
| | expect(result.authResult.searchProvider).toBeDefined(); |
| | expect(result.authResult.scraperProvider).toBeDefined(); |
| | expect(result.authResult.rerankerType).toBeDefined(); |
| | }); |
| |
|
| | it('should handle firecrawlOptions properties', async () => { |
| | |
| | const webSearchConfig: TCustomConfig['webSearch'] = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | searxngInstanceUrl: '${SEARXNG_INSTANCE_URL}', |
| | searxngApiKey: '${SEARXNG_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | cohereApiKey: '${COHERE_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | firecrawlOptions: { |
| | formats: ['markdown', 'html'], |
| | includeTags: ['img', 'p', 'h1'], |
| | excludeTags: ['script', 'style'], |
| | headers: { 'User-Agent': 'TestBot' }, |
| | waitFor: 2000, |
| | timeout: 15000, |
| | maxAge: 3600, |
| | mobile: true, |
| | skipTlsVerification: false, |
| | blockAds: true, |
| | removeBase64Images: false, |
| | parsePDF: true, |
| | storeInCache: false, |
| | zeroDataRetention: true, |
| | location: { |
| | country: 'US', |
| | languages: ['en'], |
| | }, |
| | onlyMainContent: true, |
| | changeTrackingOptions: { |
| | modes: ['diff'], |
| | schema: { title: 'string' }, |
| | prompt: 'Track changes', |
| | tag: 'test-tag', |
| | }, |
| | }, |
| | }; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.firecrawlOptions).toEqual(webSearchConfig.firecrawlOptions); |
| | expect(result.authResult.scraperTimeout).toBe(15000); |
| | }); |
| |
|
| | it('should use scraperTimeout when both scraperTimeout and firecrawlOptions.timeout are provided', async () => { |
| | |
| | const webSearchConfig = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | scraperTimeout: 15000, |
| | firecrawlOptions: { |
| | timeout: 10000, |
| | includeTags: ['p'], |
| | formats: ['markdown'], |
| | }, |
| | } as TCustomConfig['webSearch']; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.scraperTimeout).toBe(15000); |
| | expect(result.authResult.firecrawlOptions).toEqual({ |
| | timeout: 10000, |
| | includeTags: ['p'], |
| | formats: ['markdown'], |
| | }); |
| | }); |
| |
|
| | it('should fallback to default timeout when neither scraperTimeout nor firecrawlOptions.timeout are provided', async () => { |
| | |
| | const webSearchConfig = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | firecrawlOptions: { |
| | includeTags: ['p'], |
| | formats: ['markdown'], |
| | }, |
| | } as TCustomConfig['webSearch']; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.scraperTimeout).toBe(7500); |
| | expect(result.authResult.firecrawlOptions).toEqual({ |
| | includeTags: ['p'], |
| | formats: ['markdown'], |
| | }); |
| | }); |
| |
|
| | it('should use firecrawlOptions.timeout when only firecrawlOptions.timeout is provided', async () => { |
| | |
| | const webSearchConfig = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | firecrawlOptions: { |
| | timeout: 12000, |
| | }, |
| | } as TCustomConfig['webSearch']; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.scraperTimeout).toBe(12000); |
| | expect(result.authResult.firecrawlOptions).toEqual({ |
| | timeout: 12000, |
| | }); |
| | }); |
| |
|
| | it('should handle firecrawlOptions.formats when only formats is provided', async () => { |
| | |
| | const webSearchConfig = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | firecrawlOptions: { |
| | formats: ['html', 'markdown'], |
| | }, |
| | } as TCustomConfig['webSearch']; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.scraperTimeout).toBe(7500); |
| | expect(result.authResult.firecrawlOptions).toEqual({ |
| | formats: ['html', 'markdown'], |
| | }); |
| | }); |
| |
|
| | it('should handle firecrawlOptions without formats property', async () => { |
| | |
| | const webSearchConfig = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | jinaApiUrl: '${JINA_API_URL}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | firecrawlOptions: { |
| | timeout: 8000, |
| | includeTags: ['p', 'h1'], |
| | |
| | }, |
| | } as TCustomConfig['webSearch']; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.scraperTimeout).toBe(8000); |
| | expect(result.authResult.firecrawlOptions).toEqual({ |
| | timeout: 8000, |
| | includeTags: ['p', 'h1'], |
| | |
| | }); |
| | }); |
| |
|
| | it('should handle webSearchConfig without firecrawlOptions at all', async () => { |
| | |
| | const webSearchConfig = { |
| | serperApiKey: '${SERPER_API_KEY}', |
| | firecrawlApiKey: '${FIRECRAWL_API_KEY}', |
| | firecrawlApiUrl: '${FIRECRAWL_API_URL}', |
| | jinaApiKey: '${JINA_API_KEY}', |
| | safeSearch: SafeSearchTypes.MODERATE, |
| | |
| | } as TCustomConfig['webSearch']; |
| |
|
| | |
| | mockLoadAuthValues.mockImplementation(({ authFields }) => { |
| | const result: Record<string, string> = {}; |
| | authFields.forEach((field: string) => { |
| | result[field] = |
| | field === 'FIRECRAWL_API_URL' ? 'https://api.firecrawl.dev' : 'test-api-key'; |
| | }); |
| | return Promise.resolve(result); |
| | }); |
| |
|
| | const result = await loadWebSearchAuth({ |
| | userId, |
| | webSearchConfig, |
| | loadAuthValues: mockLoadAuthValues, |
| | }); |
| |
|
| | expect(result.authenticated).toBe(true); |
| | expect(result.authResult.scraperTimeout).toBe(7500); |
| | expect(result.authResult.firecrawlOptions).toBeUndefined(); |
| | }); |
| | }); |
| | }); |
| |
|