diff --git a/src/lib/features/project/project-service.e2e.test.ts b/src/lib/features/project/project-service.e2e.test.ts index 5eb715a894..3dcd277d92 100644 --- a/src/lib/features/project/project-service.e2e.test.ts +++ b/src/lib/features/project/project-service.e2e.test.ts @@ -2684,6 +2684,40 @@ describe('automatic ID generation for create project', () => { }, ); + test('Projects with long names get ids capped at 90 characters and then suffixed', async () => { + const name = Array.from({ length: 200 }) + .map(() => 'a') + .join(); + + const project = await projectService.createProject( + { + name, + }, + user, + auditUser, + ); + + expect(project.name).toBe(name); + expect(project.id.length).toBeLessThanOrEqual(90); + + const secondName = + name + + Array.from({ length: 100 }) + .map(() => 'b') + .join(); + + const secondProject = await projectService.createProject( + { + name: secondName, + }, + user, + auditUser, + ); + + expect(secondProject.name).toBe(secondName); + expect(secondProject.id).toBe(`${project.id}-1`); + }); + describe('backwards compatibility', () => { const featureFlag = 'createProjectWithEnvironmentConfig'; diff --git a/src/lib/features/project/project-service.ts b/src/lib/features/project/project-service.ts index e36619d429..2549d9c0f1 100644 --- a/src/lib/features/project/project-service.ts +++ b/src/lib/features/project/project-service.ts @@ -305,16 +305,16 @@ export default class ProjectService { } } async generateProjectId(name: string): Promise { - const generateUniqueId = async (name: string, suffix?: number) => { - const slug = createSlug(name); + const slug = createSlug(name).slice(0, 90); + const generateUniqueId = async (suffix?: number) => { const id = suffix ? `${slug}-${suffix}` : slug; if (await this.projectStore.hasProject(id)) { - return await generateUniqueId(name, (suffix ?? 0) + 1); + return await generateUniqueId((suffix ?? 0) + 1); } else { return id; } }; - return generateUniqueId(name); + return generateUniqueId(); } async createProject(