Skip to content

Commit

Permalink
[FEATURE] Tagguer les certif Pix+ seules en V2 (PIX-14714)
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Oct 22, 2024
2 parents 13b0edd + 3ee9edc commit ed30727
Show file tree
Hide file tree
Showing 38 changed files with 369 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'lodash';

import { AlgorithmEngineVersion } from '../../../src/certification/shared/domain/models/AlgorithmEngineVersion.js';
import { databaseBuffer } from '../database-buffer.js';
import { buildSession } from './build-session.js';
import { buildUser } from './build-user.js';
Expand All @@ -22,7 +23,7 @@ const buildCertificationCourse = function ({
completedAt = new Date('2022-03-01'),
isPublished = true,
verificationCode = `P-${id}`.padEnd(10, '3'),
version = 2,
version = AlgorithmEngineVersion.V2,
userId,
sessionId,
maxReachableLevelOnCertificationDate = 5,
Expand Down
5 changes: 3 additions & 2 deletions api/lib/domain/events/handle-certification-rescoring.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssessmentResultFactory } from '../../../src/certification/scoring/domain/models/factories/AssessmentResultFactory.js';
import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js';
import { SessionVersion } from '../../../src/certification/shared/domain/models/SessionVersion.js';
import { V3_REPRODUCIBILITY_RATE } from '../../../src/shared/domain/constants.js';
import { CertificationComputeError } from '../../../src/shared/domain/errors.js';
import { CertificationResult } from '../../../src/shared/domain/models/CertificationResult.js';
Expand Down Expand Up @@ -43,7 +43,8 @@ async function handleCertificationRescoring({
certificationCourseId: event.certificationCourseId,
});

if (CertificationVersion.isV3(certificationAssessment.version)) {
// TODO: switch to certif-course version, not session
if (SessionVersion.isV3(certificationAssessment.version)) {
return _handleV3CertificationScoring({
certificationAssessment,
event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
* @typedef {import('./index.js').CertificationChallengesService} CertificationChallengesService
* @typedef {import('./index.js').VerifyCertificateCodeService} VerifyCertificateCodeService
* @typedef {import('./index.js').AssessmentRepository} AssessmentRepository
* @typedef {import('../../../src/shared/domain/models/CertificationCandidate.js').CertificationCandidate} CertificationCandidate
*/
import { SessionNotAccessible } from '../../../src/certification/session-management/domain/errors.js';
import { ComplementaryCertificationCourse } from '../../../src/certification/session-management/domain/models/ComplementaryCertificationCourse.js';
import { AlgorithmEngineVersion } from '../../../src/certification/shared/domain/models/AlgorithmEngineVersion.js';
import { CertificationCourse } from '../../../src/certification/shared/domain/models/CertificationCourse.js';
import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js';
import { SessionVersion } from '../../../src/certification/shared/domain/models/SessionVersion.js';
import { config } from '../../../src/shared/config.js';
import { LanguageNotSupportedError } from '../../../src/shared/domain/errors.js';
import {
Expand Down Expand Up @@ -91,10 +93,8 @@ const retrieveLastOrCreateCertificationCourse = async function ({
};
}

const { version } = session;

let lang;
if (CertificationVersion.isV3(version)) {
if (SessionVersion.isV3(session.version)) {
const user = await userRepository.get(userId);
const isUserLanguageValid = _validateUserLanguage(languageService, user.lang);

Expand All @@ -106,7 +106,7 @@ const retrieveLastOrCreateCertificationCourse = async function ({
}

return _startNewCertification({
sessionId,
session,
userId,
certificationCandidate,
locale,
Expand All @@ -117,13 +117,30 @@ const retrieveLastOrCreateCertificationCourse = async function ({
placementProfileService,
verifyCertificateCodeService,
certificationBadgesService,
version,
lang,
});
};

export { retrieveLastOrCreateCertificationCourse };

/**
* @param {Object} params
* @param {SessionVersion} params.sessionVersion
* @param {CertificationCandidate} params.certificationCandidate
* @returns {AlgorithmEngineVersion}
*/
function _selectCertificationAlgorithmEngine({ sessionVersion, certificationCandidate }) {
if (!SessionVersion.isV3(sessionVersion)) {
return AlgorithmEngineVersion.V2;
}

if (certificationCandidate.isEnrolledToComplementaryOnly()) {
return AlgorithmEngineVersion.V2;
}

return AlgorithmEngineVersion.V3;
}

function _validateUserLanguage(languageService, userLanguage) {
return CertificationCourse.isLanguageAvailableForV3Certification(languageService, userLanguage);
}
Expand Down Expand Up @@ -166,6 +183,7 @@ async function _blockCandidateFromRestartingWithoutExplicitValidation(

/**
* @param {Object} params
* @param {Session} params.session
* @param {CertificationCourseRepository} params.certificationCourseRepository
* @param {PlacementProfileService} params.placementProfileService
* @param {CertificationCenterRepository} params.certificationCenterRepository
Expand All @@ -175,7 +193,7 @@ async function _blockCandidateFromRestartingWithoutExplicitValidation(
* @param {VerifyCertificateCodeService} params.verifyCertificateCodeService
*/
async function _startNewCertification({
sessionId,
session,
userId,
certificationCandidate,
locale,
Expand All @@ -186,12 +204,11 @@ async function _startNewCertification({
placementProfileService,
certificationBadgesService,
verifyCertificateCodeService,
version,
lang,
}) {
const challengesForCertification = [];

const certificationCenter = await certificationCenterRepository.getBySessionId({ sessionId });
const certificationCenter = await certificationCenterRepository.getBySessionId({ sessionId: session.id });

const complementaryCertificationCourseData = [];

Expand Down Expand Up @@ -222,12 +239,18 @@ async function _startNewCertification({
}
}

const algorithmEngineVersion = _selectCertificationAlgorithmEngine({
sessionVersion: session.version,
certificationCandidate,
});

let challengesForPixCertification = [];
if (!CertificationVersion.isV3(version)) {

if (!AlgorithmEngineVersion.isV3(algorithmEngineVersion)) {
const placementProfile = await placementProfileService.getPlacementProfile({
userId,
limitDate: certificationCandidate.reconciledAt,
version,
version: algorithmEngineVersion,
});

challengesForPixCertification = await certificationChallengesService.pickCertificationChallenges(
Expand All @@ -242,7 +265,7 @@ async function _startNewCertification({
const certificationCourseCreatedMeanwhile = await _getCertificationCourseIfCreatedMeanwhile(
certificationCourseRepository,
userId,
sessionId,
session.id,
);
if (certificationCourseCreatedMeanwhile) {
return {
Expand All @@ -259,7 +282,7 @@ async function _startNewCertification({
certificationChallenges: challengesForCertification,
verifyCertificateCodeService,
complementaryCertificationCourseData,
version,
algorithmEngineVersion,
lang,
});
}
Expand All @@ -285,7 +308,7 @@ async function _createCertificationCourse({
userId,
certificationChallenges,
complementaryCertificationCourseData,
version,
algorithmEngineVersion,
lang,
}) {
const verificationCode = await verifyCertificateCodeService.generateCertificateVerificationCode();
Expand All @@ -299,7 +322,7 @@ async function _createCertificationCourse({
maxReachableLevelOnCertificationDate: features.maxReachableLevel,
complementaryCertificationCourses,
verificationCode,
version,
algorithmEngineVersion,
lang,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from 'lodash';

import { CERTIFICATION_CENTER_TYPES } from '../../../../shared/domain/constants.js';
import { SESSION_STATUSES } from '../../../shared/domain/constants.js';
import { CERTIFICATION_VERSIONS } from '../../../shared/domain/models/CertificationVersion.js';
import { SESSIONS_VERSIONS } from '../../../shared/domain/models/SessionVersion.js';

const INVIGILATOR_PASSWORD_LENGTH = 6;
const INVIGILATOR_PASSWORD_CHARS = '23456789bcdfghjkmpqrstvwxyBCDFGHJKMPQRSTVWXY!*?'.split('');
Expand All @@ -25,7 +25,7 @@ class SessionEnrolment {
certificationCandidates,
certificationCenterId,
invigilatorPassword,
version = CERTIFICATION_VERSIONS.V2,
version = SESSIONS_VERSIONS.V2,
createdBy,
finalizedAt,
} = {}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @typedef {import ("./index.js").SessionCodeService} SessionCodeService
*/

import { CERTIFICATION_VERSIONS } from '../../../shared/domain/models/CertificationVersion.js';
import { SESSIONS_VERSIONS } from '../../../shared/domain/models/SessionVersion.js';
import { SessionEnrolment } from '../models/SessionEnrolment.js';

/**
Expand All @@ -31,7 +31,7 @@ const createSession = async function ({
const { isV3Pilot, name: certificationCenterName } = await centerRepository.getById({
id: certificationCenterId,
});
const version = isV3Pilot ? CERTIFICATION_VERSIONS.V3 : CERTIFICATION_VERSIONS.V2;
const version = isV3Pilot ? SESSIONS_VERSIONS.V3 : SESSIONS_VERSIONS.V2;

const domainSession = new SessionEnrolment({
...session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.js';
import { NotFoundError } from '../../../../shared/domain/errors.js';
import { CERTIFICATION_VERSIONS } from '../../../shared/domain/models/CertificationVersion.js';
import { SESSIONS_VERSIONS } from '../../../shared/domain/models/SessionVersion.js';
import { Candidate } from '../models/Candidate.js';
import { SessionEnrolment } from '../models/SessionEnrolment.js';

Expand Down Expand Up @@ -76,7 +76,7 @@ function _hasCandidates(candidates) {
async function _saveNewSessionReturningId({ sessionRepository, sessionDTO, isV3Pilot }) {
const sessionToSave = new SessionEnrolment({
...sessionDTO,
version: isV3Pilot ? CERTIFICATION_VERSIONS.V3 : CERTIFICATION_VERSIONS.V2,
version: isV3Pilot ? SESSIONS_VERSIONS.V3 : SESSIONS_VERSIONS.V2,
});
return await sessionRepository.save({ session: sessionToSave });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
UserAlreadyLinkedToCandidateInSessionError,
} from '../../../../shared/domain/errors.js';
import { CertificationCourse } from '../../../shared/domain/models/CertificationCourse.js';
import { CertificationVersion } from '../../../shared/domain/models/CertificationVersion.js';
import { SessionVersion } from '../../../shared/domain/models/SessionVersion.js';

/**
* @param {Object} params
Expand Down Expand Up @@ -84,7 +84,7 @@ export const verifyCandidateIdentity = async ({
};

async function validateUserLanguage({ languageService, user, session }) {
if (CertificationVersion.isV3(session.version)) {
if (SessionVersion.isV3(session.version)) {
const isUserLanguageValid = CertificationCourse.isLanguageAvailableForV3Certification(languageService, user.lang);

if (!isUserLanguageValid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import _ from 'lodash';

import { UserNotAuthorizedToCertifyError } from '../../../../shared/domain/errors.js';
import { AssessmentResult } from '../../../../shared/domain/models/index.js';
import { CERTIFICATION_VERSIONS } from '../../../shared/domain/models/CertificationVersion.js';
import { SessionVersion } from '../../../shared/domain/models/SessionVersion.js';
import { CertificationCandidateEligibilityError } from '../errors.js';

/**
Expand Down Expand Up @@ -117,7 +117,7 @@ function _isSubscribedUserBadgeOutDated(subscribedBadgeAcquisition) {

function _doesNeedEligibilityCheck(session, candidate) {
return (
session.version === CERTIFICATION_VERSIONS.V3 &&
SessionVersion.isV3(session.version) &&
candidate.subscriptions.length === 1 &&
candidate.subscriptions[0]?.isComplementary()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as answerRepository from '../../../../shared/infrastructure/repositorie
import * as challengeRepository from '../../../../shared/infrastructure/repositories/challenge-repository.js';
import * as flashAlgorithmService from '../../../flash-certification/domain/services/algorithm-methods/flash.js';
import { assessmentResultRepository } from '../../../session-management/infrastructure/repositories/index.js';
import { CertificationVersion } from '../../../shared/domain/models/CertificationVersion.js';
import { AlgorithmEngineVersion } from '../../../shared/domain/models/AlgorithmEngineVersion.js';
import * as scoringCertificationService from '../../../shared/domain/services/scoring-certification-service.js';
import * as certificationAssessmentRepository from '../../../shared/infrastructure/repositories/certification-assessment-repository.js';
import * as certificationCourseRepository from '../../../shared/infrastructure/repositories/certification-course-repository.js';
Expand Down Expand Up @@ -67,7 +67,7 @@ export class CertificationCompletedJobController extends JobController {
const certificationAssessment = await certificationAssessmentRepository.get(assessmentId);
let certificationScoringCompletedEvent;

if (CertificationVersion.isV3(certificationAssessment.version)) {
if (AlgorithmEngineVersion.isV3(certificationAssessment.version)) {
certificationScoringCompletedEvent = await _handleV3CertificationScoring({
certificationAssessment,
locale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from 'lodash';

import { AnswerStatus } from '../../../../shared/domain/models/AnswerStatus.js';
import { validateEntity } from '../../../../shared/domain/validators/entity-validator.js';
import { CertificationVersion } from '../../../shared/domain/models/CertificationVersion.js';
import { AlgorithmEngineVersion } from '../../../shared/domain/models/AlgorithmEngineVersion.js';
import { ChallengeToBeDeneutralizedNotFoundError, ChallengeToBeNeutralizedNotFoundError } from '../errors.js';
import { CertificationAnswerStatusChangeAttempt } from './CertificationAnswerStatusChangeAttempt.js';
import { NeutralizationAttempt } from './NeutralizationAttempt.js';
Expand All @@ -29,7 +29,7 @@ const certificationAssessmentSchema = Joi.object({
.required(),
version: Joi.number()
.integer()
.valid(...Object.values(CertificationVersion))
.valid(...Object.values(AlgorithmEngineVersion))
.required(),
certificationChallenges: Joi.array().min(1).required(),
certificationAnswersByDate: Joi.array().min(0).required(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';

import { SESSION_STATUSES } from '../../../shared/domain/constants.js';
import { CERTIFICATION_VERSIONS } from '../../../shared/domain/models/CertificationVersion.js';
import { SESSIONS_VERSIONS } from '../../../shared/domain/models/SessionVersion.js';

const NO_EXAMINER_GLOBAL_COMMENT = null;

Expand All @@ -26,7 +26,7 @@ class SessionManagement {
certificationCenterId,
assignedCertificationOfficerId,
invigilatorPassword,
version = CERTIFICATION_VERSIONS.V2,
version = SESSIONS_VERSIONS.V2,
createdBy,
} = {}) {
this.id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @typedef {import('./index.js').PlacementProfileService} PlacementProfileService
* @typedef {import('./index.js').ScoringCertificationService} ScoringCertificationService
*/
import { CERTIFICATION_VERSIONS } from '../../../shared/domain/models/CertificationVersion.js';
import { CertificationDetails } from '../read-models/CertificationDetails.js';

/**
Expand Down Expand Up @@ -37,7 +36,7 @@ const getCertificationDetails = async function ({
const placementProfile = await placementProfileService.getPlacementProfile({
userId: candidate.userId,
limitDate: candidate.reconciledAt,
version: CERTIFICATION_VERSIONS.V2,
version: certificationAssessment.version,
allowExcessPixAndLevels: false,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Version of the certification algorithm used for candidate evaluation
* It applies to various things, but especially :
* - how are selected the challenges during a certification
* - how will be scored the certification
* @readonly
* @enum {number}
*/
export class AlgorithmEngineVersion {
static V1 = 1;
static V2 = 2;
static V3 = 3;

static isV1(version) {
return version === AlgorithmEngineVersion.V1;
}

static isV2(version) {
return version === AlgorithmEngineVersion.V2;
}

static isV3(version) {
return version === AlgorithmEngineVersion.V3;
}
}
Loading

0 comments on commit ed30727

Please sign in to comment.