2022-07-15 21:30:56 +02:00
|
|
|
import { plainToInstance } from 'class-transformer';
|
2022-11-04 00:55:13 +01:00
|
|
|
import { validateSync } from 'class-validator';
|
2022-07-15 21:30:56 +02:00
|
|
|
import { SignUpDto } from './sign-up.dto';
|
|
|
|
|
2022-11-04 00:55:13 +01:00
|
|
|
describe('SignUpDto', () => {
|
|
|
|
it('should require all fields', () => {
|
|
|
|
const dto = plainToInstance(SignUpDto, {
|
|
|
|
email: '',
|
|
|
|
password: '',
|
|
|
|
firstName: '',
|
|
|
|
lastName: '',
|
|
|
|
});
|
|
|
|
const errors = validateSync(dto);
|
|
|
|
expect(errors).toHaveLength(4);
|
|
|
|
expect(errors[0].property).toEqual('email');
|
|
|
|
expect(errors[1].property).toEqual('password');
|
|
|
|
expect(errors[2].property).toEqual('firstName');
|
|
|
|
expect(errors[3].property).toEqual('lastName');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should require a valid email', () => {
|
|
|
|
const dto = plainToInstance(SignUpDto, {
|
|
|
|
email: 'immich.com',
|
2022-07-15 21:30:56 +02:00
|
|
|
password: 'password',
|
|
|
|
firstName: 'first name',
|
|
|
|
lastName: 'last name',
|
2022-11-04 00:55:13 +01:00
|
|
|
});
|
|
|
|
const errors = validateSync(dto);
|
2022-07-15 21:30:56 +02:00
|
|
|
expect(errors).toHaveLength(1);
|
2022-11-04 00:55:13 +01:00
|
|
|
expect(errors[0].property).toEqual('email');
|
|
|
|
});
|
2022-07-15 21:30:56 +02:00
|
|
|
|
2022-11-04 00:55:13 +01:00
|
|
|
it('should make the email all lowercase', () => {
|
|
|
|
const dto = plainToInstance(SignUpDto, {
|
|
|
|
email: 'TeSt@ImMiCh.com',
|
|
|
|
password: 'password',
|
|
|
|
firstName: 'first name',
|
|
|
|
lastName: 'last name',
|
|
|
|
});
|
|
|
|
const errors = validateSync(dto);
|
2022-07-15 21:30:56 +02:00
|
|
|
expect(errors).toHaveLength(0);
|
2022-11-04 00:55:13 +01:00
|
|
|
expect(dto.email).toEqual('test@immich.com');
|
2022-07-15 21:30:56 +02:00
|
|
|
});
|
|
|
|
});
|