From 68d6f1af565ccfdf39c5131fcdfb4c2b96676d4e Mon Sep 17 00:00:00 2001 From: P-Jeremy Date: Thu, 14 Nov 2024 14:26:39 +0100 Subject: [PATCH] :sparkles: api: block rescoring on complementary certification only --- .../events/handle-certification-rescoring.js | 9 ++-- .../handle-certification-rescoring_test.js | 51 ++++++++++++++++--- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/api/lib/domain/events/handle-certification-rescoring.js b/api/lib/domain/events/handle-certification-rescoring.js index 3a68ecc08f9..e3f121f6ce8 100644 --- a/api/lib/domain/events/handle-certification-rescoring.js +++ b/api/lib/domain/events/handle-certification-rescoring.js @@ -1,5 +1,5 @@ import { AssessmentResultFactory } from '../../../src/certification/scoring/domain/models/factories/AssessmentResultFactory.js'; -import { SessionVersion } from '../../../src/certification/shared/domain/models/SessionVersion.js'; +import { AlgorithmEngineVersion } from '../../../src/certification/shared/domain/models/AlgorithmEngineVersion.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'; @@ -35,8 +35,11 @@ async function handleCertificationRescoring({ certificationCourseId: event.certificationCourseId, }); - // TODO: switch to certif-course version, not session - if (SessionVersion.isV3(certificationAssessment.version)) { + if (certificationAssessment.isScoringBlockedDueToComplementaryOnlyChallenges) { + return; + } + + if (AlgorithmEngineVersion.isV3(certificationAssessment.version)) { return _handleV3CertificationScoring({ certificationAssessment, event, diff --git a/api/tests/unit/domain/events/handle-certification-rescoring_test.js b/api/tests/unit/domain/events/handle-certification-rescoring_test.js index e14a3f84751..819604efaa5 100644 --- a/api/tests/unit/domain/events/handle-certification-rescoring_test.js +++ b/api/tests/unit/domain/events/handle-certification-rescoring_test.js @@ -4,8 +4,8 @@ import { ChallengeDeneutralized } from '../../../../lib/domain/events/ChallengeD import { ChallengeNeutralized } from '../../../../lib/domain/events/ChallengeNeutralized.js'; import { _forTestOnly } from '../../../../lib/domain/events/index.js'; import { CertificationAssessment } from '../../../../src/certification/session-management/domain/models/CertificationAssessment.js'; +import { AlgorithmEngineVersion } from '../../../../src/certification/shared/domain/models/AlgorithmEngineVersion.js'; import { ABORT_REASONS } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; -import { SESSIONS_VERSIONS } from '../../../../src/certification/shared/domain/models/SessionVersion.js'; import { CertificationComputeError } from '../../../../src/shared/domain/errors.js'; import { AssessmentResult, CertificationResult } from '../../../../src/shared/domain/models/index.js'; import { domainBuilder, expect, sinon } from '../../../test-helper.js'; @@ -55,7 +55,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () it('should save the score with a rejected status', async function () { // given const certificationAssessment = domainBuilder.buildCertificationAssessment({ - version: SESSIONS_VERSIONS.V3, + version: AlgorithmEngineVersion.V3, }); const abortedCertificationCourse = domainBuilder.buildCertificationCourse({ abortReason: ABORT_REASONS.CANDIDATE, @@ -91,7 +91,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () it('should save the score with a rejected status and cancel the certification course', async function () { // given const certificationAssessment = domainBuilder.buildCertificationAssessment({ - version: SESSIONS_VERSIONS.V3, + version: AlgorithmEngineVersion.V3, }); const abortedCertificationCourse = domainBuilder.buildCertificationCourse({ @@ -142,7 +142,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () // given const certificationCourseStartDate = new Date('2022-01-01'); const certificationAssessment = domainBuilder.buildCertificationAssessment({ - version: SESSIONS_VERSIONS.V3, + version: AlgorithmEngineVersion.V3, }); const abortedCertificationCourse = domainBuilder.buildCertificationCourse({ @@ -183,7 +183,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () // given const certificationCourseStartDate = new Date('2022-01-01'); const certificationAssessment = domainBuilder.buildCertificationAssessment({ - version: SESSIONS_VERSIONS.V3, + version: AlgorithmEngineVersion.V3, }); const abortedCertificationCourse = domainBuilder.buildCertificationCourse({ @@ -221,7 +221,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () const certificationCourseStartDate = new Date('2022-01-01'); // given const certificationAssessment = domainBuilder.buildCertificationAssessment({ - version: SESSIONS_VERSIONS.V3, + version: AlgorithmEngineVersion.V3, }); const abortedCertificationCourse = domainBuilder.buildCertificationCourse({ @@ -748,5 +748,44 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () expect(assessmentResultRepository.save).to.have.been.calledOnce; }); }); + + context('when assessment in only about complementary certification', function () { + it('should return', async function () { + // given + const event = new ChallengeNeutralized({ certificationCourseId: 1, juryId: 7 }); + const certificationAssessment = new CertificationAssessment({ + id: 123, + userId: 123, + certificationCourseId: 789, + createdAt: new Date('2020-01-01'), + completedAt: new Date('2020-01-01'), + state: CertificationAssessment.states.STARTED, + version: AlgorithmEngineVersion.V2, + certificationChallenges: [ + domainBuilder.buildCertificationChallengeWithType({ certifiableBadgeKey: 'TOTO' }), + domainBuilder.buildCertificationChallengeWithType({ certifiableBadgeKey: 'TOTO' }), + ], + certificationAnswersByDate: ['answer'], + }); + certificationAssessmentRepository.getByCertificationCourseId + .withArgs({ certificationCourseId: 1 }) + .resolves(certificationAssessment); + + // when + await handleCertificationRescoring({ + event, + assessmentResultRepository, + certificationAssessmentRepository, + competenceMarkRepository, + scoringCertificationService, + certificationEvaluationServices, + certificationCourseRepository, + }); + + // then + expect(certificationEvaluationServices.handleV2CertificationScoring).to.not.have.been.called; + expect(assessmentResultRepository.save).to.not.have.been.called; + }); + }); }); });