mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 11:20:15 +01:00
ci: fix existing tests based off new permission handling
- Renamed test cases to reflect changes in permission checks being handled at the route level. - Updated assertions to verify that agents are returned regardless of user permissions due to the new permission system. - Adjusted mocks in AppService and PermissionService tests to ensure proper functionality without relying on actual implementations.
This commit is contained in:
parent
c07a342c97
commit
004f128aec
3 changed files with 15 additions and 8 deletions
|
|
@ -1633,7 +1633,7 @@ describe('models/Agent', () => {
|
||||||
expect(result.version).toBe(1);
|
expect(result.version).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return null when user is not author and agent has no projectIds', async () => {
|
test('should return agent even when user is not author (permissions checked at route level)', async () => {
|
||||||
const authorId = new mongoose.Types.ObjectId();
|
const authorId = new mongoose.Types.ObjectId();
|
||||||
const userId = new mongoose.Types.ObjectId();
|
const userId = new mongoose.Types.ObjectId();
|
||||||
const agentId = `agent_${uuidv4()}`;
|
const agentId = `agent_${uuidv4()}`;
|
||||||
|
|
@ -1654,7 +1654,11 @@ describe('models/Agent', () => {
|
||||||
model_parameters: { model: 'gpt-4' },
|
model_parameters: { model: 'gpt-4' },
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result).toBeFalsy();
|
// With the new permission system, loadAgent returns the agent regardless of permissions
|
||||||
|
// Permission checks are handled at the route level via middleware
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result.id).toBe(agentId);
|
||||||
|
expect(result.name).toBe('Test Agent');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should handle ephemeral agent with no MCP servers', async () => {
|
test('should handle ephemeral agent with no MCP servers', async () => {
|
||||||
|
|
@ -1762,7 +1766,7 @@ describe('models/Agent', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should handle loadAgent with agent from different project', async () => {
|
test('should return agent from different project (permissions checked at route level)', async () => {
|
||||||
const authorId = new mongoose.Types.ObjectId();
|
const authorId = new mongoose.Types.ObjectId();
|
||||||
const userId = new mongoose.Types.ObjectId();
|
const userId = new mongoose.Types.ObjectId();
|
||||||
const agentId = `agent_${uuidv4()}`;
|
const agentId = `agent_${uuidv4()}`;
|
||||||
|
|
@ -1785,7 +1789,11 @@ describe('models/Agent', () => {
|
||||||
model_parameters: { model: 'gpt-4' },
|
model_parameters: { model: 'gpt-4' },
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result).toBeFalsy();
|
// With the new permission system, loadAgent returns the agent regardless of permissions
|
||||||
|
// Permission checks are handled at the route level via middleware
|
||||||
|
expect(result).toBeTruthy();
|
||||||
|
expect(result.id).toBe(agentId);
|
||||||
|
expect(result.name).toBe('Project Agent');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
jest.mock('~/models', () => ({
|
jest.mock('~/models', () => ({
|
||||||
initializeRoles: jest.fn(),
|
initializeRoles: jest.fn(),
|
||||||
|
seedDefaultRoles: jest.fn(),
|
||||||
}));
|
}));
|
||||||
jest.mock('~/models/Role', () => ({
|
jest.mock('~/models/Role', () => ({
|
||||||
updateAccessPermissions: jest.fn(),
|
updateAccessPermissions: jest.fn(),
|
||||||
getRoleByName: jest.fn(),
|
getRoleByName: jest.fn(),
|
||||||
updateRoleByName: jest.fn(),
|
updateRoleByName: jest.fn(),
|
||||||
}));
|
}));
|
||||||
jest.mock('~/models/AccessRole', () => ({
|
|
||||||
seedDefaultRoles: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock('~/config', () => ({
|
jest.mock('~/config', () => ({
|
||||||
logger: {
|
logger: {
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,8 @@ beforeEach(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Mock getUserPrincipals to avoid depending on the actual implementation
|
// Mock getUserPrincipals to avoid depending on the actual implementation
|
||||||
jest.mock('~/models/userGroupMethods', () => ({
|
jest.mock('~/models', () => ({
|
||||||
|
...jest.requireActual('~/models'),
|
||||||
getUserPrincipals: jest.fn(),
|
getUserPrincipals: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue