diff --git a/apps/api/src/environment/dto/create.environment/create.environment.ts b/apps/api/src/environment/dto/create.environment/create.environment.ts index db1adb9a9..ffa62e3f5 100644 --- a/apps/api/src/environment/dto/create.environment/create.environment.ts +++ b/apps/api/src/environment/dto/create.environment/create.environment.ts @@ -1,7 +1,9 @@ -import { IsOptional, IsString } from 'class-validator' +import { IsNotEmpty, IsOptional, IsString, Matches } from 'class-validator' export class CreateEnvironment { @IsString() + @IsNotEmpty() + @Matches(/^[a-zA-Z0-9-_]{1,64}$/) name: string @IsString() diff --git a/apps/api/src/environment/environment.e2e.spec.ts b/apps/api/src/environment/environment.e2e.spec.ts index be15ee7ef..ad949f1c1 100644 --- a/apps/api/src/environment/environment.e2e.spec.ts +++ b/apps/api/src/environment/environment.e2e.spec.ts @@ -172,6 +172,23 @@ describe('Environment Controller Tests', () => { expect(environmentFromDb).toBeDefined() }) + it('should not be able to create an environment with an empty name', async () => { + const response = await app.inject({ + method: 'POST', + url: `/environment/${project1.slug}`, + payload: { + name: '', + description: 'Empty name test' + }, + headers: { + 'x-e2e-user-email': user1.email + } + }) + + expect(response.statusCode).toBe(400) + expect(response.json().message).toContain('name should not be empty') + }) + it('should not be able to create an environment in a project that does not exist', async () => { const response = await app.inject({ method: 'POST',