-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathUserAdministrativeDTO.spec.ts
More file actions
65 lines (60 loc) · 2.32 KB
/
Copy pathUserAdministrativeDTO.spec.ts
File metadata and controls
65 lines (60 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { UserAdministrativeDTO } from './UserAdministrativeDTO';
import { validate } from 'class-validator';
import {
ContractType,
WorkingTimeType
} from 'src/Domain/HumanResource/User/UserAdministrative.entity';
import { UserRole } from 'src/Domain/HumanResource/User/User.entity';
describe('UserAdministrativeDTO', () => {
it('testValidDTO', async () => {
const dto = new UserAdministrativeDTO();
dto.role = UserRole.COOPERATOR;
dto.annualEarnings = 50000;
dto.contract = ContractType.CDI;
dto.workingTime = WorkingTimeType.FULL_TIME;
dto.executivePosition = true;
dto.healthInsurance = true;
dto.transportFee = 75.2;
dto.sportsPassFee = 30;
dto.joiningDate = '2020-12-17T03:24:00';
dto.leavingDate = '2021-12-17T03:24:00';
const validation = await validate(dto);
expect(validation).toHaveLength(0);
});
it('testInvalidDTO', async () => {
const dto = new UserAdministrativeDTO();
dto.role = UserRole.COOPERATOR;
dto.joiningDate = '';
dto.leavingDate = 'invalid';
const validation = await validate(dto);
expect(validation).toHaveLength(7);
expect(validation[0].constraints).toMatchObject({
isInt: 'annualEarnings must be an integer number',
isNotEmpty: 'annualEarnings should not be empty',
isPositive: 'annualEarnings must be a positive number'
});
expect(validation[1].constraints).toMatchObject({
isBoolean: 'healthInsurance must be a boolean value',
isNotEmpty: 'healthInsurance should not be empty'
});
expect(validation[2].constraints).toMatchObject({
isBoolean: 'executivePosition must be a boolean value',
isNotEmpty: 'executivePosition should not be empty'
});
expect(validation[3].constraints).toMatchObject({
// isDateString: 'joiningDate must be a ISOString',
isNotEmpty: 'joiningDate should not be empty'
});
expect(validation[4].constraints).toMatchObject({
isIso8601: 'leavingDate must be a valid ISO 8601 date string'
});
expect(validation[5].constraints).toMatchObject({
isEnum: 'contract must be a valid enum value',
isNotEmpty: 'contract should not be empty'
});
expect(validation[6].constraints).toMatchObject({
isEnum: 'workingTime must be a valid enum value',
isNotEmpty: 'workingTime should not be empty'
});
});
});