Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { CandidateModule } from './candidate/candidate.module';
import { LoggingModule } from './common/logging.module';
import { HttpLoggerMiddleware } from './common/middlewares/http-logger.middleware';
import { CvScoringModule } from './cv-scoring/cv-scoring.module';
import { ValidationModule } from './validation/validation.module';

import { DatabaseModule } from './database/database.module';
import { EnrollmentModule } from './enrollment/enrollment.module';
import { validate } from './env.validation';
Expand Down Expand Up @@ -55,6 +57,7 @@ import { UsersModule } from './users/users.module';
SystemModule,
EnrollmentModule,
CvScoringModule,
ValidationModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
40 changes: 40 additions & 0 deletions src/cv-scoring/cv-item.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,46 @@ describe('CvItemService', () => {
}),
).rejects.toThrow(BadRequestException);
});

it('updates score field (including null)', async () => {
const updatedWithScore = { ...mockCvItem, score: 7.5 };
const updatedWithNullScore = { ...mockCvItem, score: null };

// Test with numeric score
mockCvItemRepository.findEnrollmentById.mockResolvedValueOnce(mockEnrollment); // getAndValidateEnrollment
mockCvItemRepository.findById.mockResolvedValueOnce(mockCvItem); // findById
mockCvItemRepository.update.mockResolvedValueOnce(updatedWithScore); // update
mockCvItemRepository.findEnrollmentById.mockResolvedValueOnce(mockEnrollment); // recalculateScore → getEnrollment
mockCvItemRepository.findByEnrollment.mockResolvedValueOnce([updatedWithScore]); // recalculateScore → findByEnrollment

let result = await service.update('user-uuid', 'enrollment-uuid', 'item-uuid', {
score: 7.5,
});

expect(result.score).toBe(7.5);
expect(mockCvItemRepository.update).toHaveBeenCalledWith(
'item-uuid',
expect.objectContaining({ score: 7.5 }),
);

// Reset mock call counts
mockCvItemRepository.update.mockClear();

// Test with null score
mockCvItemRepository.findEnrollmentById.mockResolvedValueOnce(mockEnrollment);
mockCvItemRepository.findById.mockResolvedValueOnce(mockCvItem);
mockCvItemRepository.update.mockResolvedValueOnce(updatedWithNullScore);
mockCvItemRepository.findEnrollmentById.mockResolvedValueOnce(mockEnrollment);
mockCvItemRepository.findByEnrollment.mockResolvedValueOnce([updatedWithNullScore]);

result = await service.update('user-uuid', 'enrollment-uuid', 'item-uuid', { score: null });

expect(result.score).toBeNull();
expect(mockCvItemRepository.update).toHaveBeenCalledWith(
'item-uuid',
expect.objectContaining({ score: null }),
);
});
});

describe('remove', () => {
Expand Down
1 change: 1 addition & 0 deletions src/cv-scoring/cv-item.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class CvItemService {
if (dto.isInArea !== undefined) updateData.isInArea = dto.isInArea;
if (dto.docenciaType !== undefined) updateData.docenciaType = dto.docenciaType;
if (dto.eventoType !== undefined) updateData.eventoType = dto.eventoType;
if (dto.score !== undefined) updateData.score = dto.score;

if (file) {
if (existingItem.proofFileId) {
Expand Down
11 changes: 10 additions & 1 deletion src/cv-scoring/dto/update-cv-item.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { PartialType } from '@nestjs/swagger';
import { CreateCvItemDto } from './create-cv-item.dto';

export class UpdateCvItemDto extends PartialType(CreateCvItemDto) {}
import { IsNumber, IsOptional } from 'class-validator';

import { ApiPropertyOptional } from '@nestjs/swagger';

export class UpdateCvItemDto extends PartialType(CreateCvItemDto) {
@ApiPropertyOptional()
@IsOptional()
@IsNumber()
score?: number | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface UpdateCvItemData {
correctedClassification?: string | null;
verificationComment?: string | null;
updatedAt: Date;
score?: number | null;
}

export abstract class CvItemRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class CvItemDrizzleRepository extends CvItemRepository {
updateData.correctedClassification = data.correctedClassification;
if (data.verificationComment !== undefined)
updateData.verificationComment = data.verificationComment;
if (data.score !== undefined) updateData.score = data.score;

const [row] = await this.db
.update(cvItems)
Expand Down
67 changes: 67 additions & 0 deletions src/validation/validation.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import { SessionAuthGuard } from '../auth/guards/session-auth.guard';
import { SessionLifecycleGuard } from '../auth/guards/session-lifecycle.guard';
import { RolesGuard } from '../roles/roles.guard';
import { ValidationController } from './validation.controller';
import { ValidationService } from './validation.service';

describe('ValidationController', () => {
let controller: ValidationController;
let service: ValidationService;

const mockValidationService = {
getCandidatesForDashboard: jest.fn(),
getValidationStats: jest.fn(),
};

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ValidationController],
providers: [
{
provide: ValidationService,
useValue: mockValidationService,
},
],
})
.overrideGuard(SessionAuthGuard)
.useValue({ canActivate: jest.fn().mockReturnValue(true) })
.overrideGuard(SessionLifecycleGuard)
.useValue({ canActivate: jest.fn().mockReturnValue(true) })
.overrideGuard(RolesGuard)
.useValue({ canActivate: jest.fn().mockReturnValue(true) })
.compile();

controller = module.get<ValidationController>(ValidationController);
service = module.get<ValidationService>(ValidationService);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});

describe('getCandidates', () => {
it('should call validationService.getCandidatesForDashboard', async () => {
const mockResult = [{ id: '1' }];
mockValidationService.getCandidatesForDashboard.mockResolvedValue(mockResult);

const result = await controller.getCandidates();

expect(mockValidationService.getCandidatesForDashboard).toHaveBeenCalled();
expect(result).toEqual(mockResult);
});
});

describe('getStats', () => {
it('should call validationService.getValidationStats', async () => {
const mockResult = { total: 10, validated: 5, pending: 3 };
mockValidationService.getValidationStats.mockResolvedValue(mockResult);

const result = await controller.getStats();

expect(mockValidationService.getValidationStats).toHaveBeenCalled();
expect(result).toEqual(mockResult);
});
});
});
29 changes: 29 additions & 0 deletions src/validation/validation.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Controller, Get, UseGuards } from '@nestjs/common';

import { ApiCookieAuth, ApiTags } from '@nestjs/swagger';

import { SessionAuthGuard } from '../auth/guards/session-auth.guard';
import { SessionLifecycleGuard } from '../auth/guards/session-lifecycle.guard';
import { StaffOnly } from '../roles/roles.decorator';

import { ValidationService } from './validation.service';

@ApiTags('Validation')
@ApiCookieAuth()
@UseGuards(SessionAuthGuard, SessionLifecycleGuard)
@Controller({ path: 'validation', version: '1' })
export class ValidationController {
constructor(private readonly validationService: ValidationService) {}

@Get('candidates')
@StaffOnly()
async getCandidates() {
return this.validationService.getCandidatesForDashboard();
}

@Get('stats')
@StaffOnly()
async getStats() {
return this.validationService.getValidationStats();
}
}
9 changes: 9 additions & 0 deletions src/validation/validation.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { ValidationController } from './validation.controller';
import { ValidationService } from './validation.service';

@Module({
controllers: [ValidationController],
providers: [ValidationService],
})
export class ValidationModule {}
Loading
Loading