102 lines
2.5 KiB
TypeScript
102 lines
2.5 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { CuestionarioPrograma2Controller } from './cuestionario-programa2.controller';
|
|
import { CuestionarioPrograma2Service } from './cuestionario-programa2.service';
|
|
import { findCuestionarioProgama2Dto } from './dto/find.dto';
|
|
import { CreateCuestionarioPrograma2Dto } from './dto/create-cuestionario-programa2.dto';
|
|
|
|
enum Version {
|
|
ACTIVO = 'v1',
|
|
INACTIVO = 'v2',
|
|
}
|
|
|
|
describe('CuestionarioAlumno2Controller', () => {
|
|
let controller: CuestionarioPrograma2Controller;
|
|
let service: CuestionarioPrograma2Service;
|
|
|
|
const mockService = {
|
|
create: jest.fn(),
|
|
getCuestionario: jest.fn(),
|
|
};
|
|
|
|
beforeEach(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
controllers: [CuestionarioPrograma2Controller],
|
|
providers: [
|
|
{
|
|
provide: CuestionarioPrograma2Service,
|
|
useValue: mockService,
|
|
},
|
|
],
|
|
}).compile();
|
|
|
|
controller = module.get<CuestionarioPrograma2Controller>(
|
|
CuestionarioPrograma2Controller,
|
|
);
|
|
service = module.get<CuestionarioPrograma2Service>(
|
|
CuestionarioPrograma2Service,
|
|
);
|
|
});
|
|
|
|
it('debería estar definido', () => {
|
|
expect(controller).toBeDefined();
|
|
});
|
|
|
|
it('debería crear un cuestionario', async () => {
|
|
const dto: CreateCuestionarioPrograma2Dto = {
|
|
idServicio: 1,
|
|
p1: 'A',
|
|
p2: 'B',
|
|
p4: 'C',
|
|
p5: 'D',
|
|
p6: 'A',
|
|
|
|
p3_A_1: 'A',
|
|
p3_A_2: 'B',
|
|
p3_A_3: 'C',
|
|
p3_A_4: 'D',
|
|
|
|
p3_B_1: 'A',
|
|
p3_B_2: 'B',
|
|
p3_B_3: 'C',
|
|
p3_B_4: 'D',
|
|
|
|
p3_C_1: 'A',
|
|
p3_C_2: 'B',
|
|
p3_C_3: 'C',
|
|
p3_C_4: 'D',
|
|
p3_C_5: 'A',
|
|
|
|
p3_D_1: 'A',
|
|
p3_D_2: 'B',
|
|
p3_D_3: 'C',
|
|
p3_D_4: 'D',
|
|
p3_D_5: 'A',
|
|
|
|
p3_E_1: 'B',
|
|
};
|
|
const result = { id: 1, ...dto };
|
|
|
|
mockService.create.mockResolvedValue(result);
|
|
|
|
expect(await controller.create(dto)).toEqual(result);
|
|
expect(service.create).toHaveBeenCalledWith(dto);
|
|
});
|
|
|
|
it('debería obtener cuestionarios filtrados', async () => {
|
|
const findDto: findCuestionarioProgama2Dto = {
|
|
version: Version.ACTIVO,
|
|
year: '2025',
|
|
};
|
|
|
|
const result = [
|
|
{ id: 1, id_alumno: 1, respuesta: 'A' },
|
|
{ id: 2, id_alumno: 2, respuesta: 'B' },
|
|
];
|
|
|
|
mockService.getCuestionario.mockResolvedValue(result);
|
|
|
|
expect(await controller.findAll(findDto)).toEqual(result);
|
|
expect(service.getCuestionario).toHaveBeenCalledWith(findDto);
|
|
});
|
|
});
|