Skip to content

Commit

Permalink
✨ feat(api): create cancel assessment result for V3 certif
Browse files Browse the repository at this point in the history
Co-authored-by: Andreia Pena <[email protected]>
Co-authored-by: Steph0 <[email protected]>
Co-authored-by: Alexandre Coin <[email protected]>
  • Loading branch information
4 people committed Jan 16, 2025
1 parent 76e6984 commit 6c80303
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
import Debug from 'debug';

import CertificationCancelled from '../../../../../../lib/domain/events/CertificationCancelled.js';
import { config } from '../../../../../shared/config.js';
import { CompetenceMark } from '../../../../../shared/domain/models/index.js';
import { FlashAssessmentAlgorithm } from '../../../../flash-certification/domain/models/FlashAssessmentAlgorithm.js';
Expand Down Expand Up @@ -58,6 +59,8 @@ export const handleV3CertificationScoring = async ({
const candidateAnswers = await answerRepository.findByAssessment(assessmentId);
debugScoringForV3Certification(`CandidateAnswers count: ${candidateAnswers.length}`);

const isCancelled = event instanceof CertificationCancelled;

const { allChallenges, askedChallenges, challengeCalibrations } = await dependencies.findByCertificationCourseId({
certificationCourseId,
});
Expand Down Expand Up @@ -93,6 +96,7 @@ export const handleV3CertificationScoring = async ({
});

const assessmentResult = await _createV3AssessmentResult({
isCancelled,
allAnswers: candidateAnswers,
emitter,
certificationAssessment,
Expand Down Expand Up @@ -125,13 +129,24 @@ export const handleV3CertificationScoring = async ({
};

function _createV3AssessmentResult({
isCancelled,
allAnswers,
emitter,
certificationAssessment,
certificationAssessmentScore,
certificationCourse,
juryId,
}) {
if (isCancelled) {
return AssessmentResultFactory.buildCancelledAssessmentResult({
juryId,
pixScore: certificationAssessmentScore.nbPix,
reproducibilityRate: certificationAssessmentScore.getPercentageCorrectAnswers(),
assessmentId: certificationAssessment.id,
emitter,
});
}

if (certificationCourse.isRejectedForFraud()) {
return AssessmentResultFactory.buildFraud({
pixScore: certificationAssessmentScore.nbPix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import CertificationCancelled from '../../../../../lib/domain/events/CertificationCancelled.js';
import { SessionAlreadyFinalizedError } from '../errors.js';
import { NotFinalizedSessionError } from '../../../../shared/domain/errors.js';

/**
* @param {Object} params
Expand All @@ -20,10 +20,9 @@ export const cancelCertificationCourse = async function ({
sessionRepository,
}) {
const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId });
const session = await sessionRepository.get({ id: certificationCourse.id });

if (session.isFinalized) {
throw new SessionAlreadyFinalizedError();
const session = await sessionRepository.get({ id: certificationCourse.getSessionId() });
if (!session.isFinalized) {
throw new NotFinalizedSessionError();
}

certificationCourse.cancel();
Expand Down
6 changes: 3 additions & 3 deletions api/src/shared/domain/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,8 @@ class AuditLoggerApiError extends DomainError {
}
}

class NotFinalizedCertificationError extends DomainError {
constructor(message) {
class NotFinalizedSessionError extends DomainError {
constructor(message = 'A certification course cannot be cancelled while session has not been finalized.') {
super(message);
}
}
Expand Down Expand Up @@ -1128,7 +1128,7 @@ export {
NoSkillsInCampaignError,
NoStagesForCampaign,
NotEnoughDaysPassedBeforeResetCampaignParticipationError,
NotFinalizedCertificationError,
NotFinalizedSessionError,
NotFoundError,
NotImplementedError,
ObjectValidationError,
Expand Down
4 changes: 2 additions & 2 deletions api/src/shared/domain/models/AssessmentResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @typedef {import('../../../certification/shared/domain/models/CompetenceMark.js').CompetenceMark} CompetenceMark
* @typedef {import('../../../certification/shared/domain/models/JuryComment.js').JuryComment} JuryComment
*/
import { NotFinalizedCertificationError } from '../errors.js';
import { NotFinalizedSessionError } from '../errors.js';
import { Assessment } from './Assessment.js';

/**
Expand Down Expand Up @@ -105,7 +105,7 @@ class AssessmentResult {

cancel() {
if (!Object.values(AssessmentResult.status).includes(this.status)) {
throw new NotFinalizedCertificationError('A certification cannot be cancelled if it has not been finalized.');
throw new NotFinalizedSessionError();
}
this.status = AssessmentResult.status.CANCELLED;
}
Expand Down
Loading

0 comments on commit 6c80303

Please sign in to comment.