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

64 lines
1.7 KiB
TypeScript

import { Test, TestingModule } from '@nestjs/testing';
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
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',
phone: '0601020304',
};
const mockUserRepository = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
findOneByUuid: jest.fn().mockImplementation((query?: FindUserByUuidQuery) => {
return Promise.resolve(mockUser);
}),
};
const mockMessager = {
publish: jest.fn().mockImplementation(),
};
describe('FindUserByUuidUseCase', () => {
let findUserByUuidUseCase: FindUserByUuidUseCase;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [],
providers: [
{
provide: UsersRepository,
useValue: mockUserRepository,
},
{
provide: LoggingMessager,
useValue: mockMessager,
},
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);
});
});
});