format name, email, phone in mapper
This commit is contained in:
		
							parent
							
								
									ad185bec92
								
							
						
					
					
						commit
						7a462f4c4b
					
				| 
						 | 
				
			
			@ -11,8 +11,8 @@ const now = new Date('2023-06-21 06:00:00');
 | 
			
		|||
const userEntity: UserEntity = new UserEntity({
 | 
			
		||||
  id: 'c160cf8c-f057-4962-841f-3ad68346df44',
 | 
			
		||||
  props: {
 | 
			
		||||
    firstName: 'John',
 | 
			
		||||
    lastName: 'Doe',
 | 
			
		||||
    firstName: 'john',
 | 
			
		||||
    lastName: 'doe',
 | 
			
		||||
    email: 'john.doe@email.com',
 | 
			
		||||
    phone: '+33611223344',
 | 
			
		||||
  },
 | 
			
		||||
| 
						 | 
				
			
			@ -45,7 +45,7 @@ describe('User Mapper', () => {
 | 
			
		|||
 | 
			
		||||
  it('should map domain entity to persistence data', async () => {
 | 
			
		||||
    const mapped: UserWriteModel = userMapper.toPersistence(userEntity);
 | 
			
		||||
    expect(mapped.lastName).toBe('Doe');
 | 
			
		||||
    expect(mapped.lastName).toBe('doe');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should map persisted data to domain entity', async () => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,10 +36,16 @@ export class UserMapper
 | 
			
		|||
      createdAt: new Date(record.createdAt),
 | 
			
		||||
      updatedAt: new Date(record.updatedAt),
 | 
			
		||||
      props: {
 | 
			
		||||
        firstName: record.firstName,
 | 
			
		||||
        lastName: record.lastName,
 | 
			
		||||
        email: record.email,
 | 
			
		||||
        phone: record.phone,
 | 
			
		||||
        firstName: `${record.firstName
 | 
			
		||||
          ?.trim()
 | 
			
		||||
          .charAt(0)
 | 
			
		||||
          .toUpperCase()}${record.firstName?.trim().toLowerCase().slice(1)}`,
 | 
			
		||||
        lastName: `${record.lastName
 | 
			
		||||
          ?.trim()
 | 
			
		||||
          .charAt(0)
 | 
			
		||||
          .toUpperCase()}${record.lastName?.trim().toLowerCase().slice(1)}`,
 | 
			
		||||
        email: record.email?.trim().toLowerCase(),
 | 
			
		||||
        phone: record.phone?.trim(),
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
    return entity;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue