Skip to content

Commit

Permalink
fix(api): Empty name "" accepted as a valid name while creating env…
Browse files Browse the repository at this point in the history
…ironments (#583)
  • Loading branch information
zaheer-Khan3260 authored Dec 9, 2024
1 parent 8199de8 commit a33f4b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
17 changes: 17 additions & 0 deletions apps/api/src/environment/environment.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit a33f4b5

Please sign in to comment.