From f30d6bd689e2b30ad85275d01f3b45e4f570a957 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Mon, 5 Feb 2024 11:26:12 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix:=20socialLogins=20default=20?= =?UTF-8?q?value=20(#1730)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: socialLogins default value * ci: add test for `AppService` --- api/server/services/AppService.js | 2 +- api/server/services/AppService.spec.js | 51 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 api/server/services/AppService.spec.js diff --git a/api/server/services/AppService.js b/api/server/services/AppService.js index 63c136704f..b62d274d53 100644 --- a/api/server/services/AppService.js +++ b/api/server/services/AppService.js @@ -12,7 +12,7 @@ const paths = require('~/config/paths'); const AppService = async (app) => { /** @type {TCustomConfig}*/ const config = (await loadCustomConfig()) ?? {}; - const socialLogins = config.registration.socialLogins ?? [ + const socialLogins = config?.registration?.socialLogins ?? [ 'google', 'facebook', 'openid', diff --git a/api/server/services/AppService.spec.js b/api/server/services/AppService.spec.js new file mode 100644 index 0000000000..1f3f2245be --- /dev/null +++ b/api/server/services/AppService.spec.js @@ -0,0 +1,51 @@ +const { FileSources } = require('librechat-data-provider'); + +const AppService = require('./AppService'); + +jest.mock('./Config/loadCustomConfig', () => { + return jest.fn(() => + Promise.resolve({ + registration: { socialLogins: ['testLogin'] }, + fileStrategy: 'testStrategy', + }), + ); +}); +jest.mock('./Files/Firebase/initialize', () => ({ + initializeFirebase: jest.fn(), +})); + +describe('AppService', () => { + let app; + + beforeEach(() => { + app = { locals: {} }; + process.env.CDN_PROVIDER = undefined; + }); + + it('should correctly assign process.env and app.locals based on custom config', async () => { + await AppService(app); + + expect(process.env.CDN_PROVIDER).toEqual('testStrategy'); + + expect(app.locals).toEqual({ + socialLogins: ['testLogin'], + fileStrategy: 'testStrategy', + paths: expect.anything(), + }); + }); + + it('should initialize Firebase when fileStrategy is firebase', async () => { + require('./Config/loadCustomConfig').mockImplementationOnce(() => + Promise.resolve({ + fileStrategy: FileSources.firebase, + }), + ); + + await AppService(app); + + const { initializeFirebase } = require('./Files/Firebase/initialize'); + expect(initializeFirebase).toHaveBeenCalled(); + + expect(process.env.CDN_PROVIDER).toEqual(FileSources.firebase); + }); +});