username mapper tests
This commit is contained in:
		
							parent
							
								
									8e1bfe68d5
								
							
						
					
					
						commit
						a95caefaf2
					
				| 
						 | 
				
			
			@ -0,0 +1,57 @@
 | 
			
		|||
import { UsernameEntity } from '@modules/authentication/core/domain/username.entity';
 | 
			
		||||
import { Type } from '@modules/authentication/core/domain/username.types';
 | 
			
		||||
import { UsernameModel } from '@modules/authentication/infrastructure/username.repository';
 | 
			
		||||
import { UsernameResponseDto } from '@modules/authentication/interface/dtos/username.response.dto';
 | 
			
		||||
import { UsernameMapper } from '@modules/authentication/username.mapper';
 | 
			
		||||
import { Test } from '@nestjs/testing';
 | 
			
		||||
 | 
			
		||||
const now = new Date('2023-06-21 06:00:00');
 | 
			
		||||
const usernameEntity: UsernameEntity = new UsernameEntity({
 | 
			
		||||
  id: 'john.doe@email.com',
 | 
			
		||||
  props: {
 | 
			
		||||
    userId: '7ca2490b-d04d-4ac5-8d6c-5c416fab922e',
 | 
			
		||||
    name: 'john.doe@email.com',
 | 
			
		||||
    type: Type.EMAIL,
 | 
			
		||||
  },
 | 
			
		||||
  createdAt: now,
 | 
			
		||||
  updatedAt: now,
 | 
			
		||||
});
 | 
			
		||||
const usernameModel: UsernameModel = {
 | 
			
		||||
  authUuid: '7ca2490b-d04d-4ac5-8d6c-5c416fab922e',
 | 
			
		||||
  username: 'john.doe@email.com',
 | 
			
		||||
  type: Type.EMAIL,
 | 
			
		||||
  createdAt: now,
 | 
			
		||||
  updatedAt: now,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
describe('Username Mapper', () => {
 | 
			
		||||
  let usernameMapper: UsernameMapper;
 | 
			
		||||
 | 
			
		||||
  beforeAll(async () => {
 | 
			
		||||
    const module = await Test.createTestingModule({
 | 
			
		||||
      providers: [UsernameMapper],
 | 
			
		||||
    }).compile();
 | 
			
		||||
    usernameMapper = module.get<UsernameMapper>(UsernameMapper);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should be defined', () => {
 | 
			
		||||
    expect(usernameMapper).toBeDefined();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should map domain entity to persistence data', async () => {
 | 
			
		||||
    const mapped: UsernameModel = usernameMapper.toPersistence(usernameEntity);
 | 
			
		||||
    expect(mapped.username).toBe('john.doe@email.com');
 | 
			
		||||
    expect(mapped.type).toBe(Type.EMAIL);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should map persisted data to domain entity', async () => {
 | 
			
		||||
    const mapped: UsernameEntity = usernameMapper.toDomain(usernameModel);
 | 
			
		||||
    expect(mapped.getProps().name).toBe('john.doe@email.com');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should map domain entity to response', async () => {
 | 
			
		||||
    const mapped: UsernameResponseDto =
 | 
			
		||||
      usernameMapper.toResponse(usernameEntity);
 | 
			
		||||
    expect(mapped.id).toBe('john.doe@email.com');
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
		Loading…
	
		Reference in New Issue