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

75 lines
2.0 KiB
TypeScript

import { Test, TestingModule } from '@nestjs/testing';
import { UsersRepository } from '../../adapters/secondaries/users.repository';
import { FindAllUsersRequest } from '../../domain/dtos/find-all-users.request';
import { FindAllUsersUseCase } from '../../domain/usecases/find-all-users.usecase';
import { FindAllUsersQuery } from '../../queries/find-all-users.query';
const findAllUsersRequest: FindAllUsersRequest = new FindAllUsersRequest();
findAllUsersRequest.page = 1;
findAllUsersRequest.perPage = 10;
const findAllUsersQuery: FindAllUsersQuery = new FindAllUsersQuery(
findAllUsersRequest,
);
const mockUsers = [
{
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
firstName: 'John',
lastName: 'Doe',
email: 'john.doe@email.com',
phone: '0601020304',
},
{
uuid: 'bb281075-1b98-4456-89d6-c643d3044a92',
firstName: 'Jane',
lastName: 'Doe',
email: 'jane.doe@email.com',
phone: '0602030405',
},
{
uuid: 'bb281075-1b98-4456-89d6-c643d3044a93',
firstName: 'Jimmy',
lastName: 'Doe',
email: 'jimmy.doe@email.com',
phone: '0603040506',
},
];
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(findAllUsersQuery);
expect(users).toBe(mockUsers);
});
});
});