From 3eabbd572e30573097774720ef662be2faf0db65 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Sat, 18 May 2024 15:44:22 -0400 Subject: [PATCH] ci: fix backend tests due to new updates --- api/app/clients/OpenAIClient.js | 2 +- api/app/clients/specs/OpenAIClient.test.js | 1 + api/server/services/ActionService.spec.js | 6 +++--- api/server/services/AppService.spec.js | 4 ++-- .../azureAssistants/initializeClient.spec.js | 14 +++++++------- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/api/app/clients/OpenAIClient.js b/api/app/clients/OpenAIClient.js index 411aa47c61..f229087575 100644 --- a/api/app/clients/OpenAIClient.js +++ b/api/app/clients/OpenAIClient.js @@ -1014,7 +1014,7 @@ ${convo} context, model: this.modelOptions.model, conversationId: this.conversationId, - user: this.user ?? this.options.req.user.id, + user: this.user ?? this.options.req.user?.id, endpointTokenConfig: this.options.endpointTokenConfig, }, { promptTokens, completionTokens }, diff --git a/api/app/clients/specs/OpenAIClient.test.js b/api/app/clients/specs/OpenAIClient.test.js index 7ef4fdcae5..4590398419 100644 --- a/api/app/clients/specs/OpenAIClient.test.js +++ b/api/app/clients/specs/OpenAIClient.test.js @@ -144,6 +144,7 @@ describe('OpenAIClient', () => { const defaultOptions = { // debug: true, + req: {}, openaiApiKey: 'new-api-key', modelOptions: { model, diff --git a/api/server/services/ActionService.spec.js b/api/server/services/ActionService.spec.js index 57f9988961..a9650d6030 100644 --- a/api/server/services/ActionService.spec.js +++ b/api/server/services/ActionService.spec.js @@ -73,12 +73,12 @@ describe('domainParser', () => { const TLD = '.com'; // Non-azure request - it('returns domain as is if not azure', async () => { + it('does not return domain as is if not azure', async () => { const domain = `example.com${actionDomainSeparator}test${actionDomainSeparator}`; const result1 = await domainParser(reqNoAzure, domain, false); const result2 = await domainParser(reqNoAzure, domain, true); - expect(result1).toEqual(domain); - expect(result2).toEqual(domain); + expect(result1).not.toEqual(domain); + expect(result2).not.toEqual(domain); }); // Test for Empty or Null Inputs diff --git a/api/server/services/AppService.spec.js b/api/server/services/AppService.spec.js index e55bff9946..602ef43f83 100644 --- a/api/server/services/AppService.spec.js +++ b/api/server/services/AppService.spec.js @@ -253,8 +253,8 @@ describe('AppService', () => { process.env.EASTUS_API_KEY = 'eastus-key'; await AppService(app); - expect(app.locals).toHaveProperty(EModelEndpoint.assistants); - expect(app.locals[EModelEndpoint.assistants].capabilities.length).toEqual(3); + expect(app.locals).toHaveProperty(EModelEndpoint.azureAssistants); + expect(app.locals[EModelEndpoint.azureAssistants].capabilities.length).toEqual(3); }); it('should correctly configure Azure OpenAI endpoint based on custom config', async () => { diff --git a/api/server/services/Endpoints/azureAssistants/initializeClient.spec.js b/api/server/services/Endpoints/azureAssistants/initializeClient.spec.js index 3879fc0ffc..6dc4a6d47a 100644 --- a/api/server/services/Endpoints/azureAssistants/initializeClient.spec.js +++ b/api/server/services/Endpoints/azureAssistants/initializeClient.spec.js @@ -33,8 +33,8 @@ describe('initializeClient', () => { }); test('initializes OpenAI client with default API key and URL', async () => { - process.env.ASSISTANTS_API_KEY = 'default-api-key'; - process.env.ASSISTANTS_BASE_URL = 'https://default.api.url'; + process.env.AZURE_ASSISTANTS_API_KEY = 'default-api-key'; + process.env.AZURE_ASSISTANTS_BASE_URL = 'https://default.api.url'; // Assuming 'isUserProvided' to return false for this test case jest.mock('~/server/utils', () => ({ @@ -51,8 +51,8 @@ describe('initializeClient', () => { }); test('initializes OpenAI client with user-provided API key and URL', async () => { - process.env.ASSISTANTS_API_KEY = 'user_provided'; - process.env.ASSISTANTS_BASE_URL = 'user_provided'; + process.env.AZURE_ASSISTANTS_API_KEY = 'user_provided'; + process.env.AZURE_ASSISTANTS_BASE_URL = 'user_provided'; getUserKeyValues.mockResolvedValue({ apiKey: 'user-api-key', baseURL: 'https://user.api.url' }); getUserKeyExpiry.mockResolvedValue(isoString); @@ -67,7 +67,7 @@ describe('initializeClient', () => { }); test('throws error for invalid JSON in user-provided values', async () => { - process.env.ASSISTANTS_API_KEY = 'user_provided'; + process.env.AZURE_ASSISTANTS_API_KEY = 'user_provided'; getUserKey.mockResolvedValue('invalid-json'); getUserKeyExpiry.mockResolvedValue(isoString); getUserKeyValues.mockImplementation(() => { @@ -91,7 +91,7 @@ describe('initializeClient', () => { }); test('throws error if API key is not provided', async () => { - delete process.env.ASSISTANTS_API_KEY; // Simulate missing API key + delete process.env.AZURE_ASSISTANTS_API_KEY; // Simulate missing API key const req = { user: { id: 'user123' }, app }; const res = {}; @@ -100,7 +100,7 @@ describe('initializeClient', () => { }); test('initializes OpenAI client with proxy configuration', async () => { - process.env.ASSISTANTS_API_KEY = 'test-key'; + process.env.AZURE_ASSISTANTS_API_KEY = 'test-key'; process.env.PROXY = 'http://proxy.server'; const req = { user: { id: 'user123' }, app };