-
Notifications
You must be signed in to change notification settings - Fork 0
final tests implemented #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "Exam_Student" ALTER COLUMN "score" DROP NOT NULL; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,18 +1,258 @@ | ||||||||||
| import { Test, TestingModule } from '@nestjs/testing'; | ||||||||||
| import { ExamService } from './exam.service'; | ||||||||||
| import { PrismaService } from 'src/prisma/prisma.service'; | ||||||||||
| import { BadRequestException, NotFoundException } from '@nestjs/common'; | ||||||||||
|
|
||||||||||
| describe('ExamService', () => { | ||||||||||
| let service: ExamService; | ||||||||||
| let prismaMock: any; | ||||||||||
|
|
||||||||||
| beforeEach(async () => { | ||||||||||
| prismaMock = { | ||||||||||
| exam: { | ||||||||||
| create: jest.fn(), | ||||||||||
| findUnique: jest.fn(), | ||||||||||
| findMany: jest.fn(), | ||||||||||
| update: jest.fn(), | ||||||||||
| delete: jest.fn(), | ||||||||||
| }, | ||||||||||
| exam_Question: { | ||||||||||
| createMany: jest.fn(), | ||||||||||
| findMany: jest.fn(), | ||||||||||
| }, | ||||||||||
| question: { | ||||||||||
| findMany: jest.fn(), | ||||||||||
| }, | ||||||||||
| $transaction: jest.fn(), | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| const module: TestingModule = await Test.createTestingModule({ | ||||||||||
| providers: [ExamService], | ||||||||||
| providers: [ | ||||||||||
| ExamService, | ||||||||||
| { | ||||||||||
| provide: PrismaService, | ||||||||||
| useValue: prismaMock, | ||||||||||
| }, | ||||||||||
| ], | ||||||||||
| }).compile(); | ||||||||||
|
|
||||||||||
| service = module.get<ExamService>(ExamService); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('should be defined', () => { | ||||||||||
| expect(service).toBeDefined(); | ||||||||||
| // ============================================================ | ||||||||||
| // 🧪 CREATE | ||||||||||
| // ============================================================ | ||||||||||
|
|
||||||||||
| it('create debe crear un examen y asociar preguntas', async () => { | ||||||||||
| prismaMock.$transaction.mockImplementation(async (cb) => | ||||||||||
| cb({ | ||||||||||
| exam: { | ||||||||||
| create: jest.fn().mockResolvedValue({ id: 1 }), | ||||||||||
| findUnique: jest.fn().mockResolvedValue({ | ||||||||||
| id: 1, | ||||||||||
| exam_questions: [], | ||||||||||
| }), | ||||||||||
| }, | ||||||||||
| exam_Question: { | ||||||||||
| createMany: jest.fn(), | ||||||||||
| }, | ||||||||||
| }), | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| const result = await service.create( | ||||||||||
| { | ||||||||||
| name: 'Parcial', | ||||||||||
| status: 'Borrador', | ||||||||||
| difficulty: 'Media', | ||||||||||
| subject_id: 1, | ||||||||||
| teacher_id: 2, | ||||||||||
| parameters_id: 3, | ||||||||||
| head_teacher_id: 4, | ||||||||||
| }, | ||||||||||
| [10, 11], | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| expect(result?.id).toBe(1); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| // ============================================================ | ||||||||||
| // 🧪 GENERATED | ||||||||||
| // ============================================================ | ||||||||||
| it('generated debe insertar una nueva combinación válida', async () => { | ||||||||||
| prismaMock.question.findMany.mockResolvedValue([ | ||||||||||
| { id: 1, type: 'Multiple', subject_id: 1 }, | ||||||||||
| { id: 2, type: 'Multiple', subject_id: 1 }, | ||||||||||
| ]); | ||||||||||
|
|
||||||||||
| prismaMock.exam_Question.findMany.mockResolvedValue([ | ||||||||||
| { question_id: 1 }, // combinación previa distinta | ||||||||||
| ]); | ||||||||||
|
|
||||||||||
| prismaMock.exam_Question.createMany.mockResolvedValue({ count: 1 }); | ||||||||||
|
|
||||||||||
| const result = await service.generated({ | ||||||||||
| exam_id: 1, | ||||||||||
| subject_id: 1, | ||||||||||
| questionDistribution: [ | ||||||||||
| { type: 'Multiple', amount: 1 }, | ||||||||||
| ], | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| expect(prismaMock.exam_Question.createMany).toHaveBeenCalledWith({ | ||||||||||
| data: [{ exam_id: 1, question_id: expect.any(Number) }], | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| expect(result.questions_added).toBe(1); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
|
Comment on lines
+108
to
+109
|
||||||||||
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are extra blank lines (109) that serve no purpose and reduce code cleanliness. Consider removing these empty lines to improve code readability.
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra blank line here that's unnecessary. Consider removing it for consistency with the rest of the codebase.
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an extra blank line here that's unnecessary. Consider removing it for consistency with the rest of the codebase.
Copilot
AI
Dec 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All test descriptions in this file are written in Spanish (e.g., "debe crear un examen y asociar preguntas", "debe insertar una nueva combinación válida", "debe lanzar error si no hay suficientes preguntas"). These should be written in English to maintain consistency with the codebase conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a missing space after the
switchkeyword. The correct syntax isswitch (difficulty.toLowerCase())with a space betweenswitchand the opening parenthesis, following standard JavaScript/TypeScript formatting conventions.