1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-25 13:12:46 +01:00
immich/server/libs/domain/src/auth/dto/sign-up.dto.spec.ts

45 lines
1.3 KiB
TypeScript
Raw Normal View History

import { plainToInstance } from 'class-transformer';
2022-11-04 00:55:13 +01:00
import { validateSync } from 'class-validator';
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',
password: 'password',
firstName: 'first name',
lastName: 'last name',
2022-11-04 00:55:13 +01:00
});
const errors = validateSync(dto);
expect(errors).toHaveLength(1);
2022-11-04 00:55:13 +01:00
expect(errors[0].property).toEqual('email');
});
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);
expect(errors).toHaveLength(0);
2022-11-04 00:55:13 +01:00
expect(dto.email).toEqual('test@immich.com');
});
});