2022-12-14 15:33:42 +00:00
|
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
|
|
import { UsersRepository } from '../../adapters/secondaries/users.repository';
|
2023-01-11 10:26:58 +00:00
|
|
|
import { FindAllUsersRequest } from '../../domain/dtos/find-all-users.request';
|
2022-12-14 15:33:42 +00:00
|
|
|
import { FindAllUsersUseCase } from '../../domain/usecases/find-all-users.usecase';
|
|
|
|
import { FindAllUsersQuery } from '../../queries/find-all-users.query';
|
|
|
|
|
2023-01-11 10:26:58 +00:00
|
|
|
const findAllUsersRequest: FindAllUsersRequest = new FindAllUsersRequest();
|
|
|
|
findAllUsersRequest.page = 1;
|
|
|
|
findAllUsersRequest.perPage = 10;
|
|
|
|
|
|
|
|
const findAllUsersQuery: FindAllUsersQuery = new FindAllUsersQuery(
|
|
|
|
findAllUsersRequest,
|
|
|
|
);
|
|
|
|
|
2022-12-14 15:33:42 +00:00
|
|
|
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 () => {
|
2023-01-11 10:26:58 +00:00
|
|
|
const users = await findAllUsersUseCase.execute(findAllUsersQuery);
|
2022-12-14 15:33:42 +00:00
|
|
|
|
|
|
|
expect(users).toBe(mockUsers);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|