import { Test, TestingModule } from '@nestjs/testing'; import { UserController } from '../src/presentation/controllers/user.controller'; import { CreateUserUseCase } from '../src/application/use-cases/create-user.use-case'; describe('UserController', () => { let controller: UserController; let createUserUseCase: CreateUserUseCase; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ controllers: [UserController], providers: [ { provide: CreateUserUseCase, useValue: { execute: jest.fn(), }, }, ], }).compile(); controller = module.get(UserController); createUserUseCase = module.get(CreateUserUseCase); }); it('should be defined', () => { expect(controller).toBeDefined(); }); describe('create', () => { it('should create a new user', async () => { const createUserDto = { email: 'test@test.com', password: 'password123', name: 'Test User', otherName: 'Other Name', address: 'Test Address', telephone: '1234567890', }; const expectedResult = { id: 1, ...createUserDto, }; jest.spyOn(createUserUseCase, 'execute').mockResolvedValue(expectedResult); const result = await controller.create(createUserDto); expect(result).toEqual(expectedResult); expect(createUserUseCase.execute).toHaveBeenCalledWith(createUserDto); }); }); });