mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
🔃 refactor: rename all server endpoints to use same file names (#4364)
This commit is contained in:
parent
f3e2bd0a12
commit
20fb7f05ae
31 changed files with 26 additions and 26 deletions
81
api/server/services/Endpoints/google/initialize.spec.js
Normal file
81
api/server/services/Endpoints/google/initialize.spec.js
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
// file deepcode ignore HardcodedNonCryptoSecret: No hardcoded secrets
|
||||
const { getUserKey } = require('~/server/services/UserService');
|
||||
const initializeClient = require('./initialize');
|
||||
const { GoogleClient } = require('~/app');
|
||||
|
||||
jest.mock('~/server/services/UserService', () => ({
|
||||
checkUserKeyExpiry: jest.requireActual('~/server/services/UserService').checkUserKeyExpiry,
|
||||
getUserKey: jest.fn().mockImplementation(() => ({})),
|
||||
}));
|
||||
|
||||
const app = { locals: {} };
|
||||
|
||||
describe('google/initializeClient', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
test('should initialize GoogleClient with user-provided credentials', async () => {
|
||||
process.env.GOOGLE_KEY = 'user_provided';
|
||||
process.env.GOOGLE_REVERSE_PROXY = 'http://reverse.proxy';
|
||||
process.env.PROXY = 'http://proxy';
|
||||
|
||||
const expiresAt = new Date(Date.now() + 60000).toISOString();
|
||||
|
||||
const req = {
|
||||
body: { key: expiresAt },
|
||||
user: { id: '123' },
|
||||
app,
|
||||
};
|
||||
const res = {};
|
||||
const endpointOption = { modelOptions: { model: 'default-model' } };
|
||||
|
||||
const { client, credentials } = await initializeClient({ req, res, endpointOption });
|
||||
|
||||
expect(getUserKey).toHaveBeenCalledWith({ userId: '123', name: 'google' });
|
||||
expect(client).toBeInstanceOf(GoogleClient);
|
||||
expect(client.options.reverseProxyUrl).toBe('http://reverse.proxy');
|
||||
expect(client.options.proxy).toBe('http://proxy');
|
||||
expect(credentials).toEqual({});
|
||||
});
|
||||
|
||||
test('should initialize GoogleClient with service key credentials', async () => {
|
||||
process.env.GOOGLE_KEY = 'service_key';
|
||||
process.env.GOOGLE_REVERSE_PROXY = 'http://reverse.proxy';
|
||||
process.env.PROXY = 'http://proxy';
|
||||
|
||||
const req = {
|
||||
body: { key: null },
|
||||
user: { id: '123' },
|
||||
app,
|
||||
};
|
||||
const res = {};
|
||||
const endpointOption = { modelOptions: { model: 'default-model' } };
|
||||
|
||||
const { client, credentials } = await initializeClient({ req, res, endpointOption });
|
||||
|
||||
expect(client).toBeInstanceOf(GoogleClient);
|
||||
expect(client.options.reverseProxyUrl).toBe('http://reverse.proxy');
|
||||
expect(client.options.proxy).toBe('http://proxy');
|
||||
expect(credentials).toEqual({
|
||||
GOOGLE_SERVICE_KEY: {},
|
||||
GOOGLE_API_KEY: 'service_key',
|
||||
});
|
||||
});
|
||||
|
||||
test('should handle expired user-provided key', async () => {
|
||||
process.env.GOOGLE_KEY = 'user_provided';
|
||||
|
||||
const expiresAt = new Date(Date.now() - 10000).toISOString(); // Expired
|
||||
const req = {
|
||||
body: { key: expiresAt },
|
||||
user: { id: '123' },
|
||||
app,
|
||||
};
|
||||
const res = {};
|
||||
const endpointOption = { modelOptions: { model: 'default-model' } };
|
||||
await expect(initializeClient({ req, res, endpointOption })).rejects.toThrow(
|
||||
/expired_user_key/,
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue