mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🧪 fix(ci): update failing initializeClient tests with new expected values (#1982)
* fix(ci): update failing tests with new expected values from `getUserKey` * refactor: safer optional chaining, and ensure apiKey is defined
This commit is contained in:
parent
2ea6e8c18a
commit
7a6a41a72e
5 changed files with 20 additions and 18 deletions
|
|
@ -60,8 +60,8 @@ const initializeClient = async ({ req, res, endpointOption }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let apiKey = userProvidesKey ? userValues.apiKey : CUSTOM_API_KEY;
|
let apiKey = userProvidesKey ? userValues?.apiKey : CUSTOM_API_KEY;
|
||||||
let baseURL = userProvidesURL ? userValues.baseURL : CUSTOM_BASE_URL;
|
let baseURL = userProvidesURL ? userValues?.baseURL : CUSTOM_BASE_URL;
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
throw new Error(`${endpoint} API key not provided.`);
|
throw new Error(`${endpoint} API key not provided.`);
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,8 @@ const initializeClient = async ({ req, res, endpointOption }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let apiKey = userProvidesKey ? userValues.apiKey : credentials[endpoint];
|
let apiKey = userProvidesKey ? userValues?.apiKey : credentials[endpoint];
|
||||||
let baseURL = userProvidesURL ? userValues.baseURL : baseURLOptions[endpoint];
|
let baseURL = userProvidesURL ? userValues?.baseURL : baseURLOptions[endpoint];
|
||||||
|
|
||||||
const clientOptions = {
|
const clientOptions = {
|
||||||
contextStrategy,
|
contextStrategy,
|
||||||
|
|
|
||||||
|
|
@ -340,9 +340,10 @@ describe('gptPlugins/initializeClient', () => {
|
||||||
test('should initialize client with default options when certain env vars are not set', async () => {
|
test('should initialize client with default options when certain env vars are not set', async () => {
|
||||||
delete process.env.DEBUG_OPENAI;
|
delete process.env.DEBUG_OPENAI;
|
||||||
delete process.env.OPENAI_SUMMARIZE;
|
delete process.env.OPENAI_SUMMARIZE;
|
||||||
|
process.env.OPENAI_API_KEY = 'some-api-key';
|
||||||
|
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: null, endpoint: 'openAI' },
|
body: { key: null, endpoint: EModelEndpoint.gptPlugins },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,8 @@ const initializeClient = async ({ req, res, endpointOption }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let apiKey = userProvidesKey ? userValues.apiKey : credentials[endpoint];
|
let apiKey = userProvidesKey ? userValues?.apiKey : credentials[endpoint];
|
||||||
let baseURL = userProvidesURL ? userValues.baseURL : baseURLOptions[endpoint];
|
let baseURL = userProvidesURL ? userValues?.baseURL : baseURLOptions[endpoint];
|
||||||
|
|
||||||
const clientOptions = {
|
const clientOptions = {
|
||||||
debug: isEnabled(DEBUG_OPENAI),
|
debug: isEnabled(DEBUG_OPENAI),
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ describe('initializeClient', () => {
|
||||||
process.env.OPENAI_SUMMARIZE = 'false';
|
process.env.OPENAI_SUMMARIZE = 'false';
|
||||||
|
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: null, endpoint: 'openAI' },
|
body: { key: null, endpoint: EModelEndpoint.openAI },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
@ -137,7 +137,7 @@ describe('initializeClient', () => {
|
||||||
process.env.DEBUG_OPENAI = 'true';
|
process.env.DEBUG_OPENAI = 'true';
|
||||||
|
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: null, endpoint: 'openAI' },
|
body: { key: null, endpoint: EModelEndpoint.openAI },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
@ -154,7 +154,7 @@ describe('initializeClient', () => {
|
||||||
process.env.OPENAI_SUMMARIZE = 'true';
|
process.env.OPENAI_SUMMARIZE = 'true';
|
||||||
|
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: null, endpoint: 'openAI' },
|
body: { key: null, endpoint: EModelEndpoint.openAI },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
@ -172,7 +172,7 @@ describe('initializeClient', () => {
|
||||||
process.env.PROXY = 'http://proxy';
|
process.env.PROXY = 'http://proxy';
|
||||||
|
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: null, endpoint: 'openAI' },
|
body: { key: null, endpoint: EModelEndpoint.openAI },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
@ -193,7 +193,7 @@ describe('initializeClient', () => {
|
||||||
|
|
||||||
const expiresAt = new Date(Date.now() - 10000).toISOString(); // Expired
|
const expiresAt = new Date(Date.now() - 10000).toISOString(); // Expired
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: expiresAt, endpoint: 'openAI' },
|
body: { key: expiresAt, endpoint: EModelEndpoint.openAI },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
@ -209,7 +209,7 @@ describe('initializeClient', () => {
|
||||||
delete process.env.AZURE_API_KEY;
|
delete process.env.AZURE_API_KEY;
|
||||||
|
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: null, endpoint: 'openAI' },
|
body: { key: null, endpoint: EModelEndpoint.openAI },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
@ -226,7 +226,7 @@ describe('initializeClient', () => {
|
||||||
const req = {
|
const req = {
|
||||||
body: {
|
body: {
|
||||||
key: new Date(Date.now() + 10000).toISOString(),
|
key: new Date(Date.now() + 10000).toISOString(),
|
||||||
endpoint: 'openAI',
|
endpoint: EModelEndpoint.openAI,
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
id: '123',
|
id: '123',
|
||||||
|
|
@ -253,7 +253,7 @@ describe('initializeClient', () => {
|
||||||
test('should throw an error if the user-provided key is invalid', async () => {
|
test('should throw an error if the user-provided key is invalid', async () => {
|
||||||
const invalidKey = new Date(Date.now() - 100000).toISOString();
|
const invalidKey = new Date(Date.now() - 100000).toISOString();
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: invalidKey, endpoint: 'openAI' },
|
body: { key: invalidKey, endpoint: EModelEndpoint.openAI },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
@ -272,7 +272,7 @@ describe('initializeClient', () => {
|
||||||
test('should throw an error when user-provided values are not valid JSON', async () => {
|
test('should throw an error when user-provided values are not valid JSON', async () => {
|
||||||
process.env.OPENAI_API_KEY = 'user_provided';
|
process.env.OPENAI_API_KEY = 'user_provided';
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: new Date(Date.now() + 10000).toISOString(), endpoint: 'openAI' },
|
body: { key: new Date(Date.now() + 10000).toISOString(), endpoint: EModelEndpoint.openAI },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
@ -315,9 +315,10 @@ describe('initializeClient', () => {
|
||||||
test('should initialize client with default options when certain env vars are not set', async () => {
|
test('should initialize client with default options when certain env vars are not set', async () => {
|
||||||
delete process.env.DEBUG_OPENAI;
|
delete process.env.DEBUG_OPENAI;
|
||||||
delete process.env.OPENAI_SUMMARIZE;
|
delete process.env.OPENAI_SUMMARIZE;
|
||||||
|
process.env.OPENAI_API_KEY = 'some-api-key';
|
||||||
|
|
||||||
const req = {
|
const req = {
|
||||||
body: { key: null, endpoint: 'openAI' },
|
body: { key: null, endpoint: EModelEndpoint.openAI },
|
||||||
user: { id: '123' },
|
user: { id: '123' },
|
||||||
app,
|
app,
|
||||||
};
|
};
|
||||||
|
|
@ -336,7 +337,7 @@ describe('initializeClient', () => {
|
||||||
const req = {
|
const req = {
|
||||||
body: {
|
body: {
|
||||||
key: new Date(Date.now() + 10000).toISOString(),
|
key: new Date(Date.now() + 10000).toISOString(),
|
||||||
endpoint: 'openAI',
|
endpoint: EModelEndpoint.openAI,
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
id: '123',
|
id: '123',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue