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', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a92', firstName: 'Jane', lastName: 'Doe', email: 'jane.doe@email.com', }, { uuid: 'bb281075-1b98-4456-89d6-c643d3044a93', firstName: 'Jimmy', lastName: 'Doe', email: 'jimmy.doe@email.com', }, ]; 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); }); 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); }); }); });