Skip to content

Commit

Permalink
✨ api: block rescoring on complementary certification only
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Jeremy authored Nov 14, 2024
1 parent 8a36fbb commit 68d6f1a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
9 changes: 6 additions & 3 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 { 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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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;
});
});
});
});

0 comments on commit 68d6f1a

Please sign in to comment.