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

64 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-12-13 17:00:07 +00:00
import { Test, TestingModule } from '@nestjs/testing';
2022-12-23 14:14:51 +00:00
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
2022-12-13 17:00:07 +00:00
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);
}),
};
2022-12-23 14:14:51 +00:00
const mockMessager = {
publish: jest.fn().mockImplementation(),
};
2022-12-13 17:00:07 +00:00
describe('FindUserByUuidUseCase', () => {
let findUserByUuidUseCase: FindUserByUuidUseCase;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [],
providers: [
{
provide: UsersRepository,
useValue: mockUserRepository,
},
2022-12-23 14:14:51 +00:00
{
provide: LoggingMessager,
useValue: mockMessager,
},
2022-12-13 17:00:07 +00:00
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);
});
});
});