2025-08-26 12:10:18 -04:00
|
|
|
jest.mock('@librechat/data-schemas', () => ({
|
2024-08-21 19:57:34 -04:00
|
|
|
logger: {
|
|
|
|
info: jest.fn(),
|
|
|
|
warn: jest.fn(),
|
|
|
|
error: jest.fn(),
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
jest.mock('@librechat/api', () => ({
|
|
|
|
...jest.requireActual('@librechat/api'),
|
2024-08-21 19:57:34 -04:00
|
|
|
loadDefaultInterface: jest.fn(),
|
|
|
|
}));
|
2025-08-26 12:10:18 -04:00
|
|
|
jest.mock('./start/tools', () => ({
|
2024-08-21 19:57:34 -04:00
|
|
|
loadAndFormatTools: jest.fn().mockReturnValue({}),
|
|
|
|
}));
|
|
|
|
jest.mock('./start/checks', () => ({
|
|
|
|
checkVariables: jest.fn(),
|
|
|
|
checkHealth: jest.fn(),
|
|
|
|
checkConfig: jest.fn(),
|
|
|
|
checkAzureVariables: jest.fn(),
|
2025-05-24 10:23:17 -04:00
|
|
|
checkWebSearchConfig: jest.fn(),
|
2024-08-21 19:57:34 -04:00
|
|
|
}));
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
jest.mock('./Config/loadCustomConfig', () => jest.fn());
|
|
|
|
|
2024-08-21 19:57:34 -04:00
|
|
|
const AppService = require('./AppService');
|
2025-08-26 12:10:18 -04:00
|
|
|
const { loadDefaultInterface } = require('@librechat/api');
|
2024-08-21 19:57:34 -04:00
|
|
|
|
2024-08-26 15:34:46 -04:00
|
|
|
describe('AppService interface configuration', () => {
|
2024-08-21 19:57:34 -04:00
|
|
|
let mockLoadCustomConfig;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
|
|
|
jest.clearAllMocks();
|
|
|
|
mockLoadCustomConfig = require('./Config/loadCustomConfig');
|
|
|
|
});
|
|
|
|
|
2024-08-26 15:34:46 -04:00
|
|
|
it('should set prompts and bookmarks to true when loadDefaultInterface returns true for both', async () => {
|
2024-08-21 19:57:34 -04:00
|
|
|
mockLoadCustomConfig.mockResolvedValue({});
|
2024-08-26 15:34:46 -04:00
|
|
|
loadDefaultInterface.mockResolvedValue({ prompts: true, bookmarks: true });
|
2024-08-21 19:57:34 -04:00
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
const result = await AppService();
|
2024-08-21 19:57:34 -04:00
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
expect(result).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
interfaceConfig: expect.objectContaining({
|
|
|
|
prompts: true,
|
|
|
|
bookmarks: true,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
2024-08-21 19:57:34 -04:00
|
|
|
expect(loadDefaultInterface).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2024-08-26 15:34:46 -04:00
|
|
|
it('should set prompts and bookmarks to false when loadDefaultInterface returns false for both', async () => {
|
|
|
|
mockLoadCustomConfig.mockResolvedValue({ interface: { prompts: false, bookmarks: false } });
|
|
|
|
loadDefaultInterface.mockResolvedValue({ prompts: false, bookmarks: false });
|
2024-08-21 19:57:34 -04:00
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
const result = await AppService();
|
2024-08-21 19:57:34 -04:00
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
expect(result).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
interfaceConfig: expect.objectContaining({
|
|
|
|
prompts: false,
|
|
|
|
bookmarks: false,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
2024-08-21 19:57:34 -04:00
|
|
|
expect(loadDefaultInterface).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2024-08-26 15:34:46 -04:00
|
|
|
it('should not set prompts and bookmarks when loadDefaultInterface returns undefined for both', async () => {
|
2024-08-21 19:57:34 -04:00
|
|
|
mockLoadCustomConfig.mockResolvedValue({});
|
|
|
|
loadDefaultInterface.mockResolvedValue({});
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
const result = await AppService();
|
2024-08-21 19:57:34 -04:00
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
expect(result).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
interfaceConfig: expect.anything(),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify that prompts and bookmarks are undefined when not provided
|
|
|
|
expect(result.interfaceConfig.prompts).toBeUndefined();
|
|
|
|
expect(result.interfaceConfig.bookmarks).toBeUndefined();
|
2024-08-26 15:34:46 -04:00
|
|
|
expect(loadDefaultInterface).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set prompts and bookmarks to different values when loadDefaultInterface returns different values', async () => {
|
|
|
|
mockLoadCustomConfig.mockResolvedValue({ interface: { prompts: true, bookmarks: false } });
|
|
|
|
loadDefaultInterface.mockResolvedValue({ prompts: true, bookmarks: false });
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
const result = await AppService();
|
2024-08-26 15:34:46 -04:00
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
expect(result).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
interfaceConfig: expect.objectContaining({
|
|
|
|
prompts: true,
|
|
|
|
bookmarks: false,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
2024-08-21 19:57:34 -04:00
|
|
|
expect(loadDefaultInterface).toHaveBeenCalled();
|
|
|
|
});
|
2025-08-03 19:24:40 -04:00
|
|
|
|
|
|
|
it('should correctly configure peoplePicker permissions including roles', async () => {
|
|
|
|
mockLoadCustomConfig.mockResolvedValue({
|
|
|
|
interface: {
|
|
|
|
peoplePicker: {
|
2025-08-10 17:42:33 -04:00
|
|
|
users: true,
|
|
|
|
groups: true,
|
|
|
|
roles: true,
|
2025-08-03 19:24:40 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
loadDefaultInterface.mockResolvedValue({
|
|
|
|
peoplePicker: {
|
2025-08-10 17:42:33 -04:00
|
|
|
users: true,
|
|
|
|
groups: true,
|
|
|
|
roles: true,
|
2025-08-03 19:24:40 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
const result = await AppService();
|
|
|
|
|
|
|
|
expect(result).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
interfaceConfig: expect.objectContaining({
|
|
|
|
peoplePicker: expect.objectContaining({
|
|
|
|
users: true,
|
|
|
|
groups: true,
|
|
|
|
roles: true,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
2025-08-03 19:24:40 -04:00
|
|
|
expect(loadDefaultInterface).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2025-08-10 17:42:33 -04:00
|
|
|
it('should handle mixed peoplePicker permissions', async () => {
|
2025-08-03 19:24:40 -04:00
|
|
|
mockLoadCustomConfig.mockResolvedValue({
|
|
|
|
interface: {
|
|
|
|
peoplePicker: {
|
2025-08-10 17:42:33 -04:00
|
|
|
users: true,
|
|
|
|
groups: false,
|
|
|
|
roles: true,
|
2025-08-03 19:24:40 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
loadDefaultInterface.mockResolvedValue({
|
|
|
|
peoplePicker: {
|
2025-08-10 17:42:33 -04:00
|
|
|
users: true,
|
|
|
|
groups: false,
|
|
|
|
roles: true,
|
2025-08-03 19:24:40 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
const result = await AppService();
|
|
|
|
|
|
|
|
expect(result).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
interfaceConfig: expect.objectContaining({
|
|
|
|
peoplePicker: expect.objectContaining({
|
|
|
|
users: true,
|
|
|
|
groups: false,
|
|
|
|
roles: true,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
2025-08-03 19:24:40 -04:00
|
|
|
});
|
|
|
|
|
2025-08-10 17:42:33 -04:00
|
|
|
it('should set default peoplePicker permissions when not provided', async () => {
|
2025-08-03 19:24:40 -04:00
|
|
|
mockLoadCustomConfig.mockResolvedValue({});
|
|
|
|
loadDefaultInterface.mockResolvedValue({
|
|
|
|
peoplePicker: {
|
2025-08-10 17:42:33 -04:00
|
|
|
users: true,
|
|
|
|
groups: true,
|
|
|
|
roles: true,
|
2025-08-03 19:24:40 -04:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2025-08-26 12:10:18 -04:00
|
|
|
const result = await AppService();
|
|
|
|
|
|
|
|
expect(result).toEqual(
|
|
|
|
expect.objectContaining({
|
|
|
|
interfaceConfig: expect.objectContaining({
|
|
|
|
peoplePicker: expect.objectContaining({
|
|
|
|
users: true,
|
|
|
|
groups: true,
|
|
|
|
roles: true,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
2025-08-03 19:24:40 -04:00
|
|
|
});
|
2024-08-21 19:57:34 -04:00
|
|
|
});
|