import { Controller, {{ className }}Controller } from '@/application/controllers' import { ServerError, UnauthorizedError } from '@/application/errors' // import { Required } from 'library-validator' describe('{{ className }}Controller', () => { let sut: {{ className }}Controller let sutUseCase: jest.Mock const mockInput = { name: '' } const mockOutput = { success: true } beforeEach(() => { sutUseCase = jest.fn().mockResolvedValue(mockOutput) sut = new {{ className }}Controller(sutUseCase) }) it('should extend Controller', async () => { expect(sut).toBeInstanceOf({{ className }}Controller) }) it('should build Validators correctly on save', async () => { const validators = sut.buildValidators({ name: '' }) expect(validators).toEqual([ // new Required('', 'name') ]) }) it('should return 500 if fails new {{ className }}Controller', async () => { sutUseCase = jest.fn() sutUseCase.mockRejectedValueOnce(new Error()) sut = new {{ className }}Controller(sutUseCase) const httpResponse = await sut.handle(mockInput) expect(httpResponse).toEqual({ statusCode: 500, data: new ServerError() }) }) it('should return 200 if success new {{ className }}Controller', async () => { sut = new {{ className }}Controller(sutUseCase) const httpResponse = await sut.handle(mockInput) expect(httpResponse).toEqual({ statusCode: 200, data: mockOutput }) }) });