user/src/modules/users/tests/unit/find-user-by-uuid.usecase.s...

55 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-12-13 17:00:07 +00:00
import { Test, TestingModule } from '@nestjs/testing';
import { UsersRepository } from '../../adapters/secondaries/users.repository';
import { FindUserByUuidUseCase } from '../../domain/usecases/find-user-by-uuid.usecase';
import { FindUserByUuidQuery } from '../../queries/find-user-by-uuid.query';
const mockUser = {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
firstName: 'John',
lastName: 'Doe',
email: 'john.doe@email.com',
2022-12-21 15:15:57 +00:00
phone: '0601020304',
2022-12-13 17:00:07 +00:00
};
const mockUserRepository = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
findOneByUuid: jest.fn().mockImplementation((query?: FindUserByUuidQuery) => {
return Promise.resolve(mockUser);
}),
};
describe('FindUserByUuidUseCase', () => {
let findUserByUuidUseCase: FindUserByUuidUseCase;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [],
providers: [
{
provide: UsersRepository,
useValue: mockUserRepository,
},
FindUserByUuidUseCase,
],
}).compile();
findUserByUuidUseCase = module.get<FindUserByUuidUseCase>(
FindUserByUuidUseCase,
);
});
it('should be defined', () => {
expect(findUserByUuidUseCase).toBeDefined();
});
describe('execute', () => {
it('should return a user', async () => {
const user = await findUserByUuidUseCase.execute(
new FindUserByUuidQuery('bb281075-1b98-4456-89d6-c643d3044a91'),
);
expect(user).toBe(mockUser);
});
});
});