feat(backend): Add Clone Endpoint

This commit is contained in:
Lilly Schramm 2025-06-20 20:27:20 +02:00
parent 8926ba06a6
commit ebf21b474a
4 changed files with 121 additions and 0 deletions

View file

@ -983,4 +983,50 @@ describe('RoleService', () => {
expect(notificationService.createNotification).not.toHaveBeenCalled();
});
});
describe('clone', () => {
test('clones an role', async () => {
const role = await createRole({
name: 'original role',
color: '#ff0000',
policies: {
canManageCustomEmojis: {
useDefault: false,
priority: 0,
value: true,
},
},
});
const clonedRole = await roleService.clone(role);
expect(clonedRole).toBeDefined();
expect(clonedRole.id).not.toBe(role.id);
expect(clonedRole.name).toBe(`${role.name} (cloned)`);
expect(clonedRole).toEqual(expect.objectContaining({
color: role.color,
policies: {
canManageCustomEmojis: {
useDefault: false,
priority: 0,
value: true,
},
},
}));
});
test('clones a roll with a too long name', async () => {
const role = await createRole({
name: 'a'.repeat(254),
});
const clonedRole = await roleService.clone(role);
expect(clonedRole).toBeDefined();
expect(clonedRole.id).not.toBe(role.id);
expect(clonedRole.name).toBe(`${role.name} (`);
expect(clonedRole.name.length).toBe(256);
});
});
});