2025-05-30 22:18:13 -04:00
|
|
|
jest.mock('~/models', () => ({
|
2024-08-21 19:57:34 -04:00
|
|
|
initializeRoles: jest.fn(),
|
2025-05-30 22:18:13 -04:00
|
|
|
}));
|
|
|
|
jest.mock('~/models/Role', () => ({
|
2024-08-26 15:34:46 -04:00
|
|
|
updateAccessPermissions: jest.fn(),
|
2024-08-21 19:57:34 -04:00
|
|
|
getRoleByName: jest.fn(),
|
|
|
|
updateRoleByName: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('~/config', () => ({
|
|
|
|
logger: {
|
|
|
|
info: jest.fn(),
|
|
|
|
warn: jest.fn(),
|
|
|
|
error: jest.fn(),
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('./Config/loadCustomConfig', () => jest.fn());
|
|
|
|
jest.mock('./start/interface', () => ({
|
|
|
|
loadDefaultInterface: jest.fn(),
|
|
|
|
}));
|
|
|
|
jest.mock('./ToolService', () => ({
|
|
|
|
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
|
|
|
}));
|
|
|
|
|
|
|
|
const AppService = require('./AppService');
|
|
|
|
const { loadDefaultInterface } = require('./start/interface');
|
|
|
|
|
2024-08-26 15:34:46 -04:00
|
|
|
describe('AppService interface configuration', () => {
|
2024-08-21 19:57:34 -04:00
|
|
|
let app;
|
|
|
|
let mockLoadCustomConfig;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
app = { locals: {} };
|
|
|
|
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
|
|
|
|
|
|
|
await AppService(app);
|
|
|
|
|
|
|
|
expect(app.locals.interfaceConfig.prompts).toBe(true);
|
2024-08-26 15:34:46 -04:00
|
|
|
expect(app.locals.interfaceConfig.bookmarks).toBe(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
|
|
|
|
|
|
|
await AppService(app);
|
|
|
|
|
|
|
|
expect(app.locals.interfaceConfig.prompts).toBe(false);
|
2024-08-26 15:34:46 -04:00
|
|
|
expect(app.locals.interfaceConfig.bookmarks).toBe(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({});
|
|
|
|
|
|
|
|
await AppService(app);
|
|
|
|
|
|
|
|
expect(app.locals.interfaceConfig.prompts).toBeUndefined();
|
2024-08-26 15:34:46 -04:00
|
|
|
expect(app.locals.interfaceConfig.bookmarks).toBeUndefined();
|
|
|
|
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 });
|
|
|
|
|
|
|
|
await AppService(app);
|
|
|
|
|
|
|
|
expect(app.locals.interfaceConfig.prompts).toBe(true);
|
|
|
|
expect(app.locals.interfaceConfig.bookmarks).toBe(false);
|
2024-08-21 19:57:34 -04:00
|
|
|
expect(loadDefaultInterface).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|