| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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>(UserController);
- createUserUseCase = module.get<CreateUserUseCase>(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);
- });
- });
- });
|