LibreChat/api/server/services/Config/loadDefaultEConfig.spec.js
Danny Avila cb23d6b993
🧯 fix: Suppress Google Service Key Noise (#13322)
* fix: suppress unused Google service key noise

* test: stabilize Google endpoint config mocks

* fix: normalize Google service key endpoint config
2026-05-26 15:33:38 -07:00

74 lines
2.1 KiB
JavaScript

const mockGetEnabledEndpoints = jest.fn();
const mockLoadAsyncEndpoints = jest.fn();
function mockOptionalModule(moduleName, factory) {
try {
require.resolve(moduleName);
jest.doMock(moduleName, factory);
} catch {
jest.doMock(moduleName, factory, { virtual: true });
}
}
function mockDependencies() {
mockOptionalModule('librechat-data-provider', () => ({
EModelEndpoint: {
agents: 'agents',
anthropic: 'anthropic',
assistants: 'assistants',
azureAssistants: 'azureAssistants',
azureOpenAI: 'azureOpenAI',
bedrock: 'bedrock',
google: 'google',
openAI: 'openAI',
},
getEnabledEndpoints: mockGetEnabledEndpoints,
}));
jest.doMock('./loadAsyncEndpoints', () => mockLoadAsyncEndpoints);
jest.doMock('./EndpointService', () => ({
config: {
agents: { userProvide: false },
anthropic: false,
assistants: false,
azureAssistants: false,
azureOpenAI: false,
bedrock: false,
openAI: { userProvide: false },
},
}));
}
describe('loadDefaultEndpointsConfig', () => {
beforeEach(() => {
jest.clearAllMocks();
jest.resetModules();
mockDependencies();
});
it('does not probe async Google credentials when Google is excluded from enabled endpoints', async () => {
mockGetEnabledEndpoints.mockReturnValue(['openAI']);
const loadDefaultEndpointsConfig = require('./loadDefaultEConfig');
const result = await loadDefaultEndpointsConfig();
expect(mockLoadAsyncEndpoints).not.toHaveBeenCalled();
expect(result).toEqual({
openAI: { userProvide: false, order: 0 },
});
});
it('loads async Google credentials when Google is enabled', async () => {
mockGetEnabledEndpoints.mockReturnValue(['google']);
mockLoadAsyncEndpoints.mockResolvedValue({ google: { userProvide: false } });
const loadDefaultEndpointsConfig = require('./loadDefaultEConfig');
const result = await loadDefaultEndpointsConfig();
expect(mockLoadAsyncEndpoints).toHaveBeenCalledTimes(1);
expect(result).toEqual({
google: { userProvide: false, order: 0 },
});
});
});