2024-08-22 17:09:05 -04:00
|
|
|
const { SystemRoles, Permissions } = require('librechat-data-provider');
|
2024-08-21 19:57:34 -04:00
|
|
|
const { updatePromptsAccess } = require('~/models/Role');
|
|
|
|
const { loadDefaultInterface } = require('./interface');
|
|
|
|
|
|
|
|
jest.mock('~/models/Role', () => ({
|
|
|
|
updatePromptsAccess: jest.fn(),
|
2024-08-22 17:09:05 -04:00
|
|
|
updateBookmarksAccess: jest.fn(),
|
2024-08-21 19:57:34 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('loadDefaultInterface', () => {
|
|
|
|
it('should call updatePromptsAccess with the correct parameters when prompts is true', async () => {
|
|
|
|
const config = { interface: { prompts: true } };
|
|
|
|
const configDefaults = { interface: {} };
|
|
|
|
|
|
|
|
await loadDefaultInterface(config, configDefaults);
|
|
|
|
|
2024-08-22 17:09:05 -04:00
|
|
|
expect(updatePromptsAccess).toHaveBeenCalledWith(SystemRoles.USER, { [Permissions.USE]: true });
|
2024-08-21 19:57:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call updatePromptsAccess with false when prompts is false', async () => {
|
|
|
|
const config = { interface: { prompts: false } };
|
|
|
|
const configDefaults = { interface: {} };
|
|
|
|
|
|
|
|
await loadDefaultInterface(config, configDefaults);
|
|
|
|
|
2024-08-22 17:09:05 -04:00
|
|
|
expect(updatePromptsAccess).toHaveBeenCalledWith(SystemRoles.USER, {
|
|
|
|
[Permissions.USE]: false,
|
|
|
|
});
|
2024-08-21 19:57:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call updatePromptsAccess with undefined when prompts is not specified in config', async () => {
|
|
|
|
const config = {};
|
|
|
|
const configDefaults = { interface: {} };
|
|
|
|
|
|
|
|
await loadDefaultInterface(config, configDefaults);
|
|
|
|
|
2024-08-22 17:09:05 -04:00
|
|
|
expect(updatePromptsAccess).toHaveBeenCalledWith(SystemRoles.USER, {
|
|
|
|
[Permissions.USE]: undefined,
|
|
|
|
});
|
2024-08-21 19:57:34 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call updatePromptsAccess with undefined when prompts is explicitly undefined', async () => {
|
|
|
|
const config = { interface: { prompts: undefined } };
|
|
|
|
const configDefaults = { interface: {} };
|
|
|
|
|
|
|
|
await loadDefaultInterface(config, configDefaults);
|
|
|
|
|
2024-08-22 17:09:05 -04:00
|
|
|
expect(updatePromptsAccess).toHaveBeenCalledWith(SystemRoles.USER, {
|
|
|
|
[Permissions.USE]: undefined,
|
|
|
|
});
|
2024-08-21 19:57:34 -04:00
|
|
|
});
|
|
|
|
});
|