fix: align admin profile request validation
This commit is contained in:
@@ -69,6 +69,22 @@ describe('AdminUsersController', () => {
|
||||
});
|
||||
|
||||
describe('admin user DTOs', () => {
|
||||
it('accepts omitted and string profile names but rejects explicit nulls', async () => {
|
||||
const omitted = plainToInstance(AdminUserProfileDto, {});
|
||||
const names = plainToInstance(AdminUserProfileDto, {
|
||||
firstName: 'Ada',
|
||||
lastName: 'Admin',
|
||||
});
|
||||
const nulls = plainToInstance(AdminUserProfileDto, {
|
||||
firstName: null,
|
||||
lastName: null,
|
||||
});
|
||||
|
||||
expect(await validate(omitted)).toEqual([]);
|
||||
expect(await validate(names)).toEqual([]);
|
||||
expect(await validate(nulls)).not.toEqual([]);
|
||||
});
|
||||
|
||||
it('accepts only profile names in the profile DTO', async () => {
|
||||
const dto = plainToInstance(AdminUserProfileDto, {
|
||||
firstName: 'Ada',
|
||||
|
||||
@@ -7,20 +7,21 @@ import {
|
||||
Max,
|
||||
MaxLength,
|
||||
Min,
|
||||
ValidateIf,
|
||||
} from 'class-validator';
|
||||
import { RoleEnum } from '../../roles/roles.enum';
|
||||
import { StatusEnum } from '../../statuses/statuses.enum';
|
||||
|
||||
export class AdminUserProfileDto {
|
||||
@IsOptional()
|
||||
@ValidateIf((_, value) => value !== undefined)
|
||||
@IsString()
|
||||
@MaxLength(255)
|
||||
firstName?: string | null;
|
||||
firstName?: string;
|
||||
|
||||
@IsOptional()
|
||||
@ValidateIf((_, value) => value !== undefined)
|
||||
@IsString()
|
||||
@MaxLength(255)
|
||||
lastName?: string | null;
|
||||
lastName?: string;
|
||||
}
|
||||
|
||||
export class AdminUserRoleDto {
|
||||
|
||||
Reference in New Issue
Block a user