user/src/modules/users/tests/unit/find-all-users.usecase.spec.ts

66 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-12-14 15:33:42 +00:00
import { Test, TestingModule } from '@nestjs/testing';
import { UsersRepository } from '../../adapters/secondaries/users.repository';
import { FindAllUsersUseCase } from '../../domain/usecases/find-all-users.usecase';
import { FindAllUsersQuery } from '../../queries/find-all-users.query';
const mockUsers = [
{
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-14 15:33:42 +00:00
},
{
uuid: 'bb281075-1b98-4456-89d6-c643d3044a92',
firstName: 'Jane',
lastName: 'Doe',
email: 'jane.doe@email.com',
2022-12-21 15:15:57 +00:00
phone: '0602030405',
2022-12-14 15:33:42 +00:00
},
{
uuid: 'bb281075-1b98-4456-89d6-c643d3044a93',
firstName: 'Jimmy',
lastName: 'Doe',
email: 'jimmy.doe@email.com',
2022-12-21 15:15:57 +00:00
phone: '0603040506',
2022-12-14 15:33:42 +00:00
},
];
const mockUsersRepository = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
findAll: jest.fn().mockImplementation((query?: FindAllUsersQuery) => {
return Promise.resolve(mockUsers);
}),
};
describe('FindAllUsersUseCase', () => {
let findAllUsersUseCase: FindAllUsersUseCase;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
{
provide: UsersRepository,
useValue: mockUsersRepository,
},
FindAllUsersUseCase,
],
}).compile();
findAllUsersUseCase = module.get<FindAllUsersUseCase>(FindAllUsersUseCase);
});
it('should be defined', () => {
expect(findAllUsersUseCase).toBeDefined();
});
describe('execute', () => {
it('should return an array filled with users', async () => {
const users = await findAllUsersUseCase.execute(new FindAllUsersQuery());
expect(users).toBe(mockUsers);
});
});
});