mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 08:20:14 +01:00
* 🧹 chore: Update logger imports to use @librechat/data-schemas across multiple files and remove unused sleep function from queue.js (#9930) * chore: Replace local isEnabled utility with @librechat/api import across multiple files, update test files * chore: Replace local logger import with @librechat/data-schemas logger in countTokens.js and fork.js * chore: Update logs volume path in docker-compose.yml to correct directory * chore: import order of isEnabled in static.js
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
const express = require('express');
|
|
const request = require('supertest');
|
|
const { isEnabled } = require('@librechat/api');
|
|
const { getLdapConfig } = require('~/server/services/Config/ldap');
|
|
|
|
jest.mock('~/server/services/Config/ldap');
|
|
jest.mock('@librechat/api', () => ({
|
|
...jest.requireActual('@librechat/api'),
|
|
isEnabled: jest.fn(),
|
|
}));
|
|
|
|
const app = express();
|
|
|
|
// Mock the route handler
|
|
app.get('/api/config', (req, res) => {
|
|
const ldapConfig = getLdapConfig();
|
|
res.json({ ldap: ldapConfig });
|
|
});
|
|
|
|
describe('LDAP Config Tests', () => {
|
|
afterEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('should return LDAP config with username property when LDAP_LOGIN_USES_USERNAME is enabled', async () => {
|
|
getLdapConfig.mockReturnValue({ enabled: true, username: true });
|
|
isEnabled.mockReturnValue(true);
|
|
|
|
const response = await request(app).get('/api/config');
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.ldap).toEqual({
|
|
enabled: true,
|
|
username: true,
|
|
});
|
|
});
|
|
|
|
it('should return LDAP config without username property when LDAP_LOGIN_USES_USERNAME is not enabled', async () => {
|
|
getLdapConfig.mockReturnValue({ enabled: true });
|
|
isEnabled.mockReturnValue(false);
|
|
|
|
const response = await request(app).get('/api/config');
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.ldap).toEqual({
|
|
enabled: true,
|
|
});
|
|
});
|
|
|
|
it('should not return LDAP config when LDAP is not enabled', async () => {
|
|
getLdapConfig.mockReturnValue(undefined);
|
|
|
|
const response = await request(app).get('/api/config');
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.ldap).toBeUndefined();
|
|
});
|
|
});
|