| 1 |  |  | import {UserNotFoundException} from 'src/Domain/HumanResource/User/Exception/UserNotFoundException'; | 
            
                                                        
            
                                    
            
            
                | 2 |  |  | import {IUserAdministrativeRepository} from 'src/Domain/HumanResource/User/Repository/IUserAdministrativeRepository'; | 
            
                                                        
            
                                    
            
            
                | 3 |  |  | import {IUserRepository} from 'src/Domain/HumanResource/User/Repository/IUserRepository'; | 
            
                                                        
            
                                    
            
            
                | 4 |  |  | import {User, UserRole} from 'src/Domain/HumanResource/User/User.entity'; | 
            
                                                        
            
                                    
            
            
                | 5 |  |  | import {ContractType, UserAdministrative} from 'src/Domain/HumanResource/User/UserAdministrative.entity'; | 
            
                                                        
            
                                    
            
            
                | 6 |  |  | import {UserAdministrativeRepository} from 'src/Infrastructure/HumanResource/User/Repository/UserAdministrativeRepository'; | 
            
                                                        
            
                                    
            
            
                | 7 |  |  | import {UserRepository} from 'src/Infrastructure/HumanResource/User/Repository/UserRepository'; | 
            
                                                        
            
                                    
            
            
                | 8 |  |  | import {anything, deepEqual, instance, mock, verify, when} from 'ts-mockito'; | 
            
                                                        
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 10 |  |  | import {UpdateUserCommand} from './UpdateUserCommand'; | 
            
                                                        
            
                                    
            
            
                | 11 |  |  | import {UpdateUserCommandHandler} from './UpdateUserCommandHandler'; | 
            
                                                        
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 13 |  |  | describe('UpdateProfileCommandHandler', () => { | 
            
                                                        
            
                                    
            
            
                | 14 |  |  |   let userRepository: IUserRepository; | 
            
                                                        
            
                                    
            
            
                | 15 |  |  |   let userAdministrativeRepository: IUserAdministrativeRepository; | 
            
                                                        
            
                                    
            
            
                | 16 |  |  |   let commandHandler: UpdateUserCommandHandler; | 
            
                                                        
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 18 |  |  |   const command: UpdateUserCommand = new UpdateUserCommand( | 
            
                                                        
            
                                    
            
            
                | 19 |  |  |     'c07c4d56-5ff1-4ef9-b38e-631a6b9e92ed', | 
            
                                                        
            
                                    
            
            
                | 20 |  |  |     UserRole.COOPERATOR, | 
            
                                                        
            
                                    
            
            
                | 21 |  |  |     50000, | 
            
                                                        
            
                                    
            
            
                | 22 |  |  |     ContractType.CDI, | 
            
                                                        
            
                                    
            
            
                | 23 |  |  |     true, | 
            
                                                        
            
                                    
            
            
                | 24 |  |  |     true, | 
            
                                                        
            
                                    
            
            
                | 25 |  |  |     '2018-01-01', | 
            
                                                        
            
                                    
            
            
                | 26 |  |  |     null, | 
            
                                                        
            
                                    
            
            
                | 27 |  |  |     75.2 | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |   ); | 
            
                                                        
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 30 |  |  |   beforeEach(() => { | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |     userRepository = mock(UserRepository); | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |     userAdministrativeRepository = mock(UserAdministrativeRepository); | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |     commandHandler = new UpdateUserCommandHandler(instance(userRepository), instance(userAdministrativeRepository)); | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |   }); | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |   it('testUserNotFound', async () => { | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |     const user = mock(User); | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |     when(userRepository.findOneById('c07c4d56-5ff1-4ef9-b38e-631a6b9e92ed')).thenResolve(null); | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |     try { | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |       await commandHandler.execute(command); | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |     } catch (e) { | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |       expect(e).toBeInstanceOf(UserNotFoundException); | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |       expect(e.message).toBe('human_resources.users.errors.not_found'); | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |       verify(userRepository.findOneById('c07c4d56-5ff1-4ef9-b38e-631a6b9e92ed')).once(); | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |       verify(userRepository.save(anything())).never(); | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |       verify(userAdministrativeRepository.save(anything())).never(); | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |   }); | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |   it('testUserUpdated', async () => { | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |     const userAdministrative = new UserAdministrative(30000, false, false, ContractType.CTT, '2017-08-01', '2018-12-31', null); | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |     const user = new User('John', 'Doe', '[email protected]', '123456789', 'password', UserRole.EMPLOYEE, userAdministrative); | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |     when(userRepository.findOneById('c07c4d56-5ff1-4ef9-b38e-631a6b9e92ed')).thenResolve(user); | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |     when(userAdministrativeRepository.findOneByUserId('c07c4d56-5ff1-4ef9-b38e-631a6b9e92ed')).thenResolve(userAdministrative); | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |     await commandHandler.execute(command); | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |     const updatedUserAdministrative = new UserAdministrative( | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |       5000000, | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |       true, | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |       true, | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |       ContractType.CDI, | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |       '2018-01-01', | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |       null, | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |       7520 | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |     ); | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |     verify(userRepository.save( | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |       deepEqual(new User( | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |           'John', 'Doe', '[email protected]', '123456789', 'password', UserRole.COOPERATOR, updatedUserAdministrative | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |         ) | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |       ) | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |     )).once(); | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |     verify(userAdministrativeRepository.save(deepEqual(updatedUserAdministrative))).once(); | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |   }); | 
            
                                                        
            
                                    
            
            
                | 78 |  |  | }); | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |  |