-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Add validation decorators,class-validator to DTO
- Loading branch information
1 parent
624c562
commit a4e2dd6
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,48 @@ describe('UserDto', () => { | |
expect(userDto.email).toBe(email); | ||
expect(userDto.firstName).toBe(firstName); | ||
}); | ||
|
||
it('should handle empty firstName and lastName', () => { | ||
const id = '456'; | ||
const email = '[email protected]'; | ||
const userDto = new UserDto(id, email, null, null); | ||
|
||
expect(userDto).toBeDefined(); | ||
expect(userDto.id).toBe(id); | ||
expect(userDto.email).toBe(email); | ||
expect(userDto.firstName).toBeUndefined(); | ||
expect(userDto.lastName).toBeUndefined(); | ||
}); | ||
|
||
it('should validate email format', () => { | ||
const id = '789'; | ||
const invalidEmail = 'invalid-email'; | ||
|
||
expect(() => { | ||
new UserDto(id, invalidEmail, null, null); | ||
}).toThrow(); | ||
}); | ||
|
||
it('should require id and email', () => { | ||
expect(() => { | ||
// @ts-expect-error testing invalid constructor args | ||
new UserDto(); | ||
}).toThrow(); | ||
|
||
expect(() => { | ||
// @ts-expect-error testing invalid constructor args | ||
new UserDto('123'); | ||
}).toThrow(); | ||
}); | ||
|
||
it('should handle special characters in names', () => { | ||
const id = '101'; | ||
const email = '[email protected]'; | ||
const firstName = 'Jean-Pierre'; | ||
const lastName = "O'Connor"; | ||
const userDto = new UserDto(id, email, firstName, lastName); | ||
|
||
expect(userDto.firstName).toBe(firstName); | ||
expect(userDto.lastName).toBe(lastName); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters