feat: Truncate Old Name

This commit is contained in:
Lilly Schramm 2025-06-20 21:33:17 +02:00
parent 18a979ea4e
commit 98a63e8e96
2 changed files with 7 additions and 4 deletions

View file

@ -739,12 +739,15 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
@bindThis @bindThis
public async clone(role: MiRole, moderator?: MiUser): Promise<MiRole> { public async clone(role: MiRole, moderator?: MiUser): Promise<MiRole> {
let newName = `${role.name} (cloned)`; const suffix = ' (cloned)';
let newName = role.name;
if (newName.length > 256) { if (newName.length > 256 - suffix.length) {
newName = newName.slice(0, 256); newName = newName.slice(0, 256 - suffix.length);
} }
newName += suffix;
return this.create({ return this.create({
...role, ...role,
name: newName, name: newName,

View file

@ -1025,7 +1025,7 @@ describe('RoleService', () => {
expect(clonedRole).toBeDefined(); expect(clonedRole).toBeDefined();
expect(clonedRole.id).not.toBe(role.id); expect(clonedRole.id).not.toBe(role.id);
expect(clonedRole.name).toBe(`${role.name} (`); expect(clonedRole.name.endsWith(' (cloned)')).toBeTruthy();
expect(clonedRole.name.length).toBe(256); expect(clonedRole.name.length).toBe(256);
}); });
}); });