Files
lislgosms/api/src/users/client-user.dto.spec.ts
T

44 lines
1.5 KiB
TypeScript

import { BadRequestException } from '@nestjs/common';
import { strictValidationPipe } from '../common/strict-validation.pipe';
import { ClientCreateUserDto, ClientUserPasswordDto } from './client-user.dto';
describe('client user DTOs', () => {
it('rejects tenant, role and operator identity supplied by a client', async () => {
await expect(
strictValidationPipe.transform(
{
displayName: '测试用户',
email: 'user@example.com',
password: 'StrongPass-2026!',
tenantId: 'other',
roleCode: 'platform_admin',
operatorId: 'other-user',
},
{ type: 'body', metatype: ClientCreateUserDto, data: undefined },
),
).rejects.toBeInstanceOf(BadRequestException);
});
it('requires a bounded password', async () => {
await expect(
strictValidationPipe.transform(
{ password: '1234567' },
{
type: 'body',
metatype: ClientUserPasswordDto,
data: undefined,
},
),
).rejects.toBeInstanceOf(BadRequestException);
});
it('normalizes optional blank login fields without rejecting the existing client form', async () => {
await expect(
strictValidationPipe.transform(
{ displayName: '测试用户', username: ' user ', email: ' ', phone: '', password: 'StrongPass-2026!' },
{ type: 'body', metatype: ClientCreateUserDto, data: undefined },
),
).resolves.toEqual(expect.objectContaining({ username: 'user', email: undefined, phone: undefined }));
});
});