diff --git a/api/lib/application/preHandlers/authorization.js b/api/lib/application/preHandlers/authorization.js index 425d753b655..1ed915efcf0 100644 --- a/api/lib/application/preHandlers/authorization.js +++ b/api/lib/application/preHandlers/authorization.js @@ -21,7 +21,7 @@ const verifyCertificationSessionAuthorization = async ( const userId = request.auth.credentials.userId; const certificationCourseId = request.params.id; - const sessionId = await dependencies.certificationCourseRepository.getSessionId(certificationCourseId); + const sessionId = await dependencies.certificationCourseRepository.getSessionId({ id: certificationCourseId }); return _isAuthorizedToAccessSession({ userId, @@ -35,10 +35,10 @@ const authorization = { verifySessionAuthorization, verifyCertificationSessionAu export { authorization, verifyCertificationSessionAuthorization, verifySessionAuthorization }; async function _isAuthorizedToAccessSession({ userId, sessionId, sessionRepository }) { - const hasMembershipAccess = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession( + const hasMembershipAccess = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession({ userId, sessionId, - ); + }); if (!hasMembershipAccess) { throw new NotFoundError( diff --git a/api/lib/application/usecases/checkUserIsMemberOfCertificationCenterSession.js b/api/lib/application/usecases/checkUserIsMemberOfCertificationCenterSession.js index 06510a00dab..7bc55ec3e3b 100644 --- a/api/lib/application/usecases/checkUserIsMemberOfCertificationCenterSession.js +++ b/api/lib/application/usecases/checkUserIsMemberOfCertificationCenterSession.js @@ -6,11 +6,11 @@ const execute = async function ({ certificationCourseId, dependencies = { certificationCourseRepository, sessionRepository }, }) { - const certificationCourse = await dependencies.certificationCourseRepository.get(certificationCourseId); - return dependencies.sessionRepository.doesUserHaveCertificationCenterMembershipForSession( + const certificationCourse = await dependencies.certificationCourseRepository.get({ id: certificationCourseId }); + return dependencies.sessionRepository.doesUserHaveCertificationCenterMembershipForSession({ userId, - certificationCourse.getSessionId(), - ); + sessionId: certificationCourse.getSessionId(), + }); }; export { execute }; diff --git a/api/lib/application/usecases/checkUserOwnsCertificationCourse.js b/api/lib/application/usecases/checkUserOwnsCertificationCourse.js index 67d02215076..7302fe5ff74 100644 --- a/api/lib/application/usecases/checkUserOwnsCertificationCourse.js +++ b/api/lib/application/usecases/checkUserOwnsCertificationCourse.js @@ -1,7 +1,7 @@ import * as certificationCourseRepository from '../../../src/certification/shared/infrastructure/repositories/certification-course-repository.js'; const execute = async function ({ userId, certificationCourseId, dependencies = { certificationCourseRepository } }) { - const certificationCourse = await dependencies.certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await dependencies.certificationCourseRepository.get({ id: certificationCourseId }); return certificationCourse.doesBelongTo(userId); }; diff --git a/api/lib/domain/events/handle-auto-jury.js b/api/lib/domain/events/handle-auto-jury.js index c754acd7eb1..304e317da7a 100644 --- a/api/lib/domain/events/handle-auto-jury.js +++ b/api/lib/domain/events/handle-auto-jury.js @@ -1,6 +1,6 @@ import bluebird from 'bluebird'; -import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js'; +import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js'; import { CertificationIssueReportResolutionAttempt } from '../models/CertificationIssueReportResolutionAttempt.js'; import { CertificationIssueReportResolutionStrategies } from '../models/CertificationIssueReportResolutionStrategies.js'; import { CertificationAssessment } from '../models/index.js'; @@ -177,9 +177,9 @@ async function _autoResolveCertificationIssueReport({ resolutionStrategies, logger, }) { - const certificationIssueReports = await certificationIssueReportRepository.findByCertificationCourseId( - certificationCourse.getId(), - ); + const certificationIssueReports = await certificationIssueReportRepository.findByCertificationCourseId({ + certificationCourseId: certificationCourse.getId(), + }); if (certificationIssueReports.length === 0) { return null; } diff --git a/api/lib/domain/events/handle-certification-rescoring.js b/api/lib/domain/events/handle-certification-rescoring.js index 4f1ddeac8b3..ec204323963 100644 --- a/api/lib/domain/events/handle-certification-rescoring.js +++ b/api/lib/domain/events/handle-certification-rescoring.js @@ -4,10 +4,10 @@ import { FlashAssessmentAlgorithm } from '../../../src/certification/flash-certi import { CertificationAssessmentHistory } from '../../../src/certification/scoring/domain/models/CertificationAssessmentHistory.js'; import { CertificationAssessmentScoreV3 } from '../../../src/certification/scoring/domain/models/CertificationAssessmentScoreV3.js'; import { AssessmentResultFactory } from '../../../src/certification/scoring/domain/models/factories/AssessmentResultFactory.js'; +import { ABORT_REASONS } from '../../../src/certification/shared/domain/models/CertificationCourse.js'; +import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js'; import { config } from '../../../src/shared/config.js'; -import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js'; import { CertificationComputeError } from '../errors.js'; -import { ABORT_REASONS } from '../models/CertificationCourse.js'; import { CertificationResult } from '../models/CertificationResult.js'; import { CompetenceMark } from '../models/CompetenceMark.js'; import { AssessmentResult } from '../models/index.js'; @@ -107,7 +107,9 @@ async function _handleV3Certification({ { certificationCourseId: certificationAssessment.certificationCourseId }, ); - const certificationCourse = await certificationCourseRepository.get(certificationAssessment.certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ + id: certificationAssessment.certificationCourseId, + }); const abortReason = certificationCourse.isAbortReasonCandidateRelated() ? ABORT_REASONS.CANDIDATE @@ -221,7 +223,9 @@ async function _handleV2Certification({ continueOnError: false, }); const emitter = _getEmitterFromEvent(event); - const certificationCourse = await certificationCourseRepository.get(certificationAssessment.certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ + id: certificationAssessment.certificationCourseId, + }); const assessmentResult = _createV2AssessmentResult({ event, emitter, @@ -256,14 +260,14 @@ async function _cancelCertificationCourseIfHasNotEnoughNonNeutralizedChallengesT hasEnoughNonNeutralizedChallengesToBeTrusted, certificationCourseRepository, }) { - const certificationCourse = await certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId }); if (hasEnoughNonNeutralizedChallengesToBeTrusted) { certificationCourse.uncancel(); } else { certificationCourse.cancel(); } - return certificationCourseRepository.update(certificationCourse); + return certificationCourseRepository.update({ certificationCourse }); } async function _saveResultAfterCertificationComputeError({ @@ -417,7 +421,7 @@ async function _cancelCertificationCourseIfV3CertificationLackOfAnswersForTechni }) { if (_shouldCancelWhenV3CertificationLacksOfAnswersForTechnicalReason({ allAnswers, certificationCourse })) { certificationCourse.cancel(); - await certificationCourseRepository.update(certificationCourse); + await certificationCourseRepository.update({ certificationCourse }); } } diff --git a/api/lib/domain/events/handle-certification-scoring.js b/api/lib/domain/events/handle-certification-scoring.js index af5205f8a79..9be4cbdb809 100644 --- a/api/lib/domain/events/handle-certification-scoring.js +++ b/api/lib/domain/events/handle-certification-scoring.js @@ -4,10 +4,10 @@ import { FlashAssessmentAlgorithm } from '../../../src/certification/flash-certi import { CertificationAssessmentHistory } from '../../../src/certification/scoring/domain/models/CertificationAssessmentHistory.js'; import { CertificationAssessmentScoreV3 } from '../../../src/certification/scoring/domain/models/CertificationAssessmentScoreV3.js'; import { AssessmentResultFactory } from '../../../src/certification/scoring/domain/models/factories/AssessmentResultFactory.js'; +import { ABORT_REASONS } from '../../../src/certification/shared/domain/models/CertificationCourse.js'; +import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js'; import { config } from '../../../src/shared/config.js'; -import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js'; import { CertificationComputeError } from '../errors.js'; -import { ABORT_REASONS } from '../models/CertificationCourse.js'; import { CompetenceMark } from '../models/CompetenceMark.js'; import { AssessmentResult } from '../models/index.js'; import { AssessmentCompleted } from './AssessmentCompleted.js'; @@ -78,7 +78,9 @@ async function _handleV2CertificationScoring({ certificationAssessment, continueOnError: false, }); - const certificationCourse = await certificationCourseRepository.get(certificationAssessment.certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ + id: certificationAssessment.certificationCourseId, + }); certificationCourse.complete({ now: new Date() }); const assessmentResult = await _createV2AssessmentResult({ certificationAssessment, @@ -132,7 +134,7 @@ async function _handleV3CertificationScoring({ certificationCourseId, }); - const certificationCourse = await certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId }); const abortReason = certificationCourse.isAbortReasonCandidateRelated() ? ABORT_REASONS.CANDIDATE @@ -228,7 +230,7 @@ async function _saveV2Result({ }); await _saveCompetenceMarks({ certificationAssessmentScore, newAssessmentResult, competenceMarkRepository }); - return certificationCourseRepository.update(certificationCourse); + return certificationCourseRepository.update({ certificationCourse }); } async function _saveV3Result({ @@ -252,7 +254,7 @@ async function _saveV3Result({ }); return competenceMarkRepository.save(competenceMarkDomain); }); - return certificationCourseRepository.update(certificationCourse); + return certificationCourseRepository.update({ certificationCourse }); } function _createV2AssessmentResult({ certificationAssessment, certificationAssessmentScore }) { @@ -325,7 +327,9 @@ async function _saveResultAfterCertificationComputeError({ certificationCourseRepository, certificationComputeError, }) { - const certificationCourse = await certificationCourseRepository.get(certificationAssessment.certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ + id: certificationAssessment.certificationCourseId, + }); const assessmentResult = AssessmentResultFactory.buildAlgoErrorResult({ error: certificationComputeError, assessmentId: certificationAssessment.id, @@ -336,7 +340,7 @@ async function _saveResultAfterCertificationComputeError({ assessmentResult, }); certificationCourse.complete({ now: new Date() }); - return certificationCourseRepository.update(certificationCourse); + return certificationCourseRepository.update({ certificationCourse }); } handleCertificationScoring.eventTypes = eventTypes; diff --git a/api/lib/domain/events/handle-complementary-certifications-scoring.js b/api/lib/domain/events/handle-complementary-certifications-scoring.js index 62945943cc3..52ad15c279d 100644 --- a/api/lib/domain/events/handle-complementary-certifications-scoring.js +++ b/api/lib/domain/events/handle-complementary-certifications-scoring.js @@ -29,7 +29,7 @@ async function handleComplementaryCertificationsScoring({ return; } - const certificationCourse = await certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId }); const assessmentResult = await assessmentResultRepository.getByCertificationCourseId({ certificationCourseId }); const { diff --git a/api/lib/domain/events/handle-session-finalized.js b/api/lib/domain/events/handle-session-finalized.js index 81ce1e6629b..9e6d2f8fe2d 100644 --- a/api/lib/domain/events/handle-session-finalized.js +++ b/api/lib/domain/events/handle-session-finalized.js @@ -28,7 +28,7 @@ async function handleSessionFinalized({ juryCertificationSummaries, }); - await finalizedSessionRepository.save(finalizedSession); + await finalizedSessionRepository.save({ finalizedSession }); } handleSessionFinalized.eventTypes = eventTypes; diff --git a/api/lib/domain/models/CertificationAssessment.js b/api/lib/domain/models/CertificationAssessment.js index 61ee1085491..2d484ec1ee8 100644 --- a/api/lib/domain/models/CertificationAssessment.js +++ b/api/lib/domain/models/CertificationAssessment.js @@ -3,8 +3,8 @@ import BaseJoi from 'joi'; const Joi = BaseJoi.extend(JoiDate); import _ from 'lodash'; +import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js'; import { AnswerStatus } from '../../../src/shared/domain/models/AnswerStatus.js'; -import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js'; import { validateEntity } from '../../../src/shared/domain/validators/entity-validator.js'; import { ChallengeToBeDeneutralizedNotFoundError, ChallengeToBeNeutralizedNotFoundError } from '../errors.js'; import { CertificationAnswerStatusChangeAttempt } from './CertificationAnswerStatusChangeAttempt.js'; diff --git a/api/lib/domain/models/CertificationIssueReportResolutionStrategies.js b/api/lib/domain/models/CertificationIssueReportResolutionStrategies.js index b6b4bbb2214..35c2dc60181 100644 --- a/api/lib/domain/models/CertificationIssueReportResolutionStrategies.js +++ b/api/lib/domain/models/CertificationIssueReportResolutionStrategies.js @@ -208,13 +208,13 @@ async function _resolveWithNoSuchQuestion( questionNumber, ) { certificationIssueReport.resolveAutomatically(`Aucune question ne correspond au numéro ${questionNumber}`); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect(); } async function _resolveWithQuestionNeutralized(certificationIssueReportRepository, certificationIssueReport) { certificationIssueReport.resolveAutomatically('Cette question a été neutralisée automatiquement'); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); return CertificationIssueReportResolutionAttempt.resolvedWithEffect(); } @@ -225,7 +225,7 @@ async function _resolveWithNeitherImageNorEmbedInChallenge( certificationIssueReport.resolveAutomatically( "Cette question n'a pas été neutralisée car elle ne contient ni image ni application/simulateur", ); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect(); } @@ -233,7 +233,7 @@ async function _resolveWithNoAttachmentInChallenge(certificationIssueReportRepos certificationIssueReport.resolveAutomatically( "Cette question n'a pas été neutralisée car elle ne contient pas de fichier à télécharger", ); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect(); } @@ -241,7 +241,7 @@ async function _resolveWithNoFocusedChallenge(certificationIssueReportRepository certificationIssueReport.resolveAutomatically( "Cette question n'a pas été neutralisée car ce n'est pas une question focus", ); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect(); } @@ -249,13 +249,13 @@ async function _resolveWithChallengeNotTimed(certificationIssueReportRepository, certificationIssueReport.resolveAutomatically( "Cette question n'a pas été neutralisée car elle n'est pas chronométrée", ); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect(); } async function _resolveWithAnswerIsCorrect(certificationIssueReportRepository, certificationIssueReport) { certificationIssueReport.resolveAutomatically("Cette question n'a pas été neutralisée car la réponse est correcte"); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect(); } @@ -266,12 +266,12 @@ async function _resolveWithNeitherSkippedNorFocusedOutAnswer( certificationIssueReport.resolveAutomatically( "Cette question n'a pas été neutralisée car la réponse n'a pas été abandonnée ou le focus n'a pas été perdu", ); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect(); } async function _resolveWithAnswerValidated(certificationIssueReportRepository, certificationIssueReport) { certificationIssueReport.resolveAutomatically('Cette réponse a été acceptée automatiquement'); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); return CertificationIssueReportResolutionAttempt.resolvedWithEffect(); } diff --git a/api/lib/domain/models/index.js b/api/lib/domain/models/index.js index 414f3cf5422..ff930ba4868 100644 --- a/api/lib/domain/models/index.js +++ b/api/lib/domain/models/index.js @@ -6,6 +6,7 @@ import { FlashAssessmentAlgorithm } from '../../../src/certification/flash-certi import { CertificationAssessmentScore } from '../../../src/certification/scoring/domain/models/CertificationAssessmentScore.js'; import { CertificationOfficer } from '../../../src/certification/session/domain/models/CertificationOfficer.js'; import { Session } from '../../../src/certification/session/domain/models/Session.js'; +import { CertificationCourse } from '../../../src/certification/shared/domain/models/CertificationCourse.js'; import { CertificationIssueReport } from '../../../src/certification/shared/domain/models/CertificationIssueReport.js'; import { CertificationIssueReportCategory } from '../../../src/certification/shared/domain/models/CertificationIssueReportCategory.js'; import { CertificationReport } from '../../../src/certification/shared/domain/models/CertificationReport.js'; @@ -60,7 +61,6 @@ import { CertificationCenterMembership } from './CertificationCenterMembership.j import { CertificationChallenge } from './CertificationChallenge.js'; import { CertificationChallengeWithType } from './CertificationChallengeWithType.js'; import { CertificationContract } from './CertificationContract.js'; -import { CertificationCourse } from './CertificationCourse.js'; import { CertificationIssueReportResolutionAttempt } from './CertificationIssueReportResolutionAttempt.js'; import { CertificationIssueReportResolutionStrategies } from './CertificationIssueReportResolutionStrategies.js'; import { CertificationResult } from './CertificationResult.js'; diff --git a/api/lib/domain/services/certification-candidates-ods-service.js b/api/lib/domain/services/certification-candidates-ods-service.js index fe1fd7c7131..686375229fd 100644 --- a/api/lib/domain/services/certification-candidates-ods-service.js +++ b/api/lib/domain/services/certification-candidates-ods-service.js @@ -24,7 +24,7 @@ async function extractCertificationCandidatesFromCandidatesImportSheet({ mailCheck = mailCheckImplementation, }) { const translate = i18n.__; - const certificationCenter = await certificationCenterRepository.getBySessionId(sessionId); + const certificationCenter = await certificationCenterRepository.getBySessionId({ sessionId }); const candidateImportStructs = getTransformationStructsForPixCertifCandidatesImport({ i18n, complementaryCertifications: certificationCenter.habilitations, diff --git a/api/lib/domain/services/placement-profile-service.js b/api/lib/domain/services/placement-profile-service.js index 02f5f805063..0d898300ed8 100644 --- a/api/lib/domain/services/placement-profile-service.js +++ b/api/lib/domain/services/placement-profile-service.js @@ -1,7 +1,7 @@ import bluebird from 'bluebird'; import _ from 'lodash'; -import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js'; +import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js'; import * as assessmentRepository from '../../../src/shared/infrastructure/repositories/assessment-repository.js'; import * as assessmentResultRepository from '../../../src/shared/infrastructure/repositories/assessment-result-repository.js'; import * as competenceRepository from '../../../src/shared/infrastructure/repositories/competence-repository.js'; diff --git a/api/lib/domain/services/scoring/scoring-certification-service.js b/api/lib/domain/services/scoring/scoring-certification-service.js index 7adebb7789e..10704d13636 100644 --- a/api/lib/domain/services/scoring/scoring-certification-service.js +++ b/api/lib/domain/services/scoring/scoring-certification-service.js @@ -1,7 +1,7 @@ import _ from 'lodash'; import { CertificationAssessmentScore } from '../../../../src/certification/scoring/domain/models/CertificationAssessmentScore.js'; -import { CertificationVersion } from '../../../../src/shared/domain/models/CertificationVersion.js'; +import { CertificationVersion } from '../../../../src/certification/shared/domain/models/CertificationVersion.js'; import * as areaRepository from '../../../../src/shared/infrastructure/repositories/area-repository.js'; import { AnswerCollectionForScoring } from '../../models/AnswerCollectionForScoring.js'; import { CertificationContract } from '../../models/CertificationContract.js'; diff --git a/api/lib/domain/services/session-publication-service.js b/api/lib/domain/services/session-publication-service.js index 183c0c9596f..1e7279c3c68 100644 --- a/api/lib/domain/services/session-publication-service.js +++ b/api/lib/domain/services/session-publication-service.js @@ -32,7 +32,7 @@ async function publishSession({ finalizedSessionRepository, sessionRepository, }) { - const session = await sessionRepository.getWithCertificationCandidates(sessionId); + const session = await sessionRepository.getWithCertificationCandidates({ id: sessionId }); if (session.isPublished()) { throw new SessionAlreadyPublishedError(); } @@ -108,13 +108,13 @@ async function manageEmails({ * @param {MailService} params.mailService */ async function _manageCleaEmails({ session, certificationCenterRepository, sessionRepository, mailService }) { - const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired(session.id); + const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired({ id: session.id }); if (!hasSomeCleaAcquired) { logger.debug(`No CLEA certifications in session ${session.id}`); return; } - const refererEmails = await certificationCenterRepository.getRefererEmails(session.certificationCenterId); + const refererEmails = await certificationCenterRepository.getRefererEmails({ id: session.certificationCenterId }); if (refererEmails.length <= 0) { logger.warn(`Publishing session ${session.id} with Clea certifications but no referer. No email will be sent`); return; @@ -181,7 +181,7 @@ function _failedAttemptsEmail(emailingAttempts) { async function _updateFinalizedSession(finalizedSessionRepository, sessionId, publishedAt) { const finalizedSession = await finalizedSessionRepository.get({ sessionId }); finalizedSession.publish(publishedAt); - await finalizedSessionRepository.save(finalizedSession); + await finalizedSessionRepository.save({ finalizedSession }); } function _hasCertificationInError(certificationStatus) { diff --git a/api/lib/domain/services/verify-certificate-code-service.js b/api/lib/domain/services/verify-certificate-code-service.js index fc34e897e8f..954d432b06e 100644 --- a/api/lib/domain/services/verify-certificate-code-service.js +++ b/api/lib/domain/services/verify-certificate-code-service.js @@ -22,9 +22,11 @@ const generateCertificateVerificationCode = async function ({ dependencies = { certificationCourseRepository }, } = {}) { for (let i = 0; i < NB_OF_TRIALS; i++) { - const code = generateCode(); - const isCodeAvailable = await dependencies.certificationCourseRepository.isVerificationCodeAvailable(code); - if (isCodeAvailable) return code; + const verificationCode = generateCode(); + const isCodeAvailable = await dependencies.certificationCourseRepository.isVerificationCodeAvailable({ + verificationCode, + }); + if (isCodeAvailable) return verificationCode; } throw new CertificateVerificationCodeGenerationTooManyTrials(NB_OF_TRIALS); }; diff --git a/api/lib/domain/usecases/cancel-certification-course.js b/api/lib/domain/usecases/cancel-certification-course.js index 231be506287..95e46885406 100644 --- a/api/lib/domain/usecases/cancel-certification-course.js +++ b/api/lib/domain/usecases/cancel-certification-course.js @@ -1,7 +1,7 @@ const cancelCertificationCourse = async function ({ certificationCourseId, certificationCourseRepository }) { - const certificationCourse = await certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId }); certificationCourse.cancel(); - await certificationCourseRepository.update(certificationCourse); + await certificationCourseRepository.update({ certificationCourse }); }; export { cancelCertificationCourse }; diff --git a/api/lib/domain/usecases/correct-candidate-identity-in-certification-course.js b/api/lib/domain/usecases/correct-candidate-identity-in-certification-course.js index eca96dabfce..125adb2ee1e 100644 --- a/api/lib/domain/usecases/correct-candidate-identity-in-certification-course.js +++ b/api/lib/domain/usecases/correct-candidate-identity-in-certification-course.js @@ -18,7 +18,7 @@ const correctCandidateIdentityInCertificationCourse = async function ({ certificationCpfCountryRepository, certificationCpfCityRepository, }) { - const certificationCourse = await certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId }); certificationCourse.correctFirstName(firstName); certificationCourse.correctLastName(lastName); certificationCourse.correctBirthdate(birthdate); @@ -40,7 +40,7 @@ const correctCandidateIdentityInCertificationCourse = async function ({ certificationCourse.correctBirthInformation(cpfBirthInformation); - await certificationCourseRepository.update(certificationCourse); + await certificationCourseRepository.update({ certificationCourse }); }; export { correctCandidateIdentityInCertificationCourse }; diff --git a/api/lib/domain/usecases/create-or-update-certification-center-invitation.js b/api/lib/domain/usecases/create-or-update-certification-center-invitation.js index 8531c098b93..08cfc3b42a5 100644 --- a/api/lib/domain/usecases/create-or-update-certification-center-invitation.js +++ b/api/lib/domain/usecases/create-or-update-certification-center-invitation.js @@ -8,7 +8,7 @@ const createOrUpdateCertificationCenterInvitation = async function ({ certificationCenterInvitationRepository, certificationCenterInvitationService, }) { - const certificationCenter = await certificationCenterRepository.get(certificationCenterId); + const certificationCenter = await certificationCenterRepository.get({ id: certificationCenterId }); const uniqueEmails = [...new Set(emails)]; const trimmedUniqueEmails = uniqueEmails.map((email) => email.replace(/[\s\r\n]/g, '')); diff --git a/api/lib/domain/usecases/delete-certification-issue-report.js b/api/lib/domain/usecases/delete-certification-issue-report.js index 3c260db5e6f..ae2293797e6 100644 --- a/api/lib/domain/usecases/delete-certification-issue-report.js +++ b/api/lib/domain/usecases/delete-certification-issue-report.js @@ -6,15 +6,17 @@ const deleteCertificationIssueReport = async function ({ certificationIssueReportRepository, sessionRepository, }) { - const certificationIssueReport = await certificationIssueReportRepository.get(certificationIssueReportId); - const sessionId = await certificationCourseRepository.getSessionId(certificationIssueReport.certificationCourseId); - const isFinalized = await sessionRepository.isFinalized(sessionId); + const certificationIssueReport = await certificationIssueReportRepository.get({ id: certificationIssueReportId }); + const sessionId = await certificationCourseRepository.getSessionId({ + id: certificationIssueReport.certificationCourseId, + }); + const isFinalized = await sessionRepository.isFinalized({ id: sessionId }); if (isFinalized) { throw new ForbiddenAccess('Certification issue report deletion forbidden'); } - return certificationIssueReportRepository.remove(certificationIssueReportId); + return certificationIssueReportRepository.remove({ id: certificationIssueReportId }); }; export { deleteCertificationIssueReport }; diff --git a/api/lib/domain/usecases/enrol-students-to-session.js b/api/lib/domain/usecases/enrol-students-to-session.js index 16351820b48..5c9552bdffc 100644 --- a/api/lib/domain/usecases/enrol-students-to-session.js +++ b/api/lib/domain/usecases/enrol-students-to-session.js @@ -16,7 +16,7 @@ const enrolStudentsToSession = async function ({ countryRepository, sessionRepository, } = {}) { - const session = await sessionRepository.get(sessionId); + const session = await sessionRepository.get({ id: sessionId }); const referentCertificationCenterMemberships = await certificationCenterMembershipRepository.findByUserId(referentId); if (!_doesSessionBelongToSameCertificationCenterAsReferent(referentCertificationCenterMemberships, session)) { diff --git a/api/lib/domain/usecases/flag-session-results-as-sent-to-prescriber.js b/api/lib/domain/usecases/flag-session-results-as-sent-to-prescriber.js index dc5098f7371..af8233baec8 100644 --- a/api/lib/domain/usecases/flag-session-results-as-sent-to-prescriber.js +++ b/api/lib/domain/usecases/flag-session-results-as-sent-to-prescriber.js @@ -8,7 +8,7 @@ const flagSessionResultsAsSentToPrescriber = async function ({ sessionId, sessio throw new NotFoundError(NOT_FOUND_SESSION); } - let session = await sessionRepository.get(sessionId); + let session = await sessionRepository.get({ id: sessionId }); if (!session.areResultsFlaggedAsSent()) { session = await sessionRepository.flagResultsAsSentToPrescriber({ diff --git a/api/lib/domain/usecases/get-assessment.js b/api/lib/domain/usecases/get-assessment.js index 34bff510e38..de3fda7aa29 100644 --- a/api/lib/domain/usecases/get-assessment.js +++ b/api/lib/domain/usecases/get-assessment.js @@ -47,7 +47,7 @@ async function _addDemoRelatedAttributes(assessment, courseRepository) { async function _addCertificationRelatedAttributes(assessment, liveAlertRepository) { if (assessment.type === Assessment.types.CERTIFICATION) { - const liveAlerts = await liveAlertRepository.getByAssessmentId(assessment.id); + const liveAlerts = await liveAlertRepository.getByAssessmentId({ assessmentId: assessment.id }); assessment.attachLiveAlerts(liveAlerts); } diff --git a/api/lib/domain/usecases/get-candidate-import-sheet-data.js b/api/lib/domain/usecases/get-candidate-import-sheet-data.js index b55cfe0e297..3cd60cc9e18 100644 --- a/api/lib/domain/usecases/get-candidate-import-sheet-data.js +++ b/api/lib/domain/usecases/get-candidate-import-sheet-data.js @@ -1,6 +1,6 @@ const getCandidateImportSheetData = async function ({ sessionId, sessionRepository, certificationCenterRepository }) { - const session = await sessionRepository.getWithCertificationCandidates(sessionId); - const certificationCenter = await certificationCenterRepository.getBySessionId(sessionId); + const session = await sessionRepository.getWithCertificationCandidates({ id: sessionId }); + const certificationCenter = await certificationCenterRepository.getBySessionId({ sessionId }); return { session, diff --git a/api/lib/domain/usecases/get-certification-candidate-subscription.js b/api/lib/domain/usecases/get-certification-candidate-subscription.js index 77e58a845c9..6abc9af958d 100644 --- a/api/lib/domain/usecases/get-certification-candidate-subscription.js +++ b/api/lib/domain/usecases/get-certification-candidate-subscription.js @@ -18,7 +18,9 @@ const getCertificationCandidateSubscription = async function ({ }); } - const certificationCenter = await certificationCenterRepository.getBySessionId(certificationCandidate.sessionId); + const certificationCenter = await certificationCenterRepository.getBySessionId({ + sessionId: certificationCandidate.sessionId, + }); let eligibleSubscription = null; let nonEligibleSubscription = null; diff --git a/api/lib/domain/usecases/get-certification-center.js b/api/lib/domain/usecases/get-certification-center.js index e8b7219d574..27e55e9d8ed 100644 --- a/api/lib/domain/usecases/get-certification-center.js +++ b/api/lib/domain/usecases/get-certification-center.js @@ -1,5 +1,5 @@ const getCertificationCenter = function ({ id, certificationCenterRepository }) { - return certificationCenterRepository.get(id); + return certificationCenterRepository.get({ id }); }; export { getCertificationCenter }; diff --git a/api/lib/domain/usecases/get-certification-course.js b/api/lib/domain/usecases/get-certification-course.js index a721935eee4..260ff8dd483 100644 --- a/api/lib/domain/usecases/get-certification-course.js +++ b/api/lib/domain/usecases/get-certification-course.js @@ -1,5 +1,5 @@ const getCertificationCourse = async function ({ certificationCourseId, certificationCourseRepository }) { - return certificationCourseRepository.get(certificationCourseId); + return certificationCourseRepository.get({ id: certificationCourseId }); }; export { getCertificationCourse }; diff --git a/api/lib/domain/usecases/get-certification-details.js b/api/lib/domain/usecases/get-certification-details.js index f5a7df224bd..9a29be40373 100644 --- a/api/lib/domain/usecases/get-certification-details.js +++ b/api/lib/domain/usecases/get-certification-details.js @@ -1,4 +1,4 @@ -import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js'; +import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js'; import { CertificationDetails } from '../read-models/CertificationDetails.js'; const getCertificationDetails = async function ({ diff --git a/api/lib/domain/usecases/get-clea-certified-candidate-by-session.js b/api/lib/domain/usecases/get-clea-certified-candidate-by-session.js index d1487d52e31..abecf73bb17 100644 --- a/api/lib/domain/usecases/get-clea-certified-candidate-by-session.js +++ b/api/lib/domain/usecases/get-clea-certified-candidate-by-session.js @@ -4,7 +4,7 @@ const getCleaCertifiedCandidateBySession = async function ({ sessionRepository, }) { const cleaCertifiedCandidateData = await cleaCertifiedCandidateRepository.getBySessionId(sessionId); - const session = await sessionRepository.get(sessionId); + const session = await sessionRepository.get({ id: sessionId }); return { session, cleaCertifiedCandidateData }; }; diff --git a/api/lib/domain/usecases/get-jury-session.js b/api/lib/domain/usecases/get-jury-session.js index b526ddf812a..1edb52417d4 100644 --- a/api/lib/domain/usecases/get-jury-session.js +++ b/api/lib/domain/usecases/get-jury-session.js @@ -1,5 +1,5 @@ const getJurySession = async function ({ sessionId, jurySessionRepository, supervisorAccessRepository }) { - const jurySession = await jurySessionRepository.get(sessionId); + const jurySession = await jurySessionRepository.get({ id: sessionId }); const hasSupervisorAccess = await supervisorAccessRepository.sessionHasSupervisorAccess({ sessionId }); return { jurySession, diff --git a/api/lib/domain/usecases/get-session-results-by-result-recipient-email.js b/api/lib/domain/usecases/get-session-results-by-result-recipient-email.js index 55ce05b2e57..757c4f7f959 100644 --- a/api/lib/domain/usecases/get-session-results-by-result-recipient-email.js +++ b/api/lib/domain/usecases/get-session-results-by-result-recipient-email.js @@ -6,7 +6,7 @@ const getSessionResultsByResultRecipientEmail = async function ({ sessionRepository, certificationResultRepository, }) { - const session = await sessionRepository.getWithCertificationCandidates(sessionId); + const session = await sessionRepository.getWithCertificationCandidates({ id: sessionId }); const certificationCandidateIdsForResultRecipient = _(session.certificationCandidates) .filter({ resultRecipientEmail }) .map('id') diff --git a/api/lib/domain/usecases/get-session-results.js b/api/lib/domain/usecases/get-session-results.js index 3a07ca2f735..3dbb55327a9 100644 --- a/api/lib/domain/usecases/get-session-results.js +++ b/api/lib/domain/usecases/get-session-results.js @@ -1,5 +1,5 @@ const getSessionResults = async function ({ sessionId, sessionRepository, certificationResultRepository }) { - const session = await sessionRepository.get(sessionId); + const session = await sessionRepository.get({ id: sessionId }); const certificationResults = await certificationResultRepository.findBySessionId({ sessionId }); return { session, certificationResults }; diff --git a/api/lib/domain/usecases/get-session.js b/api/lib/domain/usecases/get-session.js index df0c22480ca..32b765bae0d 100644 --- a/api/lib/domain/usecases/get-session.js +++ b/api/lib/domain/usecases/get-session.js @@ -1,6 +1,6 @@ const getSession = async function ({ sessionId, sessionRepository, supervisorAccessRepository }) { - const session = await sessionRepository.get(sessionId); - const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired(sessionId); + const session = await sessionRepository.get({ id: sessionId }); + const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired({ id: sessionId }); const hasSupervisorAccess = await supervisorAccessRepository.sessionHasSupervisorAccess({ sessionId }); return { session, diff --git a/api/lib/domain/usecases/import-certification-candidates-from-candidates-import-sheet.js b/api/lib/domain/usecases/import-certification-candidates-from-candidates-import-sheet.js index dea79f3f7d5..aaebaa335d3 100644 --- a/api/lib/domain/usecases/import-certification-candidates-from-candidates-import-sheet.js +++ b/api/lib/domain/usecases/import-certification-candidates-from-candidates-import-sheet.js @@ -23,7 +23,7 @@ const importCertificationCandidatesFromCandidatesImportSheet = async function ({ throw new CertificationCandidateAlreadyLinkedToUserError('At least one candidate is already linked to a user'); } - const isSco = await sessionRepository.isSco({ sessionId }); + const isSco = await sessionRepository.isSco({ id: sessionId }); const certificationCandidates = await certificationCandidatesOdsService.extractCertificationCandidatesFromCandidatesImportSheet({ diff --git a/api/lib/domain/usecases/index.js b/api/lib/domain/usecases/index.js index a679b8bbcbe..82c94024f97 100644 --- a/api/lib/domain/usecases/index.js +++ b/api/lib/domain/usecases/index.js @@ -12,20 +12,20 @@ import { getNextChallengeForCertification } from '../../../src/certification/cou import * as flashAlgorithmService from '../../../src/certification/flash-certification/domain/services/algorithm-methods/flash.js'; import { pickChallengeService } from '../../../src/certification/flash-certification/domain/services/pick-challenge-service.js'; import * as flashAlgorithmConfigurationRepository from '../../../src/certification/flash-certification/infrastructure/repositories/flash-algorithm-configuration-repository.js'; +import * as certificationCpfService from '../../../src/certification/session/domain/services/certification-cpf-service.js'; import * as sessionCodeService from '../../../src/certification/session/domain/services/session-code-service.js'; -import * as certificationChallengeLiveAlertRepository from '../../../src/certification/session/infrastructure/repositories/certification-challenge-live-alert-repository.js'; +import * as certificationCandidateRepository from '../../../src/certification/session/infrastructure/repositories/certification-candidate-repository.js'; +import * as certificationCpfCityRepository from '../../../src/certification/session/infrastructure/repositories/certification-cpf-city-repository.js'; +import * as certificationCpfCountryRepository from '../../../src/certification/session/infrastructure/repositories/certification-cpf-country-repository.js'; import * as certificationOfficerRepository from '../../../src/certification/session/infrastructure/repositories/certification-officer-repository.js'; import * as finalizedSessionRepository from '../../../src/certification/session/infrastructure/repositories/finalized-session-repository.js'; import * as jurySessionRepository from '../../../src/certification/session/infrastructure/repositories/jury-session-repository.js'; import * as sessionRepository from '../../../src/certification/session/infrastructure/repositories/session-repository.js'; -import * as certificationCpfService from '../../../src/certification/shared/domain/services/certification-cpf-service.js'; import * as certificationAssessmentRepository from '../../../src/certification/shared/infrastructure/repositories/certification-assessment-repository.js'; -import * as certificationCandidateRepository from '../../../src/certification/shared/infrastructure/repositories/certification-candidate-repository.js'; import * as certificationCenterRepository from '../../../src/certification/shared/infrastructure/repositories/certification-center-repository.js'; +import * as certificationChallengeLiveAlertRepository from '../../../src/certification/shared/infrastructure/repositories/certification-challenge-live-alert-repository.js'; import * as certificationChallengeRepository from '../../../src/certification/shared/infrastructure/repositories/certification-challenge-repository.js'; import * as certificationCourseRepository from '../../../src/certification/shared/infrastructure/repositories/certification-course-repository.js'; -import * as certificationCpfCityRepository from '../../../src/certification/shared/infrastructure/repositories/certification-cpf-city-repository.js'; -import * as certificationCpfCountryRepository from '../../../src/certification/shared/infrastructure/repositories/certification-cpf-country-repository.js'; import * as certificationIssueReportRepository from '../../../src/certification/shared/infrastructure/repositories/certification-issue-report-repository.js'; import * as issueReportCategoryRepository from '../../../src/certification/shared/infrastructure/repositories/issue-report-category-repository.js'; import * as certificationCandidateForSupervisingRepository from '../../../src/certification/supervision/infrastructure/repositories/certification-candidate-for-supervising-repository.js'; diff --git a/api/lib/domain/usecases/link-user-to-session-certification-candidate.js b/api/lib/domain/usecases/link-user-to-session-certification-candidate.js index 0c26de011c4..f1c1fe55017 100644 --- a/api/lib/domain/usecases/link-user-to-session-certification-candidate.js +++ b/api/lib/domain/usecases/link-user-to-session-certification-candidate.js @@ -24,7 +24,7 @@ const linkUserToSessionCertificationCandidate = async function ({ organizationLearnerRepository, sessionRepository, }) { - const session = await sessionRepository.get(sessionId); + const session = await sessionRepository.get({ id: sessionId }); if (!session.isAccessible()) { throw new SessionNotAccessible(); } @@ -104,7 +104,7 @@ async function _isSessionFromAScoAndManagingStudentsOrganization({ certificationCenterRepository, organizationRepository, }) { - const sessionCertificationCenter = await certificationCenterRepository.getBySessionId(sessionId); + const sessionCertificationCenter = await certificationCenterRepository.getBySessionId({ sessionId }); if (sessionCertificationCenter.isSco) { const sessionOrganization = await _getOrganizationLinkedToCertificationCenter({ diff --git a/api/lib/domain/usecases/manually-resolve-certification-issue-report.js b/api/lib/domain/usecases/manually-resolve-certification-issue-report.js index 67f249a0d27..c1bd643a18e 100644 --- a/api/lib/domain/usecases/manually-resolve-certification-issue-report.js +++ b/api/lib/domain/usecases/manually-resolve-certification-issue-report.js @@ -5,13 +5,13 @@ const manuallyResolveCertificationIssueReport = async function ({ resolution, certificationIssueReportRepository, }) { - const certificationIssueReport = await certificationIssueReportRepository.get(certificationIssueReportId); + const certificationIssueReport = await certificationIssueReportRepository.get({ id: certificationIssueReportId }); if (certificationIssueReport.hasBeenAutomaticallyResolved) { throw new CertificationIssueReportAutomaticallyResolvedShouldNotBeUpdatedManually(); } certificationIssueReport.resolveManually(resolution); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); }; export { manuallyResolveCertificationIssueReport }; diff --git a/api/lib/domain/usecases/publish-session.js b/api/lib/domain/usecases/publish-session.js index 2482a2c8ff4..3554eab0535 100644 --- a/api/lib/domain/usecases/publish-session.js +++ b/api/lib/domain/usecases/publish-session.js @@ -40,7 +40,7 @@ const publishSession = async function ({ sessionRepository, }); - return sessionRepository.get(sessionId); + return sessionRepository.get({ id: sessionId }); }; export { publishSession }; diff --git a/api/lib/domain/usecases/resend-certification-center-invitation.js b/api/lib/domain/usecases/resend-certification-center-invitation.js index 189d00f0fe1..6da074d31e7 100644 --- a/api/lib/domain/usecases/resend-certification-center-invitation.js +++ b/api/lib/domain/usecases/resend-certification-center-invitation.js @@ -8,9 +8,9 @@ const resendCertificationCenterInvitation = async function ({ const certificationCenterInvitation = await certificationCenterInvitationRepository.get( certificationCenterInvitationId, ); - const certificationCenter = await certificationCenterRepository.get( - certificationCenterInvitation.certificationCenterId, - ); + const certificationCenter = await certificationCenterRepository.get({ + id: certificationCenterInvitation.certificationCenterId, + }); await certificationCenterInvitationService.resendCertificationCenterInvitation({ certificationCenterInvitationRepository, })({ diff --git a/api/lib/domain/usecases/retrieve-last-or-create-certification-course.js b/api/lib/domain/usecases/retrieve-last-or-create-certification-course.js index 8823501a837..4540c8911fb 100644 --- a/api/lib/domain/usecases/retrieve-last-or-create-certification-course.js +++ b/api/lib/domain/usecases/retrieve-last-or-create-certification-course.js @@ -1,7 +1,8 @@ import bluebird from 'bluebird'; +import { CertificationCourse } from '../../../src/certification/shared/domain/models/CertificationCourse.js'; +import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js'; import { Assessment } from '../../../src/shared/domain/models/Assessment.js'; -import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js'; import { config } from '../../config.js'; import { CandidateNotAuthorizedToJoinSessionError, @@ -11,7 +12,6 @@ import { UnexpectedUserAccountError, UserNotAuthorizedToCertifyError, } from '../errors.js'; -import { CertificationCourse } from '../models/CertificationCourse.js'; import { ComplementaryCertificationCourse } from '../models/ComplementaryCertificationCourse.js'; const { features } = config; @@ -33,7 +33,7 @@ const retrieveLastOrCreateCertificationCourse = async function ({ certificationBadgesService, verifyCertificateCodeService, }) { - const session = await sessionRepository.get(sessionId); + const session = await sessionRepository.get({ id: sessionId }); _validateSessionAccess(session, accessCode); _validateSessionIsActive(session); @@ -166,7 +166,7 @@ async function _startNewCertification({ }; } - const certificationCenter = await certificationCenterRepository.getBySessionId(sessionId); + const certificationCenter = await certificationCenterRepository.getBySessionId({ sessionId }); const complementaryCertificationCourseData = []; diff --git a/api/lib/domain/usecases/supervise-session.js b/api/lib/domain/usecases/supervise-session.js index 09e03c05719..024b5c71ad8 100644 --- a/api/lib/domain/usecases/supervise-session.js +++ b/api/lib/domain/usecases/supervise-session.js @@ -7,7 +7,7 @@ const superviseSession = async function ({ sessionRepository, supervisorAccessRepository, }) { - const session = await sessionRepository.get(sessionId); + const session = await sessionRepository.get({ id: sessionId }); if (!session.isSupervisable(supervisorPassword)) { throw new InvalidSessionSupervisingLoginError(); } diff --git a/api/lib/domain/usecases/uncancel-certification-course.js b/api/lib/domain/usecases/uncancel-certification-course.js index 7b8c9b1a17e..edd21173ebb 100644 --- a/api/lib/domain/usecases/uncancel-certification-course.js +++ b/api/lib/domain/usecases/uncancel-certification-course.js @@ -1,7 +1,7 @@ const uncancelCertificationCourse = async function ({ certificationCourseId, certificationCourseRepository }) { - const certificationCourse = await certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId }); certificationCourse.uncancel(); - await certificationCourseRepository.update(certificationCourse); + await certificationCourseRepository.update({ certificationCourse }); }; export { uncancelCertificationCourse }; diff --git a/api/lib/domain/usecases/unpublish-session.js b/api/lib/domain/usecases/unpublish-session.js index 30c2a17079a..7ceb207e80d 100644 --- a/api/lib/domain/usecases/unpublish-session.js +++ b/api/lib/domain/usecases/unpublish-session.js @@ -4,7 +4,7 @@ const unpublishSession = async function ({ sessionRepository, finalizedSessionRepository, }) { - const session = await sessionRepository.getWithCertificationCandidates(sessionId); + const session = await sessionRepository.getWithCertificationCandidates({ id: sessionId }); await certificationRepository.unpublishCertificationCoursesBySessionId(sessionId); @@ -14,7 +14,7 @@ const unpublishSession = async function ({ await _updateFinalizedSession(finalizedSessionRepository, sessionId); - return sessionRepository.getWithCertificationCandidates(sessionId); + return sessionRepository.getWithCertificationCandidates({ id: sessionId }); }; export { unpublishSession }; @@ -22,5 +22,5 @@ export { unpublishSession }; async function _updateFinalizedSession(finalizedSessionRepository, sessionId) { const finalizedSession = await finalizedSessionRepository.get({ sessionId }); finalizedSession.unpublish(); - await finalizedSessionRepository.save(finalizedSession); + await finalizedSessionRepository.save({ finalizedSession }); } diff --git a/api/lib/infrastructure/repositories/sessions/session-for-supervising-repository.js b/api/lib/infrastructure/repositories/sessions/session-for-supervising-repository.js index 1b6c27d0b95..afd9f706963 100644 --- a/api/lib/infrastructure/repositories/sessions/session-for-supervising-repository.js +++ b/api/lib/infrastructure/repositories/sessions/session-for-supervising-repository.js @@ -1,8 +1,8 @@ import { knex } from '../../../../db/knex-database-connection.js'; -import { CertificationChallengeLiveAlertStatus } from '../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationVersion } from '../../../../src/certification/shared/domain/models/CertificationVersion.js'; import { CertificationCandidateForSupervising } from '../../../../src/certification/supervision/domain/models/CertificationCandidateForSupervising.js'; import { CertificationCandidateForSupervisingV3 } from '../../../../src/certification/supervision/domain/models/CertificationCandidateForSupervisingV3.js'; -import { CertificationVersion } from '../../../../src/shared/domain/models/CertificationVersion.js'; import { NotFoundError } from '../../../domain/errors.js'; import { ComplementaryCertificationForSupervising } from '../../../domain/models/ComplementaryCertificationForSupervising.js'; import { SessionForSupervising } from '../../../domain/read-models/SessionForSupervising.js'; diff --git a/api/lib/infrastructure/serializers/jsonapi/certification-serializer.js b/api/lib/infrastructure/serializers/jsonapi/certification-serializer.js index 7c3e0bf550d..f5dfe2ad1e9 100644 --- a/api/lib/infrastructure/serializers/jsonapi/certification-serializer.js +++ b/api/lib/infrastructure/serializers/jsonapi/certification-serializer.js @@ -3,10 +3,10 @@ import _ from 'lodash'; const { Serializer, Deserializer } = jsonapiSerializer; +import { CertificationCourse } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { NO_EXAMINER_COMMENT } from '../../../../src/certification/shared/domain/models/CertificationReport.js'; import { isValidDate } from '../../../../src/shared/infrastructure/utils/date-utils.js'; import { WrongDateFormatError } from '../../../domain/errors.js'; -import { CertificationCourse } from '../../../domain/models/CertificationCourse.js'; const serializeFromCertificationCourse = function (certificationCourse) { return new Serializer('certifications', { diff --git a/api/scripts/certification/send-certification-result-emails.js b/api/scripts/certification/send-certification-result-emails.js index f4521d5735c..707404f1929 100644 --- a/api/scripts/certification/send-certification-result-emails.js +++ b/api/scripts/certification/send-certification-result-emails.js @@ -44,7 +44,7 @@ async function main() { let session; try { - session = await sessionRepository.getWithCertificationCandidates(parseInt(sessionId)); + session = await sessionRepository.getWithCertificationCandidates({ id: parseInt(sessionId) }); } catch (e) { logger.error({ e }); return; diff --git a/api/src/certification/course/domain/usecases/create-certification-challenge-live-alert.js b/api/src/certification/course/domain/usecases/create-certification-challenge-live-alert.js index 1fc84537e99..cf652791f89 100644 --- a/api/src/certification/course/domain/usecases/create-certification-challenge-live-alert.js +++ b/api/src/certification/course/domain/usecases/create-certification-challenge-live-alert.js @@ -1,4 +1,4 @@ -import { CertificationChallengeLiveAlert } from '../../../session/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationChallengeLiveAlert } from '../../../shared/domain/models/CertificationChallengeLiveAlert.js'; const createCertificationChallengeLiveAlert = async function ({ assessmentId, diff --git a/api/src/certification/course/domain/usecases/get-next-challenge-for-certification.js b/api/src/certification/course/domain/usecases/get-next-challenge-for-certification.js index de758a6a826..6602ba6bf66 100644 --- a/api/src/certification/course/domain/usecases/get-next-challenge-for-certification.js +++ b/api/src/certification/course/domain/usecases/get-next-challenge-for-certification.js @@ -1,5 +1,5 @@ import { CertificationChallenge, FlashAssessmentAlgorithm } from '../../../../../lib/domain/models/index.js'; -import { CertificationVersion } from '../../../../shared/domain/models/CertificationVersion.js'; +import { CertificationVersion } from '../../../shared/domain/models/CertificationVersion.js'; const getNextChallengeForCertification = async function ({ answerRepository, @@ -13,7 +13,9 @@ const getNextChallengeForCertification = async function ({ flashAlgorithmService, flashAlgorithmConfigurationRepository, }) { - const certificationCourse = await certificationCourseRepository.get(assessment.certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ + id: assessment.certificationCourseId, + }); if (certificationCourse.getVersion() === CertificationVersion.V3) { const alreadyAnsweredChallengeIds = await _getAlreadyAnsweredChallengeIds({ @@ -110,7 +112,7 @@ const _getAlreadyAnsweredChallengeIds = async ({ assessmentId, answerRepository }; const _getValidatedLiveAlertChallengeIds = async ({ assessmentId, certificationChallengeLiveAlertRepository }) => { - return certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId(assessmentId); + return certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId({ assessmentId }); }; export { getNextChallengeForCertification }; diff --git a/api/src/certification/course/domain/usecases/get-session-certification-reports.js b/api/src/certification/course/domain/usecases/get-session-certification-reports.js index 0ad7b398241..06cddfddb3d 100644 --- a/api/src/certification/course/domain/usecases/get-session-certification-reports.js +++ b/api/src/certification/course/domain/usecases/get-session-certification-reports.js @@ -1,5 +1,5 @@ const getSessionCertificationReports = async function ({ sessionId, certificationReportRepository }) { - return certificationReportRepository.findBySessionId(sessionId); + return certificationReportRepository.findBySessionId({ sessionId }); }; export { getSessionCertificationReports }; diff --git a/api/src/certification/course/domain/usecases/index.js b/api/src/certification/course/domain/usecases/index.js index edae10ed9d5..0f7fb61b518 100644 --- a/api/src/certification/course/domain/usecases/index.js +++ b/api/src/certification/course/domain/usecases/index.js @@ -17,7 +17,7 @@ import * as scoCertificationCandidateRepository from '../../infrastructure/repos * @typedef {courseAssessmentResultRepository} CourseAssessmentResultRepository * @typedef {competenceMarkRepository} CompetenceMarkRepository * @typedef {certificationResultRepository} CertificationResultRepository - * @typedef {scoCertificationCandidateRepository} ScoCertificationCandidateRepository * + * @typedef {scoCertificationCandidateRepository} ScoCertificationCandidateRepository **/ const dependencies = { assessmentResultRepository, diff --git a/api/src/certification/course/domain/usecases/reject-certification-course.js b/api/src/certification/course/domain/usecases/reject-certification-course.js index d72d8b1892e..1fbe1997027 100644 --- a/api/src/certification/course/domain/usecases/reject-certification-course.js +++ b/api/src/certification/course/domain/usecases/reject-certification-course.js @@ -1,11 +1,11 @@ import { CertificationCourseRejected } from '../../../../../lib/domain/events/CertificationCourseRejected.js'; export const rejectCertificationCourse = async ({ certificationCourseId, juryId, certificationCourseRepository }) => { - const certificationCourse = await certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId }); certificationCourse.rejectForFraud(); - await certificationCourseRepository.update(certificationCourse); + await certificationCourseRepository.update({ certificationCourse }); return new CertificationCourseRejected({ certificationCourseId, juryId }); }; diff --git a/api/src/certification/course/domain/usecases/unreject-certification-course.js b/api/src/certification/course/domain/usecases/unreject-certification-course.js index 15d07d1358b..27b37d7569a 100644 --- a/api/src/certification/course/domain/usecases/unreject-certification-course.js +++ b/api/src/certification/course/domain/usecases/unreject-certification-course.js @@ -1,11 +1,11 @@ import { CertificationCourseUnrejected } from '../../../../../lib/domain/events/CertificationCourseUnrejected.js'; export const unrejectCertificationCourse = async ({ certificationCourseId, juryId, certificationCourseRepository }) => { - const certificationCourse = await certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId }); certificationCourse.unrejectForFraud(); - await certificationCourseRepository.update(certificationCourse); + await certificationCourseRepository.update({ certificationCourse }); return new CertificationCourseUnrejected({ certificationCourseId, juryId }); }; diff --git a/api/src/certification/course/infrastructure/repositories/v3-certification-course-details-for-administration-repository.js b/api/src/certification/course/infrastructure/repositories/v3-certification-course-details-for-administration-repository.js index 55beb16bf6d..f95a00e24f4 100644 --- a/api/src/certification/course/infrastructure/repositories/v3-certification-course-details-for-administration-repository.js +++ b/api/src/certification/course/infrastructure/repositories/v3-certification-course-details-for-administration-repository.js @@ -1,6 +1,6 @@ import { knex } from '../../../../../db/knex-database-connection.js'; import { AnswerStatus } from '../../../../shared/domain/models/AnswerStatus.js'; -import { CertificationChallengeLiveAlertStatus } from '../../../session/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../shared/domain/models/CertificationChallengeLiveAlert.js'; import { V3CertificationChallengeForAdministration } from '../../domain/models/V3CertificationChallengeForAdministration.js'; import { V3CertificationChallengeLiveAlertForAdministration } from '../../domain/models/V3CertificationChallengeLiveAlertForAdministration.js'; import { V3CertificationCourseDetailsForAdministration } from '../../domain/models/V3CertificationCourseDetailsForAdministration.js'; diff --git a/api/src/certification/session/application/attendance-sheet-controller.js b/api/src/certification/session/application/attendance-sheet-controller.js index 521a7bb233b..f4e729c451f 100644 --- a/api/src/certification/session/application/attendance-sheet-controller.js +++ b/api/src/certification/session/application/attendance-sheet-controller.js @@ -1,4 +1,4 @@ -import { usecases } from '../../shared/domain/usecases/index.js'; +import { usecases } from '../domain/usecases/index.js'; const getAttendanceSheet = async function (request, h) { const sessionId = request.params.id; diff --git a/api/src/certification/session/application/certification-candidate-controller.js b/api/src/certification/session/application/certification-candidate-controller.js index eafdcba5f69..b68fb88204e 100644 --- a/api/src/certification/session/application/certification-candidate-controller.js +++ b/api/src/certification/session/application/certification-candidate-controller.js @@ -1,5 +1,4 @@ import * as sessionCertificationCandidateSerializer from '../../session/infrastructure/serializers/jsonapi/certification-candidate-serializer.js'; -import { usecases as sharedUsecases } from '../../shared/domain/usecases/index.js'; import * as certificationCandidateSerializer from '../../shared/infrastructure/serializers/jsonapi/certification-candidate-serializer.js'; import { usecases } from '../domain/usecases/index.js'; @@ -7,7 +6,7 @@ const addCandidate = async function (request, h, dependencies = { certificationC const sessionId = request.params.id; const certificationCandidate = await dependencies.certificationCandidateSerializer.deserialize(request.payload); const complementaryCertification = request.payload.data.attributes['complementary-certification'] ?? null; - const addedCertificationCandidate = await sharedUsecases.addCertificationCandidateToSession({ + const addedCertificationCandidate = await usecases.addCertificationCandidateToSession({ sessionId, certificationCandidate, complementaryCertification, @@ -26,7 +25,7 @@ const getCandidate = async function (request, h, dependencies = { sessionCertifi const deleteCandidate = async function (request) { const certificationCandidateId = request.params.certificationCandidateId; - await sharedUsecases.deleteUnlinkedCertificationCandidate({ certificationCandidateId }); + await usecases.deleteUnlinkedCertificationCandidate({ certificationCandidateId }); return null; }; diff --git a/api/src/certification/session/application/certification-officer-controller.js b/api/src/certification/session/application/certification-officer-controller.js index a71212d1ff8..9f1b6653438 100644 --- a/api/src/certification/session/application/certification-officer-controller.js +++ b/api/src/certification/session/application/certification-officer-controller.js @@ -1,5 +1,5 @@ import * as jurySessionSerializer from '../../../../lib/infrastructure/serializers/jsonapi/jury-session-serializer.js'; -import { usecases } from '../../shared/domain/usecases/index.js'; +import { usecases } from '../domain/usecases/index.js'; const assignCertificationOfficer = async function (request, h, dependencies = { jurySessionSerializer }) { const sessionId = request.params.id; diff --git a/api/src/certification/session/application/certification-report-controller.js b/api/src/certification/session/application/certification-report-controller.js index 199ce0b4e99..ef70deacd7c 100644 --- a/api/src/certification/session/application/certification-report-controller.js +++ b/api/src/certification/session/application/certification-report-controller.js @@ -1,5 +1,5 @@ import * as certificationIssueReportSerializer from '../../../../lib/infrastructure/serializers/jsonapi/certification-issue-report-serializer.js'; -import { usecases } from '../../shared/domain/usecases/index.js'; +import { usecases } from '../domain/usecases/index.js'; const saveCertificationIssueReport = async function (request, h) { const certificationIssueReportDTO = certificationIssueReportSerializer.deserialize(request); diff --git a/api/src/certification/session/application/invigilator-kit-controller.js b/api/src/certification/session/application/invigilator-kit-controller.js index 2c22a6771a5..5fa73ea85e4 100644 --- a/api/src/certification/session/application/invigilator-kit-controller.js +++ b/api/src/certification/session/application/invigilator-kit-controller.js @@ -1,4 +1,4 @@ -import { usecases } from '../../shared/domain/usecases/index.js'; +import { usecases } from '../domain/usecases/index.js'; import * as invigilatorKitPdf from '../infrastructure/utils/pdf/invigilator-kit-pdf.js'; const getInvigilatorKitPdf = async function (request, h, dependencies = { invigilatorKitPdf }) { diff --git a/api/src/certification/session/application/session-controller.js b/api/src/certification/session/application/session-controller.js index d9979e0c8b3..42ed4f78226 100644 --- a/api/src/certification/session/application/session-controller.js +++ b/api/src/certification/session/application/session-controller.js @@ -1,5 +1,5 @@ import * as events from '../../../../lib/domain/events/index.js'; -import { usecases } from '../../shared/domain/usecases/index.js'; +import { usecases as sessionUsecases } from '../../session/domain/usecases/index.js'; import * as certificationReportSerializer from '../../shared/infrastructure/serializers/jsonapi/certification-report-serializer.js'; import * as sessionSerializer from '../infrastructure/serializers/jsonapi/session-serializer.js'; @@ -7,7 +7,7 @@ const createSession = async function (request, _h, dependencies = { sessionSeria const userId = request.auth.credentials.userId; const session = dependencies.sessionSerializer.deserialize(request.payload); - const newSession = await usecases.createSession({ userId, session }); + const newSession = await sessionUsecases.createSession({ userId, session }); return dependencies.sessionSerializer.serialize({ session: newSession }); }; @@ -17,7 +17,7 @@ const update = async function (request, h, dependencies = { sessionSerializer }) const session = dependencies.sessionSerializer.deserialize(request.payload); session.id = request.params.id; - const updatedSession = await usecases.updateSession({ userId, session }); + const updatedSession = await sessionUsecases.updateSession({ userId, session }); return dependencies.sessionSerializer.serialize({ session: updatedSession }); }; @@ -25,7 +25,7 @@ const update = async function (request, h, dependencies = { sessionSerializer }) const remove = async function (request, h) { const sessionId = request.params.id; - await usecases.deleteSession({ sessionId }); + await sessionUsecases.deleteSession({ sessionId }); return h.response().code(204); }; @@ -41,7 +41,7 @@ const finalize = async function (request, h, dependencies = { certificationRepor .map((data) => dependencies.certificationReportSerializer.deserialize({ data })), ); - const event = await usecases.finalizeSession({ + const event = await sessionUsecases.finalizeSession({ sessionId, examinerGlobalComment, hasIncident, diff --git a/api/src/certification/session/application/session-live-alert-controller.js b/api/src/certification/session/application/session-live-alert-controller.js index 56868b6cb38..b1fdb11ddb0 100644 --- a/api/src/certification/session/application/session-live-alert-controller.js +++ b/api/src/certification/session/application/session-live-alert-controller.js @@ -1,4 +1,4 @@ -import { usecases } from '../../shared/domain/usecases/index.js'; +import { usecases } from '../domain/usecases/index.js'; const dismissLiveAlert = async function (request, h) { const { id: sessionId, candidateId: userId } = request.params; diff --git a/api/src/certification/session/application/session-mass-import-controller.js b/api/src/certification/session/application/session-mass-import-controller.js index f42debf19a0..5f7ae307148 100644 --- a/api/src/certification/session/application/session-mass-import-controller.js +++ b/api/src/certification/session/application/session-mass-import-controller.js @@ -2,7 +2,6 @@ import { usecases as libUsecases } from '../../../../lib/domain/usecases/index.j import * as csvSerializer from '../../../../lib/infrastructure/serializers/csv/csv-serializer.js'; import { usecases } from '../../../../src/certification/session/domain/usecases/index.js'; import * as csvHelpers from '../../shared/application/helpers/csvHelpers.js'; -import { usecases as sharedUsecases } from '../../shared/domain/usecases/index.js'; import { getCsvHeaders } from '../infrastructure/files/sessions-import.js'; const createSessions = async function (request, h) { @@ -11,7 +10,7 @@ const createSessions = async function (request, h) { const { cachedValidatedSessionsKey } = request.payload.data.attributes; - await sharedUsecases.createSessions({ + await usecases.createSessions({ cachedValidatedSessionsKey, certificationCenterId, userId: authenticatedUserId, @@ -31,7 +30,7 @@ const validateSessions = async function (request, h, dependencies = { csvHelpers parsedCsvData, hasBillingMode: certificationCenter.hasBillingMode, }); - const sessionMassImportReport = await sharedUsecases.validateSessions({ + const sessionMassImportReport = await usecases.validateSessions({ sessions, certificationCenterId, userId: authenticatedUserId, diff --git a/api/src/certification/session/application/unfinalize-controller.js b/api/src/certification/session/application/unfinalize-controller.js index 218d5cb2086..f4af4fa8510 100644 --- a/api/src/certification/session/application/unfinalize-controller.js +++ b/api/src/certification/session/application/unfinalize-controller.js @@ -1,4 +1,4 @@ -import { usecases } from '../../shared/domain/usecases/index.js'; +import { usecases } from '../domain/usecases/index.js'; export const unfinalizeSession = async function (request, h) { const sessionId = request.params.id; diff --git a/api/src/certification/session/application/update-cpf-import-status-controller.js b/api/src/certification/session/application/update-cpf-import-status-controller.js index fec29e670ca..02f76d0ee83 100644 --- a/api/src/certification/session/application/update-cpf-import-status-controller.js +++ b/api/src/certification/session/application/update-cpf-import-status-controller.js @@ -1,4 +1,4 @@ -import { usecases } from '../../shared/domain/usecases/index.js'; +import { usecases } from '../domain/usecases/index.js'; const updateFromReceipts = async function (request, _h) { await usecases.integrateCpfProccessingReceipts(); diff --git a/api/src/certification/session/domain/models/Session.js b/api/src/certification/session/domain/models/Session.js index 361c9e11e14..057b8f36d17 100644 --- a/api/src/certification/session/domain/models/Session.js +++ b/api/src/certification/session/domain/models/Session.js @@ -1,7 +1,7 @@ import _ from 'lodash'; -import { config } from '../../../../../lib/config.js'; -import { CertificationVersion } from '../../../../shared/domain/models/CertificationVersion.js'; +import { config } from '../../../../../src/shared/config.js'; +import { CertificationVersion } from '../../../shared/domain/models/CertificationVersion.js'; const CREATED = 'created'; const FINALIZED = 'finalized'; diff --git a/api/src/certification/shared/domain/services/certification-cpf-service.js b/api/src/certification/session/domain/services/certification-cpf-service.js similarity index 98% rename from api/src/certification/shared/domain/services/certification-cpf-service.js rename to api/src/certification/session/domain/services/certification-cpf-service.js index 893478b142d..c0c59728199 100644 --- a/api/src/certification/shared/domain/services/certification-cpf-service.js +++ b/api/src/certification/session/domain/services/certification-cpf-service.js @@ -1,6 +1,6 @@ import lodash from 'lodash'; -import { normalizeAndSortChars } from '../../../../../src/shared/infrastructure/utils/string-utils.js'; +import { normalizeAndSortChars } from '../../../../shared/infrastructure/utils/string-utils.js'; const { isEmpty } = lodash; diff --git a/api/src/certification/session/domain/services/sessions-import-validation-service.js b/api/src/certification/session/domain/services/sessions-import-validation-service.js index e74b4404af5..e59ab4bc6eb 100644 --- a/api/src/certification/session/domain/services/sessions-import-validation-service.js +++ b/api/src/certification/session/domain/services/sessions-import-validation-service.js @@ -3,8 +3,9 @@ import dayjs from 'dayjs'; import { CERTIFICATION_CANDIDATES_ERRORS } from '../../../../../lib/domain/constants/certification-candidates-errors.js'; import { CERTIFICATION_SESSIONS_ERRORS } from '../../../../../lib/domain/constants/sessions-errors.js'; import * as mailCheck from '../../../../shared/mail/infrastructure/services/mail-check.js'; -import * as certificationCpfService from '../../../shared/domain/services/certification-cpf-service.js'; import * as sessionValidator from '../validators/session-validator.js'; +// should be injected +import * as certificationCpfService from './certification-cpf-service.js'; const validateSession = async function ({ session, diff --git a/api/src/certification/course/domain/usecases/abort-certification-course.js b/api/src/certification/session/domain/usecases/abort-certification-course.js similarity index 71% rename from api/src/certification/course/domain/usecases/abort-certification-course.js rename to api/src/certification/session/domain/usecases/abort-certification-course.js index d1c7891a797..8874a7063db 100644 --- a/api/src/certification/course/domain/usecases/abort-certification-course.js +++ b/api/src/certification/session/domain/usecases/abort-certification-course.js @@ -3,9 +3,9 @@ const abortCertificationCourse = async function ({ certificationCourseId, abortReason, }) { - const certificationCourse = await certificationCourseRepository.get(certificationCourseId); + const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId }); certificationCourse.abort(abortReason); - await certificationCourseRepository.update(certificationCourse); + await certificationCourseRepository.update({ certificationCourse }); }; export { abortCertificationCourse }; diff --git a/api/src/certification/session/domain/usecases/add-certification-candidate-to-session.js b/api/src/certification/session/domain/usecases/add-certification-candidate-to-session.js index c61fcece613..436a20d76e3 100644 --- a/api/src/certification/session/domain/usecases/add-certification-candidate-to-session.js +++ b/api/src/certification/session/domain/usecases/add-certification-candidate-to-session.js @@ -35,12 +35,12 @@ const addCertificationCandidateToSession = async function ({ }) { certificationCandidate.sessionId = sessionId; - const session = await sessionRepository.get(sessionId); + const session = await sessionRepository.get({ id: sessionId }); if (!session.canEnrolCandidate()) { throw new CertificationCandidateOnFinalizedSessionError(); } - const isSco = await sessionRepository.isSco({ sessionId }); + const isSco = await sessionRepository.isSco({ id: sessionId }); try { certificationCandidate.validate(isSco); diff --git a/api/src/certification/session/domain/usecases/assign-certification-officer-to-jury-session.js b/api/src/certification/session/domain/usecases/assign-certification-officer-to-jury-session.js index d1e21a028a7..29bb6f1967b 100644 --- a/api/src/certification/session/domain/usecases/assign-certification-officer-to-jury-session.js +++ b/api/src/certification/session/domain/usecases/assign-certification-officer-to-jury-session.js @@ -1,7 +1,7 @@ /** - * @typedef {import('../../../shared/domain/usecases/index.js').JurySessionRepository} JurySessionRepository - * @typedef {import('../../../shared/domain/usecases/index.js').FinalizedSessionRepository} FinalizedSessionRepository - * @typedef {import('../../../shared/domain/usecases/index.js').CertificationOfficerRepository} CertificationOfficerRepository + * @typedef {import('../../domain/usecases/index.js').JurySessionRepository} JurySessionRepository + * @typedef {import('../../domain/usecases/index.js').FinalizedSessionRepository} FinalizedSessionRepository + * @typedef {import('../../domain/usecases/index.js').CertificationOfficerRepository} CertificationOfficerRepository */ /** @@ -17,17 +17,19 @@ const assignCertificationOfficerToJurySession = async function ({ finalizedSessionRepository, certificationOfficerRepository, } = {}) { - const certificationOfficer = await certificationOfficerRepository.get(certificationOfficerId); + const certificationOfficer = await certificationOfficerRepository.get({ userId: certificationOfficerId }); const finalizedSession = await finalizedSessionRepository.get({ sessionId }); finalizedSession.assignCertificationOfficer({ certificationOfficerName: certificationOfficer.getFullName() }); - await finalizedSessionRepository.save(finalizedSession); + await finalizedSessionRepository.save({ finalizedSession }); - return jurySessionRepository.assignCertificationOfficer({ + await jurySessionRepository.assignCertificationOfficer({ id: finalizedSession.sessionId, assignedCertificationOfficerId: certificationOfficer.id, }); + + return jurySessionRepository.get({ id: finalizedSession.sessionId }); }; export { assignCertificationOfficerToJurySession }; diff --git a/api/src/certification/session/domain/usecases/create-session.js b/api/src/certification/session/domain/usecases/create-session.js index 0a89d78a58f..2a9a61e2064 100644 --- a/api/src/certification/session/domain/usecases/create-session.js +++ b/api/src/certification/session/domain/usecases/create-session.js @@ -1,20 +1,17 @@ /** * @typedef {import ('../../../shared/domain/usecases/index.js').CertificationCenterRepository} CertificationCenterRepository * @typedef {import ('../../../shared/domain/usecases/index.js').SessionRepository} SessionRepository - * @typedef {import ('../../../shared/domain/usecases/index.js').UserRepository} UserRepository * @typedef {import ('../../../shared/domain/usecases/index.js').SessionValidator} SessionValidator * @typedef {import ('../../../shared/domain/usecases/index.js').SessionCodeService} SessionCodeService */ -import { ForbiddenAccess } from '../../../../shared/domain/errors.js'; -import { CertificationVersion } from '../../../../shared/domain/models/CertificationVersion.js'; +import { CertificationVersion } from '../../../shared/domain/models/CertificationVersion.js'; import { Session } from '../models/Session.js'; /** * @param {Object} params * @param {CertificationCenterRepository} params.certificationCenterRepository * @param {SessionRepository} params.sessionRepository - * @param {UserRepository} params.userRepository * @param {SessionValidator} params.sessionValidator * @param {SessionCodeService} params.sessionCodeService */ @@ -23,22 +20,17 @@ const createSession = async function ({ session, certificationCenterRepository, sessionRepository, - userRepository, sessionValidator, sessionCodeService, }) { sessionValidator.validate(session); const certificationCenterId = session.certificationCenterId; - const userWithCertifCenters = await userRepository.getWithCertificationCenterMemberships(userId); - if (!userWithCertifCenters.hasAccessToCertificationCenter(certificationCenterId)) { - throw new ForbiddenAccess( - "L'utilisateur n'est pas membre du centre de certification dans lequel il souhaite créer une session", - ); - } const accessCode = sessionCodeService.getNewSessionCode(); - const { isV3Pilot, name: certificationCenterName } = await certificationCenterRepository.get(certificationCenterId); + const { isV3Pilot, name: certificationCenterName } = await certificationCenterRepository.get({ + id: certificationCenterId, + }); const version = isV3Pilot ? CertificationVersion.V3 : CertificationVersion.V2; const domainSession = new Session({ @@ -49,7 +41,7 @@ const createSession = async function ({ createdBy: userId, }); - return sessionRepository.save(domainSession); + return sessionRepository.save({ session: domainSession }); }; export { createSession }; diff --git a/api/src/certification/session/domain/usecases/create-sessions.js b/api/src/certification/session/domain/usecases/create-sessions.js index c83103cbdab..e465ff1859b 100644 --- a/api/src/certification/session/domain/usecases/create-sessions.js +++ b/api/src/certification/session/domain/usecases/create-sessions.js @@ -7,7 +7,7 @@ import bluebird from 'bluebird'; import { NotFoundError } from '../../../../../lib/domain/errors.js'; import { CertificationCandidate } from '../../../../../lib/domain/models/CertificationCandidate.js'; import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.js'; -import { CertificationVersion } from '../../../../shared/domain/models/CertificationVersion.js'; +import { CertificationVersion } from '../../../shared/domain/models/CertificationVersion.js'; import { Session } from '../models/Session.js'; /** @@ -35,7 +35,7 @@ const createSessions = async function ({ throw new NotFoundError(); } - const { isV3Pilot } = await certificationCenterRepository.get(certificationCenterId); + const { isV3Pilot } = await certificationCenterRepository.get({ id: certificationCenterId }); await DomainTransaction.execute(async (domainTransaction) => { return await bluebird.mapSeries(temporaryCachedSessions, async (sessionDTO) => { @@ -82,7 +82,7 @@ async function _saveNewSessionReturningId({ sessionRepository, sessionDTO, domai ...sessionDTO, version: isV3Pilot ? CertificationVersion.V3 : CertificationVersion.V2, }); - return await sessionRepository.save(sessionToSave, domainTransaction); + return await sessionRepository.save({ session: sessionToSave, domainTransaction }); } async function _deleteExistingCandidatesInSession({ certificationCandidateRepository, sessionId, domainTransaction }) { diff --git a/api/src/certification/session/domain/usecases/delete-session.js b/api/src/certification/session/domain/usecases/delete-session.js index 4135fef3558..fa5de62d418 100644 --- a/api/src/certification/session/domain/usecases/delete-session.js +++ b/api/src/certification/session/domain/usecases/delete-session.js @@ -8,15 +8,13 @@ import { SessionStartedDeletionError } from '../errors.js'; /** * @param {Object} params * @param {SessionRepository} params.sessionRepository - * @param {CertificationCourseRepository} params.certificationCourseRepository */ const deleteSession = async function ({ sessionId, sessionRepository, certificationCourseRepository }) { if (await _isSessionStarted(certificationCourseRepository, sessionId)) { - certificationCourseRepository.findCertificationCoursesBySessionId; throw new SessionStartedDeletionError(); } - await sessionRepository.remove(sessionId); + await sessionRepository.remove({ id: sessionId }); }; export { deleteSession }; diff --git a/api/src/certification/session/domain/usecases/delete-unlinked-certification-candidate.js b/api/src/certification/session/domain/usecases/delete-unlinked-certification-candidate.js index 29875800591..0a8cca0bbac 100644 --- a/api/src/certification/session/domain/usecases/delete-unlinked-certification-candidate.js +++ b/api/src/certification/session/domain/usecases/delete-unlinked-certification-candidate.js @@ -1,5 +1,5 @@ /** - * @typedef {import('../../../shared/domain/usecases/index.js').CertificationCandidateRepository} CertificationCandidateRepository + * @typedef {import('./index.js').CertificationCandidateRepository} CertificationCandidateRepository */ import { CertificationCandidateForbiddenDeletionError } from '../errors.js'; @@ -12,10 +12,10 @@ const deleteUnlinkedCertificationCandidate = async function ({ certificationCandidateId, certificationCandidateRepository, }) { - const isNotLinked = await certificationCandidateRepository.isNotLinked(certificationCandidateId); + const isNotLinked = await certificationCandidateRepository.isNotLinked({ id: certificationCandidateId }); if (isNotLinked) { - return certificationCandidateRepository.remove(certificationCandidateId); + return certificationCandidateRepository.remove({ id: certificationCandidateId }); } throw new CertificationCandidateForbiddenDeletionError(); diff --git a/api/src/certification/session/domain/usecases/finalize-session.js b/api/src/certification/session/domain/usecases/finalize-session.js index ccde7bf1be3..1d320646642 100644 --- a/api/src/certification/session/domain/usecases/finalize-session.js +++ b/api/src/certification/session/domain/usecases/finalize-session.js @@ -1,9 +1,9 @@ /** - * @typedef {import('../../../shared/domain/usecases/index.js').SessionRepository} SessionRepository + * @typedef {import('../../../session/domain/usecases/index.js').SessionRepository} SessionRepository * * @typedef {import('../../../shared/domain/usecases/index.js').CertificationCourseRepository} CertificationCourseRepository * - * @typedef {import('../../../shared/domain/usecases/index.js').CertificationReportRepository} CertificationReportRepository + * @typedef {import('../../../session/domain/usecases/index.js').CertificationReportRepository} CertificationReportRepository */ import bluebird from 'bluebird'; @@ -32,11 +32,13 @@ const finalizeSession = async function ({ hasIncident, hasJoiningIssue, }) { - const isSessionAlreadyFinalized = await sessionRepository.isFinalized(sessionId); + const isSessionAlreadyFinalized = await sessionRepository.isFinalized({ id: sessionId }); - const hasNoStartedCertification = await sessionRepository.hasNoStartedCertification(sessionId); + const hasNoStartedCertification = await sessionRepository.hasNoStartedCertification({ id: sessionId }); - const uncompletedCertificationCount = await sessionRepository.countUncompletedCertificationsAssessment(sessionId); + const uncompletedCertificationCount = await sessionRepository.countUncompletedCertificationsAssessment({ + id: sessionId, + }); const abortReasonCount = _countAbortReasons(certificationReports); @@ -69,7 +71,7 @@ const finalizeSession = async function ({ certificationReports.forEach((certifReport) => certifReport.validateForFinalization()); - await certificationReportRepository.finalizeAll(certificationReports); + await certificationReportRepository.finalizeAll({ certificationReports }); const finalizedSession = await sessionRepository.finalize({ id: sessionId, @@ -121,7 +123,7 @@ async function _removeAbortReasonFromCompletedCertificationCourses({ sessionCertificationCourse.isCompleted() ) { sessionCertificationCourse.unabort(); - await certificationCourseRepository.update(sessionCertificationCourse); + await certificationCourseRepository.update({ certificationCourse: sessionCertificationCourse }); } }, ); diff --git a/api/src/certification/session/domain/usecases/get-attendance-sheet.js b/api/src/certification/session/domain/usecases/get-attendance-sheet.js index 846b885a21d..c4eb0fc5804 100644 --- a/api/src/certification/session/domain/usecases/get-attendance-sheet.js +++ b/api/src/certification/session/domain/usecases/get-attendance-sheet.js @@ -1,6 +1,6 @@ /** - * @typedef {import('../../../shared/domain/usecases/index.js').SessionForAttendanceSheetRepository} SessionForAttendanceSheetRepository - * @typedef {import('../../../shared/domain/usecases/index.js').AttendanceSheetPdfUtils} AttendanceSheetPdfUtils + * @typedef {import('../../../session/domain/usecases/index.js').SessionForAttendanceSheetRepository} SessionForAttendanceSheetRepository + * @typedef {import('../../../session/domain/usecases/index.js').AttendanceSheetPdfUtils} AttendanceSheetPdfUtils */ /** @@ -14,7 +14,7 @@ const getAttendanceSheet = async function ({ sessionForAttendanceSheetRepository, attendanceSheetPdfUtils, }) { - const session = await sessionForAttendanceSheetRepository.getWithCertificationCandidates(sessionId); + const session = await sessionForAttendanceSheetRepository.getWithCertificationCandidates({ id: sessionId }); const { attendanceSheet, fileName } = await attendanceSheetPdfUtils.getAttendanceSheetPdfBuffer({ session, diff --git a/api/src/certification/session/domain/usecases/get-invigilator-kit-session-info.js b/api/src/certification/session/domain/usecases/get-invigilator-kit-session-info.js index d48945f80b5..a20486db8d4 100644 --- a/api/src/certification/session/domain/usecases/get-invigilator-kit-session-info.js +++ b/api/src/certification/session/domain/usecases/get-invigilator-kit-session-info.js @@ -1,5 +1,5 @@ /** - * @typedef {import('../../../shared/domain/usecases/index.js').SessionForInvigilatorKitRepository} SessionForInvigilatorKitRepository + * @typedef {import('./index.js').SessionForInvigilatorKitRepository} SessionForInvigilatorKitRepository */ /** @@ -7,7 +7,7 @@ * @param {SessionForInvigilatorKitRepository} params.sessionForInvigilatorKitRepository */ const getInvigilatorKitSessionInfo = async function ({ sessionId, sessionForInvigilatorKitRepository }) { - return sessionForInvigilatorKitRepository.get(sessionId); + return sessionForInvigilatorKitRepository.get({ id: sessionId }); }; export { getInvigilatorKitSessionInfo }; diff --git a/api/src/certification/session/domain/usecases/get-session-certification-candidates.js b/api/src/certification/session/domain/usecases/get-session-certification-candidates.js index 9c8b5028941..bc79579f80c 100644 --- a/api/src/certification/session/domain/usecases/get-session-certification-candidates.js +++ b/api/src/certification/session/domain/usecases/get-session-certification-candidates.js @@ -21,7 +21,7 @@ const getSessionCertificationCandidates = async function ({ candidateRepository, complementaryCertificationRepository, }) { - const candidates = await candidateRepository.findBySessionId(sessionId); + const candidates = await candidateRepository.findBySessionId({ sessionId }); const complementaryCertifications = await getUniqComplementaryCertifications({ candidates, diff --git a/api/src/certification/session/domain/usecases/index.js b/api/src/certification/session/domain/usecases/index.js index 55d3dfcffab..daac21da457 100644 --- a/api/src/certification/session/domain/usecases/index.js +++ b/api/src/certification/session/domain/usecases/index.js @@ -4,24 +4,84 @@ import { fileURLToPath } from 'node:url'; import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js'; import { importNamedExportsFromDirectory } from '../../../../shared/infrastructure/utils/import-named-exports-from-directory.js'; +import { assessmentRepository, sessionRepositories } from '../../infrastructure/repositories/index.js'; +import { cpfExportsStorage } from '../../infrastructure/storage/cpf-exports-storage.js'; +import { cpfReceiptsStorage } from '../../infrastructure/storage/cpf-receipts-storage.js'; +import * as attendanceSheetPdfUtils from '../../infrastructure/utils/pdf/attendance-sheet-pdf.js'; +import * as certificationCpfService from '../services/certification-cpf-service.js'; +import * as sessionCodeService from '../services/session-code-service.js'; +import * as sessionsImportValidationService from '../services/sessions-import-validation-service.js'; +import * as temporarySessionsStorageForMassImportService from '../services/temporary-sessions-storage-for-mass-import-service.js'; +import * as sessionValidator from '../validators/session-validator.js'; + /** * @typedef {import('../../infrastructure/repositories/index.js').ComplementaryCertificationRepository} ComplementaryCertificationRepository + * @typedef {import('../../infrastructure/repositories/index.js').CertificationCourseRepository} CertificationCourseRepository + * @typedef {import('../../infrastructure/repositories/index.js').CandidateRepository} CandidateRepository + * @typedef {import('../../infrastructure/repositories/index.js').CenterRepository} CenterRepository + * @typedef {import('../../infrastructure/repositories/index.js').CertificationCandidateRepository} CertificationCandidateRepository + * @typedef {import('../../infrastructure/repositories/index.js').CertificationCenterRepository} CertificationCenterRepository + * @typedef {import('../validators/session-validator.js')} SessionValidator + * @typedef {import('../services/certification-cpf-service.js')} CertificationCpfService + * @typedef {import('../../infrastructure/utils/pdf/attendance-sheet-pdf.js')} AttendanceSheetPdfUtils + * @typedef {import('../services/temporary-sessions-storage-for-mass-import-service.js').TemporarySessionsStorageForMassImportService} TemporarySessionsStorageForMassImportService + * @typedef {import('../../infrastructure/repositories/index.js').CertificationCpfCityRepository} CertificationCpfCityRepository + * @typedef {import('../../infrastructure/repositories/index.js').CertificationCpfCountryRepository} CertificationCpfCountryRepository + * @typedef {import('../../infrastructure/repositories/index.js').CertificationOfficerRepository} CertificationOfficerRepository + * @typedef {import('../../infrastructure/repositories/index.js').FinalizedSessionRepository} FinalizedSessionRepository + * @typedef {import('../../infrastructure/repositories/index.js').JurySessionRepository} JurySessionRepository + * @typedef {import('../../infrastructure/repositories/index.js').SessionForInvigilatorKitRepository} SessionForInvigilatorKitRepository + * @typedef {import('../../infrastructure/repositories/index.js').AssessmentRepository} AssessmentRepository + * @typedef {import('../../infrastructure/repositories/index.js').IssueReportCategoryRepository} IssueReportCategoryRepository + * @typedef {import('../../infrastructure/repositories/index.js').CertificationIssueReportRepository} CertificationIssueReportRepository + * @typedef {import('../../infrastructure/repositories/index.js').SessionRepository} SessionRepository + * @typedef {import('../../infrastructure/repositories/index.js').CertificationReportRepository} CertificationReportRepository + * @typedef {import('../../infrastructure/repositories/index.js').SessionForAttendanceSheetRepository} SessionForAttendanceSheetRepository + * @typedef {import('../../infrastructure/storage/cpf-receipts-storage.js')} CpfReceiptsStorage + * @typedef {import('../../infrastructure/storage/cpf-exports-storage.js')} CpfExportsStorage **/ -import { sessionRepositories } from '../../../session/infrastructure/repositories/index.js'; -import * as candidateRepository from '../../infrastructure/repositories/candidate-repository.js'; -import * as centerRepository from '../../infrastructure/repositories/center-repository.js'; /** * Using {@link https://jsdoc.app/tags-type "Closure Compiler's syntax"} to document injected dependencies * + * @typedef {assessmentRepository} AssessmentRepository + * @typedef {certificationCourseRepository} CertificationCourseRepository + * @typedef {certificationCenterRepository} CertificationCenterRepository + * @typedef {candidateRepository} CandidateRepository * @typedef {candidateRepository} CandidateRepository * @typedef {centerRepository} CenterRepository + * @typedef {certificationCandidateRepository} CertificationCandidateRepository + * @typedef {certificationChallengeLiveAlertRepository} CertificationChallengeLiveAlertRepository + * @typedef {certificationCpfService} CertificationCpfService + * @typedef {certificationCpfCityRepository} CertificationCpfCityRepository + * @typedef {certificationCpfCountryRepository} CertificationCpfCountryRepository + * @typedef {certificationOfficerRepository} CertificationOfficerRepository * @typedef {complementaryCertificationRepository} ComplementaryCertificationRepository + * @typedef {finalizedSessionRepository} FinalizedSessionRepository + * @typedef {jurySessionRepository} JurySessionRepository + * @typedef {sessionForInvigilatorKitRepository} SessionForInvigilatorKitRepository + * @typedef {issueReportCategoryRepository} IssueReportCategoryRepository + * @typedef {certificationIssueReportRepository} CertificationIssueReportRepository + * @typedef {sessionRepository} SessionRepository + * @typedef {certificationReportRepository} CertificationReportRepository + * @typedef {sessionForAttendanceSheetRepository} SessionForAttendanceSheetRepository + * @typedef {temporarySessionsStorageForMassImportService} TemporarySessionsStorageForMassImportService + * @typedef {sessionValidator} SessionValidator + * @typedef {cpfReceiptsStorage} CpfReceiptsStorage + * @typedef {cpfExportsStorage} CpfExportsStorage + * @typedef {attendanceSheetPdfUtils} AttendanceSheetPdfUtils **/ const dependencies = { - candidateRepository, - centerRepository, - complementaryCertificationRepository: sessionRepositories.complementaryCertificationRepository, + ...sessionRepositories, + assessmentRepository, + certificationCpfService, + sessionCodeService, + sessionsImportValidationService, + temporarySessionsStorageForMassImportService, + sessionValidator, + cpfReceiptsStorage, + cpfExportsStorage, + attendanceSheetPdfUtils, }; const path = dirname(fileURLToPath(import.meta.url)); @@ -34,25 +94,7 @@ const path = dirname(fileURLToPath(import.meta.url)); const usecasesWithoutInjectedDependencies = { ...(await importNamedExportsFromDirectory({ path: join(path, './'), - ignoredFileNames: [ - 'index.js', - 'add-certification-candidate-to-session.js', - 'assign-certification-officer-to-jury-session.js', - 'create-session.js', - 'create-sessions.js', - 'delete-session.js', - 'delete-unlinked-certification-candidate.js', - 'dismiss-live-alert.js', - 'finalize-session.js', - 'get-attendance-sheet.js', - 'get-cpf-presigned-urls.js', - 'get-invigilator-kit-session-info.js', - 'integrate-cpf-processing-receipts.js', - 'update-session.js', - 'upload-cpf-files.js', - 'validate-live-alert.js', - 'validate-sessions.js', - ], + ignoredFileNames: ['index.js'], })), }; diff --git a/api/src/certification/session/domain/usecases/save-certification-issue-report.js b/api/src/certification/session/domain/usecases/save-certification-issue-report.js index 3c54ce3d52b..085146f849d 100644 --- a/api/src/certification/session/domain/usecases/save-certification-issue-report.js +++ b/api/src/certification/session/domain/usecases/save-certification-issue-report.js @@ -14,7 +14,7 @@ const saveCertificationIssueReport = async function ({ categoryId: issueReportCategory.id, }); - return certificationIssueReportRepository.save(certificationIssueReport); + return certificationIssueReportRepository.save({ certificationIssueReport }); }; export { saveCertificationIssueReport }; diff --git a/api/src/certification/session/domain/usecases/unfinalize-session.js b/api/src/certification/session/domain/usecases/unfinalize-session.js index 7a3e6316349..c3e52b5c3c6 100644 --- a/api/src/certification/session/domain/usecases/unfinalize-session.js +++ b/api/src/certification/session/domain/usecases/unfinalize-session.js @@ -1,6 +1,6 @@ /** - * @typedef {import('../../../shared/domain/usecases/index.js').SessionRepository} SessionRepository - * @typedef {import('../../../shared/domain/usecases/index.js').FinalizedSessionRepository} FinalizedSessionRepository + * @typedef {import('./index.js').SessionRepository} SessionRepository + * @typedef {import('./index.js').FinalizedSessionRepository} FinalizedSessionRepository */ import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.js'; @@ -12,13 +12,13 @@ import { SessionAlreadyPublishedError } from '../errors.js'; * @param {FinalizedSessionRepository} params.finalizedSessionRepository */ const unfinalizeSession = async function ({ sessionId, sessionRepository, finalizedSessionRepository }) { - if (await sessionRepository.isPublished(sessionId)) { + if (await sessionRepository.isPublished({ id: sessionId })) { throw new SessionAlreadyPublishedError(); } return DomainTransaction.execute(async (domainTransaction) => { await finalizedSessionRepository.remove({ sessionId, domainTransaction }); - await sessionRepository.unfinalize({ sessionId, domainTransaction }); + await sessionRepository.unfinalize({ id: sessionId, domainTransaction }); }); }; diff --git a/api/src/certification/session/domain/usecases/update-session.js b/api/src/certification/session/domain/usecases/update-session.js index 6902463ba06..619e70e4041 100644 --- a/api/src/certification/session/domain/usecases/update-session.js +++ b/api/src/certification/session/domain/usecases/update-session.js @@ -11,10 +11,10 @@ */ const updateSession = async function ({ session, sessionRepository, sessionValidator }) { sessionValidator.validate(session); - const sessionToUpdate = await sessionRepository.get(session.id); + const sessionToUpdate = await sessionRepository.get({ id: session.id }); Object.assign(sessionToUpdate, session); - return sessionRepository.updateSessionInfo(sessionToUpdate); + return sessionRepository.updateSessionInfo({ session: sessionToUpdate }); }; export { updateSession }; diff --git a/api/src/certification/session/domain/usecases/validate-live-alert.js b/api/src/certification/session/domain/usecases/validate-live-alert.js index 94181449fcf..482f566c476 100644 --- a/api/src/certification/session/domain/usecases/validate-live-alert.js +++ b/api/src/certification/session/domain/usecases/validate-live-alert.js @@ -1,12 +1,10 @@ /** * @typedef {import('../../../shared/domain/usecases/index.js').CertificationChallengeLiveAlertRepository} CertificationChallengeLiveAlertRepository * - * * @typedef {import('../../../shared/domain/usecases/index.js').AssessmentRepository} AssessmentRepository * * @typedef {import('../../../shared/domain/usecases/index.js').IssueReportCategoryRepository} IssueReportCategoryRepository * - * * @typedef {import('../../../shared/domain/usecases/index.js').CertificationIssueReportRepository} CertificationIssueReportRepository */ @@ -58,7 +56,7 @@ export const validateLiveAlert = async ({ 'Le signalement a été validé par le surveillant pendant la session. Une nouvelle question a été proposée au candidat'; certificationIssueReport.resolveAutomatically(ISSUE_REPORT_RESOLUTION); - await certificationIssueReportRepository.save(certificationIssueReport); + await certificationIssueReportRepository.save({ certificationIssueReport }); await certificationChallengeLiveAlertRepository.save({ certificationChallengeLiveAlert, diff --git a/api/src/certification/session/domain/usecases/validate-sessions.js b/api/src/certification/session/domain/usecases/validate-sessions.js index d8db28441d8..01a1b9d5850 100644 --- a/api/src/certification/session/domain/usecases/validate-sessions.js +++ b/api/src/certification/session/domain/usecases/validate-sessions.js @@ -1,5 +1,5 @@ /** - * @typedef {import ('../../../shared/domain/usecases/index.js').dependencies} deps + * @typedef {import ('../../../session/domain/usecases/index.js').dependencies} deps */ import bluebird from 'bluebird'; @@ -35,7 +35,7 @@ const validateSessions = async function ({ sessionsImportValidationService, temporarySessionsStorageForMassImportService, }) { - const { name: certificationCenter, isSco } = await certificationCenterRepository.get(certificationCenterId); + const { name: certificationCenter, isSco } = await certificationCenterRepository.get({ id: certificationCenterId }); const sessionsMassImportReport = new SessionMassImportReport(); const translate = i18n.__; diff --git a/api/src/certification/session/domain/validators/session-validator.js b/api/src/certification/session/domain/validators/session-validator.js index 901be1d6a0f..273e802eb74 100644 --- a/api/src/certification/session/domain/validators/session-validator.js +++ b/api/src/certification/session/domain/validators/session-validator.js @@ -4,8 +4,8 @@ import BaseJoi from 'joi'; import { CERTIFICATION_SESSIONS_ERRORS } from '../../../../../lib/domain/constants/sessions-errors.js'; import { types } from '../../../../../lib/domain/models/CertificationCenter.js'; import { EntityValidationError } from '../../../../../src/shared/domain/errors.js'; -import { CertificationVersion } from '../../../../shared/domain/models/CertificationVersion.js'; import { identifiersType } from '../../../../shared/domain/types/identifiers-type.js'; +import { CertificationVersion } from '../../../shared/domain/models/CertificationVersion.js'; import { statuses } from '../models/Session.js'; const Joi = BaseJoi.extend(JoiDate); diff --git a/api/src/certification/session/infrastructure/repositories/candidate-repository.js b/api/src/certification/session/infrastructure/repositories/candidate-repository.js index 854464fdd1e..35a0e5361aa 100644 --- a/api/src/certification/session/infrastructure/repositories/candidate-repository.js +++ b/api/src/certification/session/infrastructure/repositories/candidate-repository.js @@ -1,7 +1,7 @@ import { knex } from '../../../../../db/knex-database-connection.js'; import { Candidate } from '../../domain/models/Candidate.js'; -const findBySessionId = async function (sessionId) { +const findBySessionId = async function ({ sessionId }) { const results = await knex .select({ certificationCandidate: 'certification-candidates.*', diff --git a/api/src/certification/shared/infrastructure/repositories/certification-candidate-repository.js b/api/src/certification/session/infrastructure/repositories/certification-candidate-repository.js similarity index 96% rename from api/src/certification/shared/infrastructure/repositories/certification-candidate-repository.js rename to api/src/certification/session/infrastructure/repositories/certification-candidate-repository.js index e18dad7753b..0be462161b5 100644 --- a/api/src/certification/shared/infrastructure/repositories/certification-candidate-repository.js +++ b/api/src/certification/session/infrastructure/repositories/certification-candidate-repository.js @@ -11,8 +11,8 @@ import { CertificationCandidate } from '../../../../../lib/domain/models/Certifi import { DomainTransaction } from '../../../../../lib/infrastructure/DomainTransaction.js'; import { BookshelfCertificationCandidate } from '../../../../../lib/infrastructure/orm-models/CertificationCandidate.js'; import * as bookshelfToDomainConverter from '../../../../../lib/infrastructure/utils/bookshelf-to-domain-converter.js'; -import { logger } from '../../../../../src/shared/infrastructure/utils/logger.js'; -import { normalize } from '../../../../../src/shared/infrastructure/utils/string-utils.js'; +import { logger } from '../../../../shared/infrastructure/utils/logger.js'; +import { normalize } from '../../../../shared/infrastructure/utils/string-utils.js'; import { ComplementaryCertification } from '../../../complementary-certification/domain/models/ComplementaryCertification.js'; const linkToUser = async function ({ id, userId }) { @@ -75,18 +75,18 @@ const saveInSession = async function ({ } }; -const remove = async function (certificationCandidateId) { +const remove = async function ({ id }) { await knex.transaction(async (trx) => { - await trx('complementary-certification-subscriptions').where({ certificationCandidateId }).del(); - return trx('certification-candidates').where({ id: certificationCandidateId }).del(); + await trx('complementary-certification-subscriptions').where({ certificationCandidateId: id }).del(); + return trx('certification-candidates').where({ id }).del(); }); return true; }; -const isNotLinked = async function (certificationCandidateId) { +const isNotLinked = async function ({ id }) { const notLinkedCandidate = await BookshelfCertificationCandidate.where({ - id: certificationCandidateId, + id, userId: null, }).fetch({ require: false, columns: ['id'] }); diff --git a/api/src/certification/shared/infrastructure/repositories/certification-cpf-city-repository.js b/api/src/certification/session/infrastructure/repositories/certification-cpf-city-repository.js similarity index 89% rename from api/src/certification/shared/infrastructure/repositories/certification-cpf-city-repository.js rename to api/src/certification/session/infrastructure/repositories/certification-cpf-city-repository.js index 033a476d5c3..f8bc1a5188c 100644 --- a/api/src/certification/shared/infrastructure/repositories/certification-cpf-city-repository.js +++ b/api/src/certification/session/infrastructure/repositories/certification-cpf-city-repository.js @@ -1,5 +1,5 @@ import { knex } from '../../../../../db/knex-database-connection.js'; -import { CertificationCpfCity } from '../../domain/models/CertificationCpfCity.js'; +import { CertificationCpfCity } from '../../../shared/domain/models/CertificationCpfCity.js'; const COLUMNS = ['id', 'name', 'postalCode', 'INSEECode', 'isActualName']; diff --git a/api/src/certification/shared/infrastructure/repositories/certification-cpf-country-repository.js b/api/src/certification/session/infrastructure/repositories/certification-cpf-country-repository.js similarity index 78% rename from api/src/certification/shared/infrastructure/repositories/certification-cpf-country-repository.js rename to api/src/certification/session/infrastructure/repositories/certification-cpf-country-repository.js index fdb04538914..74325aa6591 100644 --- a/api/src/certification/shared/infrastructure/repositories/certification-cpf-country-repository.js +++ b/api/src/certification/session/infrastructure/repositories/certification-cpf-country-repository.js @@ -1,5 +1,5 @@ import { knex } from '../../../../../db/knex-database-connection.js'; -import { CertificationCpfCountry } from '../../../../certification/shared/domain/models/CertificationCpfCountry.js'; +import { CertificationCpfCountry } from '../../../shared/domain/models/CertificationCpfCountry.js'; const getByMatcher = async function ({ matcher }) { const COLUMNS = ['id', 'code', 'commonName', 'originalName', 'matcher']; diff --git a/api/src/certification/session/infrastructure/repositories/certification-officer-repository.js b/api/src/certification/session/infrastructure/repositories/certification-officer-repository.js index 0e3d45bb22f..d6134a624c8 100644 --- a/api/src/certification/session/infrastructure/repositories/certification-officer-repository.js +++ b/api/src/certification/session/infrastructure/repositories/certification-officer-repository.js @@ -2,14 +2,14 @@ import { knex } from '../../../../../db/knex-database-connection.js'; import { UserNotFoundError } from '../../../../../lib/domain/errors.js'; import { CertificationOfficer } from '../../domain/models/CertificationOfficer.js'; -const get = async function (certificationOfficerId) { +const get = async function ({ userId }) { const certificationOfficer = await knex('users') .select(['id', 'firstName', 'lastName']) - .where({ id: certificationOfficerId }) + .where({ id: userId }) .first(); if (!certificationOfficer) { - throw new UserNotFoundError(`User not found for ID ${certificationOfficerId}`); + throw new UserNotFoundError(`User not found for ID ${userId}`); } return _toDomain(certificationOfficer); }; diff --git a/api/src/certification/session/infrastructure/repositories/finalized-session-repository.js b/api/src/certification/session/infrastructure/repositories/finalized-session-repository.js index 8dee72ede74..9e570786f28 100644 --- a/api/src/certification/session/infrastructure/repositories/finalized-session-repository.js +++ b/api/src/certification/session/infrastructure/repositories/finalized-session-repository.js @@ -5,7 +5,7 @@ import { NotFoundError } from '../../../../../lib/domain/errors.js'; import { FinalizedSession } from '../../../../../lib/domain/models/index.js'; import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.js'; -const save = async function (finalizedSession) { +const save = async function ({ finalizedSession }) { await knex('finalized-sessions').insert(_toDTO(finalizedSession)).onConflict('sessionId').merge(); return finalizedSession; }; diff --git a/api/src/certification/session/infrastructure/repositories/index.js b/api/src/certification/session/infrastructure/repositories/index.js index 0749f2ddc55..d6a81df7e9d 100644 --- a/api/src/certification/session/infrastructure/repositories/index.js +++ b/api/src/certification/session/infrastructure/repositories/index.js @@ -1,14 +1,68 @@ +import * as certificationIssueReportRepository from '../../../../certification/shared/infrastructure/repositories/certification-issue-report-repository.js'; +import * as issueReportCategoryRepository from '../../../../certification/shared/infrastructure/repositories/issue-report-category-repository.js'; +import * as assessmentRepository from '../../../../shared/infrastructure/repositories/assessment-repository.js'; import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js'; import * as complementaryCertificationApi from '../../../complementary-certification/application/api/complementary-certification-api.js'; +import * as sessionForAttendanceSheetRepository from '../../../session/infrastructure/repositories/session-for-attendance-sheet-repository.js'; +import * as certificationCenterRepository from '../../../shared/infrastructure/repositories/certification-center-repository.js'; +import * as certificationChallengeLiveAlertRepository from '../../../shared/infrastructure/repositories/certification-challenge-live-alert-repository.js'; +import * as certificationCourseRepository from '../../../shared/infrastructure/repositories/certification-course-repository.js'; +import * as certificationReportRepository from '../../../shared/infrastructure/repositories/certification-report-repository.js'; +import * as candidateRepository from './candidate-repository.js'; +import * as centerRepository from './center-repository.js'; +import * as certificationCandidateRepository from './certification-candidate-repository.js'; +import * as certificationCpfCityRepository from './certification-cpf-city-repository.js'; +import * as certificationCpfCountryRepository from './certification-cpf-country-repository.js'; +import * as certificationOfficerRepository from './certification-officer-repository.js'; import * as complementaryCertificationRepository from './complementary-certification-repository.js'; +import * as finalizedSessionRepository from './finalized-session-repository.js'; +import * as jurySessionRepository from './jury-session-repository.js'; +import * as sessionForInvigilatorKitRepository from './session-for-invigilator-kit-repository.js'; +import * as sessionRepository from './session-repository.js'; /** * Using {@link https://jsdoc.app/tags-type "Closure Compiler's syntax"} to document injected dependencies * + * @typedef {assessmentRepository} AssessmentRepository * @typedef {complementaryCertificationRepository} ComplementaryCertificationRepository + * @typedef {candidateRepository} CandidateRepository + * @typedef {certificationCenterRepository} CertificationCenterRepository + * @typedef {centerRepository} CenterRepository + * @typedef {certificationCandidateRepository} CertificationCandidateRepository + * @typedef {certificationCourseRepository} CertificationCourseRepository + * @typedef {certificationChallengeLiveAlertRepository} CertificationChallengeLiveAlertRepository + * @typedef {certificationCpfCityRepository} CertificationCpfCityRepository + * @typedef {certificationCpfCountryRepository} CertificationCpfCountryRepository + * @typedef {certificationOfficerRepository} CertificationOfficerRepository + * @typedef {finalizedSessionRepository} FinalizedSessionRepository + * @typedef {jurySessionRepository} JurySessionRepository + * @typedef {sessionForInvigilatorKitRepository} SessionForInvigilatorKitRepository + * @typedef {issueReportCategoryRepository} IssueReportCategoryRepository + * @typedef {certificationIssueReportRepository} CertificationIssueReportRepository + * @typedef {sessionRepository} SessionRepository + * @typedef {certificationReportRepository} CertificationReportRepository + * @typedef {sessionForAttendanceSheetRepository} SessionForAttendanceSheetRepository */ const repositoriesWithoutInjectedDependencies = { + assessmentRepository, complementaryCertificationRepository, + candidateRepository, + certificationCenterRepository, + centerRepository, + certificationCandidateRepository, + certificationCourseRepository, + certificationChallengeLiveAlertRepository, + certificationCpfCityRepository, + certificationCpfCountryRepository, + certificationOfficerRepository, + finalizedSessionRepository, + jurySessionRepository, + sessionForInvigilatorKitRepository, + issueReportCategoryRepository, + certificationIssueReportRepository, + sessionRepository, + certificationReportRepository, + sessionForAttendanceSheetRepository, }; /** @@ -22,4 +76,4 @@ const dependencies = { const sessionRepositories = injectDependencies(repositoriesWithoutInjectedDependencies, dependencies); -export { sessionRepositories }; +export { assessmentRepository, sessionRepositories }; diff --git a/api/src/certification/session/infrastructure/repositories/jury-session-repository.js b/api/src/certification/session/infrastructure/repositories/jury-session-repository.js index c111cee3a3f..ee1dd3fcdaf 100644 --- a/api/src/certification/session/infrastructure/repositories/jury-session-repository.js +++ b/api/src/certification/session/infrastructure/repositories/jury-session-repository.js @@ -1,8 +1,9 @@ import { knex } from '../../../../../db/knex-database-connection.js'; -import { PGSQL_UNIQUE_CONSTRAINT_VIOLATION_ERROR } from '../../../../../db/pgsql-errors.js'; +import { PGSQL_FOREIGN_KEY_VIOLATION_ERROR } from '../../../../../db/pgsql-errors.js'; import { NotFoundError } from '../../../../../lib/domain/errors.js'; import { JurySession, statuses } from '../../../../../lib/domain/models/JurySession.js'; import { fetchPage } from '../../../../../lib/infrastructure/utils/knex-utils.js'; +import { logger } from '../../../../shared/infrastructure/utils/logger.js'; import { CertificationOfficer } from '../../domain/models/CertificationOfficer.js'; const COLUMNS = Object.freeze([ @@ -17,7 +18,7 @@ const ALIASED_COLUMNS = Object.freeze({ juryCommentAuthorLastName: 'jury-comment-authors.lastName', }); -const get = async function (id) { +const get = async function ({ id }) { const jurySessionDTO = await knex .select(COLUMNS) .select(ALIASED_COLUMNS) @@ -57,13 +58,18 @@ const findPaginatedFiltered = async function ({ filters, page }) { const assignCertificationOfficer = async function ({ id, assignedCertificationOfficerId }) { try { - await knex('sessions').where({ id }).update({ assignedCertificationOfficerId }).returning('*'); - return this.get(id); + const updatedLines = await knex('sessions').where({ id }).update({ assignedCertificationOfficerId }); + if (updatedLines === 0) { + throw new NotFoundError(`La session d'id ${id} n'existe pas.`); + } } catch (error) { - if (error.code === PGSQL_UNIQUE_CONSTRAINT_VIOLATION_ERROR) { + if (error.code === PGSQL_FOREIGN_KEY_VIOLATION_ERROR) { throw new NotFoundError(`L'utilisateur d'id ${assignedCertificationOfficerId} n'existe pas`); } - throw new NotFoundError(`La session d'id ${id} n'existe pas.`); + if (error instanceof NotFoundError) { + throw error; + } + logger.error(error); } }; diff --git a/api/src/certification/session/infrastructure/repositories/session-for-attendance-sheet-repository.js b/api/src/certification/session/infrastructure/repositories/session-for-attendance-sheet-repository.js index 51285b721da..f0ccd0efa9d 100644 --- a/api/src/certification/session/infrastructure/repositories/session-for-attendance-sheet-repository.js +++ b/api/src/certification/session/infrastructure/repositories/session-for-attendance-sheet-repository.js @@ -3,7 +3,7 @@ import { NotFoundError } from '../../../../shared/domain/errors.js'; import { CertificationCandidateForAttendanceSheet } from '../../domain/read-models/CertificationCandidateForAttendanceSheet.js'; import { SessionForAttendanceSheet } from '../../domain/read-models/SessionForAttendanceSheet.js'; -const getWithCertificationCandidates = async function (sessionId) { +const getWithCertificationCandidates = async function ({ id }) { const results = await knex .select( 'sessions.id', @@ -43,7 +43,7 @@ const getWithCertificationCandidates = async function (sessionId) { 'certification-candidates.organizationLearnerId', ) .groupBy('sessions.id', 'certification-centers.id', 'organizations.id') - .where({ 'sessions.id': sessionId }) + .where({ 'sessions.id': id }) .first(); if (!results) { diff --git a/api/src/certification/session/infrastructure/repositories/session-for-invigilator-kit-repository.js b/api/src/certification/session/infrastructure/repositories/session-for-invigilator-kit-repository.js index d72ff4b3a41..7e7d2ee834e 100644 --- a/api/src/certification/session/infrastructure/repositories/session-for-invigilator-kit-repository.js +++ b/api/src/certification/session/infrastructure/repositories/session-for-invigilator-kit-repository.js @@ -1,7 +1,7 @@ import { knex } from '../../../../../db/knex-database-connection.js'; import { SessionForInvigilatorKit } from '../../domain/read-models/SessionForInvigilatorKit.js'; -const get = async function (idSession) { +const get = async function ({ id }) { const results = await knex .select( 'sessions.id', @@ -15,7 +15,7 @@ const get = async function (idSession) { 'sessions.version', ) .from('sessions') - .where({ 'sessions.id': idSession }) + .where({ 'sessions.id': id }) .first(); return _toDomain(results); diff --git a/api/src/certification/session/infrastructure/repositories/session-repository.js b/api/src/certification/session/infrastructure/repositories/session-repository.js index 125e90d3c84..aa22b4254ac 100644 --- a/api/src/certification/session/infrastructure/repositories/session-repository.js +++ b/api/src/certification/session/infrastructure/repositories/session-repository.js @@ -10,10 +10,10 @@ import { ComplementaryCertification } from '../../../session/domain/models/Compl import { ComplementaryCertificationKeys } from '../../../shared/domain/models/ComplementaryCertificationKeys.js'; import { Session } from '../../domain/models/Session.js'; -const save = async function (sessionData, { knexTransaction } = DomainTransaction.emptyTransaction()) { - const knexConn = knexTransaction ?? knex; - sessionData = _.omit(sessionData, ['certificationCandidates']); - const [savedSession] = await knexConn('sessions').insert(sessionData).returning('*'); +const save = async function ({ session, domainTransaction = DomainTransaction.emptyTransaction() }) { + const knexConn = domainTransaction.knexTransaction ?? knex; + session = _.omit(session, ['certificationCandidates']); + const [savedSession] = await knexConn('sessions').insert(session).returning('*'); return new Session(savedSession); }; @@ -25,18 +25,18 @@ const saveSessions = async function (sessionsData) { return knex.batchInsert('sessions', sessions); }; -const isFinalized = async function (id) { +const isFinalized = async function ({ id }) { const session = await knex.select('id').from('sessions').where({ id }).whereNotNull('finalizedAt').first(); return Boolean(session); }; -const isPublished = async function (id) { +const isPublished = async function ({ id }) { const isPublished = await knex.select(1).from('sessions').where({ id }).whereNotNull('publishedAt').first(); return Boolean(isPublished); }; -const get = async function (sessionId) { - const foundSession = await knex.select('*').from('sessions').where({ id: sessionId }).first(); +const get = async function ({ id }) { + const foundSession = await knex.select('*').from('sessions').where({ id }).first(); if (!foundSession) { throw new NotFoundError("La session n'existe pas ou son accès est restreint"); } @@ -53,8 +53,8 @@ const isSessionExistingBySessionAndCertificationCenterIds = async function ({ se return Boolean(session); }; -const getWithCertificationCandidates = async function (sessionId) { - const session = await knex.from('sessions').where({ 'sessions.id': sessionId }).first(); +const getWithCertificationCandidates = async function ({ id }) { + const session = await knex.from('sessions').where({ id }).first(); if (!session) { throw new NotFoundError("La session n'existe pas ou son accès est restreint"); @@ -79,13 +79,13 @@ const getWithCertificationCandidates = async function (sessionId) { 'complementary-certification-subscriptions.complementaryCertificationId', ) .groupBy('certification-candidates.id', 'complementary-certifications.id') - .where({ sessionId }) + .where({ sessionId: id }) .orderByRaw('LOWER(??) ASC, LOWER(??) ASC', ['lastName', 'firstName']); return _toDomain({ ...session, certificationCandidates }); }; -const updateSessionInfo = async function (session) { +const updateSessionInfo = async function ({ session }) { const sessionDataToUpdate = _.pick(session, [ 'address', 'room', @@ -100,7 +100,7 @@ const updateSessionInfo = async function (session) { return new Session(updatedSession); }; -const doesUserHaveCertificationCenterMembershipForSession = async function (userId, sessionId) { +const doesUserHaveCertificationCenterMembershipForSession = async function ({ userId, sessionId }) { const sessions = await knex .select('sessions.id') .from('sessions') @@ -126,10 +126,10 @@ const finalize = async function ({ id, examinerGlobalComment, hasIncident, hasJo return new Session(finalizedSession); }; -const unfinalize = async function ({ sessionId, domainTransaction = DomainTransaction.emptyTransaction() }) { +const unfinalize = async function ({ id, domainTransaction = DomainTransaction.emptyTransaction() }) { const knexConn = domainTransaction.knexTransaction ?? knex; const updates = await knexConn('sessions') - .where({ id: sessionId }) + .where({ id }) .update({ finalizedAt: null, assignedCertificationOfficerId: null }); if (updates === 0) { throw new NotFoundError("La session n'existe pas ou son accès est restreint"); @@ -146,21 +146,23 @@ const updatePublishedAt = async function ({ id, publishedAt }) { return new Session(publishedSession); }; -const isSco = async function ({ sessionId }) { +const isSco = async function ({ id }) { const result = await knex .select('certification-centers.type') .from('sessions') - .where('sessions.id', '=', sessionId) + .where('sessions.id', '=', id) .innerJoin('certification-centers', 'certification-centers.id', 'sessions.certificationCenterId') .first(); return result.type === CertificationCenter.types.SCO; }; -const remove = async function (sessionId) { +const remove = async function ({ id }) { await knex.transaction(async (trx) => { - const certificationCandidateIdsInSession = await knex('certification-candidates').where({ sessionId }).pluck('id'); - const supervisorAccessIds = await knex('supervisor-accesses').where({ sessionId }).pluck('id'); + const certificationCandidateIdsInSession = await knex('certification-candidates') + .where({ sessionId: id }) + .pluck('id'); + const supervisorAccessIds = await knex('supervisor-accesses').where({ sessionId: id }).pluck('id'); if (supervisorAccessIds) { await trx('supervisor-accesses').whereIn('id', supervisorAccessIds).del(); @@ -172,14 +174,14 @@ const remove = async function (sessionId) { .del(); await trx('certification-candidates').whereIn('id', certificationCandidateIdsInSession).del(); } - const nbSessionsDeleted = await trx('sessions').where('id', sessionId).del(); + const nbSessionsDeleted = await trx('sessions').where('id', id).del(); if (nbSessionsDeleted === 0) throw new NotFoundError(); }); return; }; -const hasSomeCleaAcquired = async function (sessionId) { +const hasSomeCleaAcquired = async function ({ id }) { const result = await knex .select(1) .from('sessions') @@ -199,7 +201,7 @@ const hasSomeCleaAcquired = async function (sessionId) { 'complementary-certification-course-results.complementaryCertificationCourseId', 'complementary-certification-courses.id', ) - .where('sessions.id', sessionId) + .where('sessions.id', id) .whereNotNull('sessions.publishedAt') .where('complementary-certification-course-results.acquired', true) .where('complementary-certifications.key', ComplementaryCertificationKeys.CLEA) @@ -207,18 +209,18 @@ const hasSomeCleaAcquired = async function (sessionId) { return Boolean(result); }; -const hasNoStartedCertification = async function (sessionId) { - const result = await knex.select(1).from('certification-courses').where('sessionId', sessionId).first(); +const hasNoStartedCertification = async function ({ id }) { + const result = await knex.select(1).from('certification-courses').where('sessionId', id).first(); return !result; }; -const countUncompletedCertificationsAssessment = async function (sessionId) { +const countUncompletedCertificationsAssessment = async function ({ id }) { const { count } = await knex .count('certification-courses.id') .from('certification-courses') .join('assessments', 'certification-courses.id', 'certificationCourseId') .whereIn('state', CertificationAssessment.uncompletedAssessmentStates) - .andWhere({ sessionId }) + .andWhere({ sessionId: id }) .first(); return count; }; diff --git a/api/src/certification/session/domain/models/CertificationChallengeLiveAlert.js b/api/src/certification/shared/domain/models/CertificationChallengeLiveAlert.js similarity index 100% rename from api/src/certification/session/domain/models/CertificationChallengeLiveAlert.js rename to api/src/certification/shared/domain/models/CertificationChallengeLiveAlert.js diff --git a/api/lib/domain/models/CertificationCourse.js b/api/src/certification/shared/domain/models/CertificationCourse.js similarity index 97% rename from api/lib/domain/models/CertificationCourse.js rename to api/src/certification/shared/domain/models/CertificationCourse.js index 7be51b7461b..fb8f42e1f81 100644 --- a/api/lib/domain/models/CertificationCourse.js +++ b/api/src/certification/shared/domain/models/CertificationCourse.js @@ -2,8 +2,8 @@ import JoiDate from '@joi/date'; import BaseJoi from 'joi'; import _ from 'lodash'; const Joi = BaseJoi.extend(JoiDate); -import { EntityValidationError } from '../../../src/shared/domain/errors.js'; -import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js'; +import { EntityValidationError } from '../../../../shared/domain/errors.js'; +import { CertificationVersion } from './CertificationVersion.js'; export const ABORT_REASONS = { CANDIDATE: 'candidate', diff --git a/api/src/shared/domain/models/CertificationVersion.js b/api/src/certification/shared/domain/models/CertificationVersion.js similarity index 100% rename from api/src/shared/domain/models/CertificationVersion.js rename to api/src/certification/shared/domain/models/CertificationVersion.js diff --git a/api/src/certification/shared/domain/usecases/index.js b/api/src/certification/shared/domain/usecases/index.js index d0a310c1ab1..03e85f661ec 100644 --- a/api/src/certification/shared/domain/usecases/index.js +++ b/api/src/certification/shared/domain/usecases/index.js @@ -15,33 +15,14 @@ import { injectDependencies } from '../../../../shared/infrastructure/utils/depe import { importNamedExportsFromDirectory } from '../../../../shared/infrastructure/utils/import-named-exports-from-directory.js'; import * as certificateRepository from '../../../course/infrastructure/repositories/certificate-repository.js'; import * as v3CertificationCourseDetailsForAdministrationRepository from '../../../course/infrastructure/repositories/v3-certification-course-details-for-administration-repository.js'; -import * as sessionCodeService from '../../../session/domain/services/session-code-service.js'; -import * as sessionsImportValidationService from '../../../session/domain/services/sessions-import-validation-service.js'; -import * as temporarySessionsStorageForMassImportService from '../../../session/domain/services/temporary-sessions-storage-for-mass-import-service.js'; -import * as sessionValidator from '../../../session/domain/validators/session-validator.js'; +import * as flashAlgorithmService from '../../../flash-certification/domain/services/algorithm-methods/flash.js'; +import * as flashAlgorithmConfigurationRepository from '../../../flash-certification/infrastructure/repositories/flash-algorithm-configuration-repository.js'; import * as candidateRepository from '../../../session/infrastructure/repositories/candidate-repository.js'; -import * as certificationChallengeLiveAlertRepository from '../../../session/infrastructure/repositories/certification-challenge-live-alert-repository.js'; -import * as certificationOfficerRepository from '../../../session/infrastructure/repositories/certification-officer-repository.js'; -import * as cpfCertificationResultRepository from '../../../session/infrastructure/repositories/cpf-certification-result-repository.js'; -import * as cpfExportRepository from '../../../session/infrastructure/repositories/cpf-export-repository.js'; -import * as finalizedSessionRepository from '../../../session/infrastructure/repositories/finalized-session-repository.js'; -import * as jurySessionRepository from '../../../session/infrastructure/repositories/jury-session-repository.js'; -import * as sessionForAttendanceSheetRepository from '../../../session/infrastructure/repositories/session-for-attendance-sheet-repository.js'; -import * as sessionForInvigilatorKitRepository from '../../../session/infrastructure/repositories/session-for-invigilator-kit-repository.js'; -import * as sessionRepository from '../../../session/infrastructure/repositories/session-repository.js'; -import { cpfExportsStorage } from '../../../session/infrastructure/storage/cpf-exports-storage.js'; -import { cpfReceiptsStorage } from '../../../session/infrastructure/storage/cpf-receipts-storage.js'; -import * as attendanceSheetPdfUtils from '../../../session/infrastructure/utils/pdf/attendance-sheet-pdf.js'; import * as certificationAssessmentRepository from '../../../shared/infrastructure/repositories/certification-assessment-repository.js'; -import * as certificationCandidateRepository from '../../../shared/infrastructure/repositories/certification-candidate-repository.js'; -import * as certificationCenterRepository from '../../../shared/infrastructure/repositories/certification-center-repository.js'; -import * as certificationCpfCityRepository from '../../../shared/infrastructure/repositories/certification-cpf-city-repository.js'; -import * as certificationCpfCountryRepository from '../../../shared/infrastructure/repositories/certification-cpf-country-repository.js'; +import * as certificationChallengeLiveAlertRepository from '../../../shared/infrastructure/repositories/certification-challenge-live-alert-repository.js'; import * as certificationIssueReportRepository from '../../../shared/infrastructure/repositories/certification-issue-report-repository.js'; import * as certificationReportRepository from '../../../shared/infrastructure/repositories/certification-report-repository.js'; -import * as issueReportCategoryRepository from '../../../shared/infrastructure/repositories/issue-report-category-repository.js'; import * as certificationCourseRepository from '../../infrastructure/repositories/certification-course-repository.js'; -import * as certificationCpfService from '../services/certification-cpf-service.js'; import * as mailService from '../services/mail-service.js'; /** @@ -50,78 +31,39 @@ import * as mailService from '../services/mail-service.js'; * @typedef {answerRepository} AnswerRepository * @typedef {assessmentRepository} AssessmentRepository * @typedef {assessmentResultRepository} AssessmentResultRepository - * @typedef {attendanceSheetPdfUtils} AttendanceSheetPdfUtils - * @typedef {badgeRepository} BadgeRepository * @typedef {candidateRepository} CandidateRepository * @typedef {certificationAssessmentRepository} CertificationAssessmentRepository - * @typedef {certificationCandidateRepository} CertificationCandidateRepository - * @typedef {certificationCenterRepository} CertificationCenterRepository * @typedef {certificationChallengeLiveAlertRepository} CertificationChallengeLiveAlertRepository * @typedef {certificationCourseRepository} CertificationCourseRepository - * @typedef {certificationCpfService} CertificationCpfService - * @typedef {certificationIssueReportRepository} CertificationIssueReportRepository * @typedef {challengeRepository} ChallengeRepository - * @typedef {certificationCpfCityRepository} CertificationCpfCityRepository - * @typedef {certificationCpfCountryRepository} CertificationCpfCountryRepository - * @typedef {certificationOfficerRepository} CertificationOfficerRepository * @typedef {competenceMarkRepository} CompetenceMarkRepository * @typedef {competenceRepository} CompetenceRepository * @typedef {complementaryCertificationRepository} ComplementaryCertificationRepository - * @typedef {cpfExportRepository} CpfExportRepository - * @typedef {finalizedSessionRepository} FinalizedSessionRepository - * @typedef {issueReportCategoryRepository} IssueReportCategoryRepository - * @typedef {jurySessionRepository} JurySessionRepository + * @typedef {flashAlgorithmService} FlashAlgorithmService * @typedef {mailService} MailService - * @typedef {sessionCodeService} SessionCodeService - * @typedef {sessionForAttendanceSheetRepository} SessionForAttendanceSheetRepository - * @typedef {sessionForInvigilatorKitRepository} SessionForInvigilatorKitRepository - * @typedef {cpfCertificationResultRepository} CpfCertificationResultRepository * @typedef {v3CertificationCourseDetailsForAdministrationRepository} V3CertificationCourseDetailsForAdministrationRepository - * @typedef {sessionRepository} SessionRepository - * @typedef {sessionValidator} SessionValidator * @typedef {userRepository} UserRepository - * @typedef {cpfReceiptsStorage} CpfReceiptsStorage - * @typedef {cpfExportsStorage} CpfExportsStorage */ const dependencies = { answerRepository, assessmentRepository, assessmentResultRepository, - attendanceSheetPdfUtils, candidateRepository, certificationAssessmentRepository, - certificationCandidateRepository, - certificationCenterRepository, certificationChallengeLiveAlertRepository, certificationCourseRepository, - certificationCpfService, certificationIssueReportRepository, - certificationOfficerRepository, certificationReportRepository, certificateRepository, challengeRepository, - certificationCpfCityRepository, - certificationCpfCountryRepository, competenceMarkRepository, competenceRepository, complementaryCertificationRepository, - finalizedSessionRepository, - issueReportCategoryRepository, - jurySessionRepository, + flashAlgorithmService, + flashAlgorithmConfigurationRepository, mailService, - sessionCodeService, - sessionsImportValidationService, - temporarySessionsStorageForMassImportService, - sessionForAttendanceSheetRepository, - sessionForInvigilatorKitRepository, - cpfCertificationResultRepository, - cpfExportRepository, - sessionRepository, - sessionValidator, userRepository, v3CertificationCourseDetailsForAdministrationRepository, - cpfReceiptsStorage, - cpfExportsStorage, }; const path = dirname(fileURLToPath(import.meta.url)); @@ -131,14 +73,6 @@ const path = dirname(fileURLToPath(import.meta.url)); * This file should inject usecases from the shared sub-domain only. */ const usecasesWithoutInjectedDependencies = { - ...(await importNamedExportsFromDirectory({ - path: join(path, '../../../session/domain/usecases/'), - ignoredFileNames: [ - 'index.js', - 'get-session-certification-candidates.js', - 'get-mass-import-template-information.js', - ], - })), ...(await importNamedExportsFromDirectory({ path: join(path, '../../../course/domain/usecases/'), ignoredFileNames: ['index.js', 'update-jury-comment.js', 'get-sco-certification-results-by-division.js'], diff --git a/api/src/certification/shared/infrastructure/repositories/certification-center-repository.js b/api/src/certification/shared/infrastructure/repositories/certification-center-repository.js index 9fae2d53dcf..6917c2226bf 100644 --- a/api/src/certification/shared/infrastructure/repositories/certification-center-repository.js +++ b/api/src/certification/shared/infrastructure/repositories/certification-center-repository.js @@ -42,7 +42,7 @@ function _setSearchFiltersForQueryBuilder(filters, qb) { *@deprecated implemented without bookshelf in {@link file://./../../../session/infrastructure/repositories/center-repository.js} * note that the new implementations does not provide the lazy loading on habilitations */ -const get = async function (id) { +const get = async function ({ id }) { const certificationCenterBookshelf = await BookshelfCertificationCenter.query((q) => q.orderBy('id', 'desc')) .where({ id }) .fetch({ @@ -62,7 +62,7 @@ const get = async function (id) { throw new NotFoundError(`Certification center with id: ${id} not found`); }; -const getBySessionId = async function (sessionId) { +const getBySessionId = async function ({ sessionId }) { const certificationCenterBookshelf = await BookshelfCertificationCenter.where({ 'sessions.id': sessionId }) .query((qb) => { qb.innerJoin('sessions', 'sessions.certificationCenterId', 'certification-centers.id'); @@ -84,7 +84,8 @@ const getBySessionId = async function (sessionId) { throw new NotFoundError(`Could not find certification center for sessionId ${sessionId}.`); }; -const save = async function (certificationCenter) { +// @deprecated +const save = async function ({ certificationCenter }) { const cleanedCertificationCenter = _.omit(certificationCenter, ['createdAt', 'habilitations']); const certificationCenterBookshelf = await new BookshelfCertificationCenter(cleanedCertificationCenter).save(); await certificationCenterBookshelf.related('habilitations').fetch(); @@ -125,7 +126,7 @@ const findByExternalId = async function ({ externalId }) { return certificationCenterBookshelf ? _toDomain(certificationCenterBookshelf) : null; }; -const getRefererEmails = async function (certificationCenterId) { +const getRefererEmails = async function ({ id }) { const refererEmails = await knex('certification-centers') .select('users.email') .join( @@ -134,7 +135,7 @@ const getRefererEmails = async function (certificationCenterId) { 'certification-centers.id', ) .join('users', 'users.id', 'certification-center-memberships.userId') - .where('certification-centers.id', certificationCenterId) + .where('certification-centers.id', id) .where('certification-center-memberships.isReferer', true); return refererEmails; diff --git a/api/src/certification/session/infrastructure/repositories/certification-challenge-live-alert-repository.js b/api/src/certification/shared/infrastructure/repositories/certification-challenge-live-alert-repository.js similarity index 94% rename from api/src/certification/session/infrastructure/repositories/certification-challenge-live-alert-repository.js rename to api/src/certification/shared/infrastructure/repositories/certification-challenge-live-alert-repository.js index 2cd728d6d72..f2bd542657b 100644 --- a/api/src/certification/session/infrastructure/repositories/certification-challenge-live-alert-repository.js +++ b/api/src/certification/shared/infrastructure/repositories/certification-challenge-live-alert-repository.js @@ -13,7 +13,7 @@ const save = async function ({ certificationChallengeLiveAlert }) { .merge(); }; -const getByAssessmentId = async (assessmentId) => { +const getByAssessmentId = async ({ assessmentId }) => { const certificationChallengeLiveAlertsDto = await knex('certification-challenge-live-alerts').where({ assessmentId, }); @@ -21,7 +21,7 @@ const getByAssessmentId = async (assessmentId) => { return certificationChallengeLiveAlertsDto.map(_toDomain); }; -const getLiveAlertValidatedChallengeIdsByAssessmentId = async (assessmentId) => { +const getLiveAlertValidatedChallengeIdsByAssessmentId = async ({ assessmentId }) => { const liveAlertValidatedChallengeIds = await knex('certification-challenge-live-alerts').select('challengeId').where({ assessmentId, status: CertificationChallengeLiveAlertStatus.VALIDATED, diff --git a/api/src/certification/shared/infrastructure/repositories/certification-course-repository.js b/api/src/certification/shared/infrastructure/repositories/certification-course-repository.js index 72a6bdea99c..f46422e8b14 100644 --- a/api/src/certification/shared/infrastructure/repositories/certification-course-repository.js +++ b/api/src/certification/shared/infrastructure/repositories/certification-course-repository.js @@ -47,7 +47,7 @@ async function save({ certificationCourse, domainTransaction = DomainTransaction }); }); - return get(certificationCourseId, domainTransaction); + return get({ id: certificationCourseId, domainTransaction }); } const _findCertificationCourse = async function (id, knexConn = knex) { @@ -62,7 +62,7 @@ const _findAllChallenges = async function (certificationCourseId, knexConn = kne return knexConn('certification-challenges').where({ courseId: certificationCourseId }); }; -async function get(id, domainTransaction = DomainTransaction.emptyTransaction()) { +async function get({ id, domainTransaction = DomainTransaction.emptyTransaction() }) { const knexConn = domainTransaction.knexTransaction || knex; const certificationCourseDTO = await _findCertificationCourse(id, knexConn); @@ -134,7 +134,7 @@ async function _getV3ConfigurationForCertificationCreationDate(createdAt, knexCo .first(); } -async function getSessionId(id) { +async function getSessionId({ id }) { const row = await knex('certification-courses').select('sessionId').where({ id }).first(); if (!row) { throw new NotFoundError(`Certification course of id ${id} does not exist`); @@ -182,7 +182,7 @@ async function findOneCertificationCourseByUserIdAndSessionId({ }); } -async function update(certificationCourse) { +async function update({ certificationCourse }) { const knexConn = knex; const certificationCourseData = _pickUpdatableProperties(certificationCourse); @@ -195,10 +195,10 @@ async function update(certificationCourse) { throw new NotFoundError(`No rows updated for certification course of id ${certificationCourse.getId()}.`); } - return get(certificationCourseData.id); + return get({ id: certificationCourseData.id }); } -async function isVerificationCodeAvailable(verificationCode) { +async function isVerificationCodeAvailable({ verificationCode }) { const exist = await knex('certification-courses') .select('id') .whereRaw('UPPER(??)=?', ['verificationCode', verificationCode.toUpperCase()]) diff --git a/api/src/certification/shared/infrastructure/repositories/certification-issue-report-repository.js b/api/src/certification/shared/infrastructure/repositories/certification-issue-report-repository.js index 0260d1d5915..219cb1114b8 100644 --- a/api/src/certification/shared/infrastructure/repositories/certification-issue-report-repository.js +++ b/api/src/certification/shared/infrastructure/repositories/certification-issue-report-repository.js @@ -6,7 +6,7 @@ import { knex } from '../../../../../db/knex-database-connection.js'; import { NotFoundError } from '../../../../shared/domain/errors.js'; import { CertificationIssueReport } from '../../domain/models/CertificationIssueReport.js'; -const save = async function (certificationIssueReport) { +const save = async function ({ certificationIssueReport }) { const [data] = await knex .from('certification-issue-reports') .insert(omit(certificationIssueReport, ['isImpactful'])) @@ -17,7 +17,7 @@ const save = async function (certificationIssueReport) { return new CertificationIssueReport(data); }; -const get = async function (id) { +const get = async function ({ id }) { const certificationIssueReport = await knex('certification-issue-reports').where({ id }).first(); if (!certificationIssueReport) { throw new NotFoundError(`Certification issue report ${id} does not exist`); @@ -25,14 +25,14 @@ const get = async function (id) { return new CertificationIssueReport(certificationIssueReport); }; -const findByCertificationCourseId = async function (certificationCourseId) { +const findByCertificationCourseId = async function ({ certificationCourseId }) { const certificationIssueReports = await knex('certification-issue-reports').where({ certificationCourseId }); return certificationIssueReports.map( (certificationIssueReport) => new CertificationIssueReport(certificationIssueReport), ); }; -const remove = async function (id) { +const remove = async function ({ id }) { return knex('certification-issue-reports').where({ id }).del(); }; diff --git a/api/src/certification/shared/infrastructure/repositories/certification-report-repository.js b/api/src/certification/shared/infrastructure/repositories/certification-report-repository.js index 762994cadd6..bc157cd739e 100644 --- a/api/src/certification/shared/infrastructure/repositories/certification-report-repository.js +++ b/api/src/certification/shared/infrastructure/repositories/certification-report-repository.js @@ -13,7 +13,7 @@ import * as bookshelfToDomainConverter from '../../../../../lib/infrastructure/u import { CertificationCourseUpdateError } from '../../domain/errors.js'; import { CertificationReport } from '../../domain/models/CertificationReport.js'; -const findBySessionId = async function (sessionId) { +const findBySessionId = async function ({ sessionId }) { const results = await BookshelfCertificationCourse.where({ sessionId }) .query((qb) => { qb.orderByRaw('LOWER("lastName") asc'); @@ -27,7 +27,7 @@ const findBySessionId = async function (sessionId) { return _.map(certificationCourses, CertificationReport.fromCertificationCourse); }; -const finalizeAll = async function (certificationReports) { +const finalizeAll = async function ({ certificationReports }) { try { await Bookshelf.transaction((trx) => { const finalizeReport = (certificationReport) => _finalize({ certificationReport, transaction: trx }); diff --git a/api/src/shared/application/security-pre-handlers.js b/api/src/shared/application/security-pre-handlers.js index 3193dac887c..7861f052f4f 100644 --- a/api/src/shared/application/security-pre-handlers.js +++ b/api/src/shared/application/security-pre-handlers.js @@ -293,8 +293,9 @@ async function checkUserIsMemberOfCertificationCenterSessionFromCertificationIss const certificationIssueReportId = request.params.id; try { - const certificationIssueReport = - await dependencies.certificationIssueReportRepository.get(certificationIssueReportId); + const certificationIssueReport = await dependencies.certificationIssueReportRepository.get({ + id: certificationIssueReportId, + }); const isMemberOfSession = await dependencies.checkUserIsMemberOfCertificationCenterSessionUsecase.execute({ userId, certificationCourseId: certificationIssueReport.certificationCourseId, diff --git a/api/src/shared/domain/models/Assessment.js b/api/src/shared/domain/models/Assessment.js index 0c0224e8d70..45d98bf7316 100644 --- a/api/src/shared/domain/models/Assessment.js +++ b/api/src/shared/domain/models/Assessment.js @@ -1,5 +1,5 @@ import { ObjectValidationError } from '../../../../lib/domain/errors.js'; -import { CertificationChallengeLiveAlertStatus } from '../../../certification/session/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../certification/shared/domain/models/CertificationChallengeLiveAlert.js'; import { Answer } from '../../../evaluation/domain/models/Answer.js'; const courseIdMessage = { diff --git a/api/tests/acceptance/application/certification-courses/certification-course-controller_test.js b/api/tests/acceptance/application/certification-courses/certification-course-controller_test.js index 6bffba47cb5..517af285f51 100644 --- a/api/tests/acceptance/application/certification-courses/certification-course-controller_test.js +++ b/api/tests/acceptance/application/certification-courses/certification-course-controller_test.js @@ -3,8 +3,8 @@ import { CertificationAssessment } from '../../../../lib/domain/models/Certifica import { ComplementaryCertificationCourseResult } from '../../../../lib/domain/models/ComplementaryCertificationCourseResult.js'; import { KnowledgeElement } from '../../../../lib/domain/models/KnowledgeElement.js'; import { CertificationIssueReportCategory } from '../../../../src/certification/shared/domain/models/CertificationIssueReportCategory.js'; +import { CertificationVersion } from '../../../../src/certification/shared/domain/models/CertificationVersion.js'; import { AutoJuryCommentKeys } from '../../../../src/certification/shared/domain/models/JuryComment.js'; -import { CertificationVersion } from '../../../../src/shared/domain/models/CertificationVersion.js'; import { createServer, databaseBuilder, diff --git a/api/tests/certification/complementary-certification/unit/domain/usecases/delete-session_test.js b/api/tests/certification/complementary-certification/unit/domain/usecases/delete-session_test.js index 27fc892e90f..4cfa44b3c01 100644 --- a/api/tests/certification/complementary-certification/unit/domain/usecases/delete-session_test.js +++ b/api/tests/certification/complementary-certification/unit/domain/usecases/delete-session_test.js @@ -18,7 +18,7 @@ describe('Unit | UseCase | delete-session', function () { }); // then - expect(sessionRepository.remove).to.have.been.calledWithExactly(123); + expect(sessionRepository.remove).to.have.been.calledWithExactly({ id: 123 }); }); }); diff --git a/api/tests/certification/course/integration/infrastructure/repositories/v3-certification-course-details-for-administration-repository_test.js b/api/tests/certification/course/integration/infrastructure/repositories/v3-certification-course-details-for-administration-repository_test.js index 066bc8494cd..c4899093e02 100644 --- a/api/tests/certification/course/integration/infrastructure/repositories/v3-certification-course-details-for-administration-repository_test.js +++ b/api/tests/certification/course/integration/infrastructure/repositories/v3-certification-course-details-for-administration-repository_test.js @@ -1,5 +1,5 @@ -import { ABORT_REASONS } from '../../../../../../lib/domain/models/CertificationCourse.js'; import * as v3CertificationCourseDetailsForAdministrationRepository from '../../../../../../src/certification/course/infrastructure/repositories/v3-certification-course-details-for-administration-repository.js'; +import { ABORT_REASONS } from '../../../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { CertificationIssueReportCategory, CertificationIssueReportSubcategories, diff --git a/api/tests/certification/course/unit/domain/usecases/get-next-challenge-for-certification_test.js b/api/tests/certification/course/unit/domain/usecases/get-next-challenge-for-certification_test.js index f76dec831cb..3f7b5d4a7f8 100644 --- a/api/tests/certification/course/unit/domain/usecases/get-next-challenge-for-certification_test.js +++ b/api/tests/certification/course/unit/domain/usecases/get-next-challenge-for-certification_test.js @@ -1,8 +1,8 @@ import { AssessmentEndedError } from '../../../../../../lib/domain/errors.js'; import { getNextChallengeForCertification } from '../../../../../../src/certification/course/domain/usecases/get-next-challenge-for-certification.js'; +import { CertificationVersion } from '../../../../../../src/certification/shared/domain/models/CertificationVersion.js'; import { config } from '../../../../../../src/shared/config.js'; import { Assessment } from '../../../../../../src/shared/domain/models/Assessment.js'; -import { CertificationVersion } from '../../../../../../src/shared/domain/models/CertificationVersion.js'; import { catchErr, domainBuilder, expect, sinon } from '../../../../../test-helper.js'; describe('Unit | Domain | Use Cases | get-next-challenge-for-certification', function () { @@ -25,7 +25,9 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-certification', fun const certificationCourse = domainBuilder.buildCertificationCourse(); certificationChallengeRepository.getNextNonAnsweredChallengeByCourseId.resolves(nextChallenge); - certificationCourseRepository.get.withArgs(assessment.certificationCourseId).resolves(certificationCourse); + certificationCourseRepository.get + .withArgs({ id: assessment.certificationCourseId }) + .resolves(certificationCourse); // when await getNextChallengeForCertification({ @@ -52,7 +54,9 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-certification', fun certificationChallengeRepository.getNextNonAnsweredChallengeByCourseId.resolves(nextCertificationChallenge); challengeRepository.get.resolves(nextChallengeToAnswer); - certificationCourseRepository.get.withArgs(assessment.certificationCourseId).resolves(certificationCourse); + certificationCourseRepository.get + .withArgs({ id: assessment.certificationCourseId }) + .resolves(certificationCourse); // when const challenge = await getNextChallengeForCertification({ @@ -129,10 +133,12 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-certification', fun answerRepository.findByAssessment.withArgs(assessment.id).resolves([]); certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId - .withArgs(assessment.id) + .withArgs({ assessmentId: assessment.id }) .resolves([]); - certificationCourseRepository.get.withArgs(assessment.certificationCourseId).resolves(v3CertificationCourse); + certificationCourseRepository.get + .withArgs({ id: assessment.certificationCourseId }) + .resolves(v3CertificationCourse); certificationChallengeRepository.getNextChallengeByCourseIdForV3 .withArgs(assessment.certificationCourseId, []) .resolves(null); @@ -207,11 +213,11 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-certification', fun answerRepository.findByAssessment.withArgs(assessment.id).resolves([]); certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId - .withArgs(assessment.id) + .withArgs({ assessmentId: assessment.id }) .resolves([]); certificationCourseRepository.get - .withArgs(assessment.certificationCourseId) + .withArgs({ id: assessment.certificationCourseId }) .resolves(v3CertificationCourse); certificationChallengeRepository.getNextChallengeByCourseIdForV3 .withArgs(assessment.certificationCourseId, []) @@ -293,10 +299,12 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-certification', fun answerRepository.findByAssessment.withArgs(assessment.id).resolves([]); certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId - .withArgs(assessment.id) + .withArgs({ assessmentId: assessment.id }) .resolves([nonAnsweredCertificationChallenge.challengeId]); - certificationCourseRepository.get.withArgs(assessment.certificationCourseId).resolves(v3CertificationCourse); + certificationCourseRepository.get + .withArgs({ id: assessment.certificationCourseId }) + .resolves(v3CertificationCourse); certificationChallengeRepository.getNextChallengeByCourseIdForV3 .withArgs(assessment.certificationCourseId, []) .resolves(nonAnsweredCertificationChallenge); @@ -389,10 +397,12 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-certification', fun answerRepository.findByAssessment.withArgs(assessment.id).resolves([]); certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId - .withArgs(assessment.id) + .withArgs({ assessmentId: assessment.id }) .resolves([nonAnsweredCertificationChallenge.challengeId]); - certificationCourseRepository.get.withArgs(assessment.certificationCourseId).resolves(v3CertificationCourse); + certificationCourseRepository.get + .withArgs({ id: assessment.certificationCourseId }) + .resolves(v3CertificationCourse); certificationChallengeRepository.getNextChallengeByCourseIdForV3 .withArgs(assessment.certificationCourseId, []) .resolves(nonAnsweredCertificationChallenge); @@ -448,10 +458,12 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-certification', fun answerRepository.findByAssessment.withArgs(assessment.id).resolves([answer]); certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId - .withArgs(assessment.id) + .withArgs({ assessmentId: assessment.id }) .resolves([]); - certificationCourseRepository.get.withArgs(assessment.certificationCourseId).resolves(v3CertificationCourse); + certificationCourseRepository.get + .withArgs({ id: assessment.certificationCourseId }) + .resolves(v3CertificationCourse); certificationChallengeRepository.getNextChallengeByCourseIdForV3 .withArgs(assessment.certificationCourseId, [answeredChallenge.id]) .resolves(null); @@ -546,11 +558,11 @@ describe('Unit | Domain | Use Cases | get-next-challenge-for-certification', fun answerRepository.findByAssessment.withArgs(assessment.id).resolves([]); certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId - .withArgs(assessment.id) + .withArgs({ assessmentId: assessment.id }) .resolves([]); certificationCourseRepository.get - .withArgs(assessment.certificationCourseId) + .withArgs({ id: assessment.certificationCourseId }) .resolves(v3CertificationCourse); certificationChallengeRepository.getNextChallengeByCourseIdForV3 .withArgs(assessment.certificationCourseId, []) diff --git a/api/tests/certification/course/unit/domain/usecases/get-session-certification-reports_test.js b/api/tests/certification/course/unit/domain/usecases/get-session-certification-reports_test.js index 65978b7d28f..76b2df5acd4 100644 --- a/api/tests/certification/course/unit/domain/usecases/get-session-certification-reports_test.js +++ b/api/tests/certification/course/unit/domain/usecases/get-session-certification-reports_test.js @@ -7,7 +7,7 @@ describe('Unit | Domain | Use Cases | get-session-certification-reports', funct const sessionId = 'sessionId'; const certificationReports = Symbol('some certification candidates'); const certificationReportRepository = { findBySessionId: sinon.stub() }; - certificationReportRepository.findBySessionId.withArgs(sessionId).resolves(certificationReports); + certificationReportRepository.findBySessionId.withArgs({ sessionId }).resolves(certificationReports); // when const actualCandidates = await getSessionCertificationReports({ sessionId, certificationReportRepository }); diff --git a/api/tests/certification/course/unit/domain/usecases/reject-certification-course_test.js b/api/tests/certification/course/unit/domain/usecases/reject-certification-course_test.js index ef239f86d73..b753bef2a83 100644 --- a/api/tests/certification/course/unit/domain/usecases/reject-certification-course_test.js +++ b/api/tests/certification/course/unit/domain/usecases/reject-certification-course_test.js @@ -1,6 +1,6 @@ import { CertificationCourseRejected } from '../../../../../../lib/domain/events/CertificationCourseRejected.js'; -import { CertificationCourse } from '../../../../../../lib/domain/models/index.js'; import { rejectCertificationCourse } from '../../../../../../src/certification/course/domain/usecases/reject-certification-course.js'; +import { CertificationCourse } from '../../../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { domainBuilder, expect, sinon } from '../../../../../test-helper.js'; describe('Unit | UseCase | reject-certification-course', function () { @@ -15,7 +15,7 @@ describe('Unit | UseCase | reject-certification-course', function () { const certificationCourse = domainBuilder.buildCertificationCourse(); const certificationCourseId = certificationCourse.getId(); - certificationCourseRepository.get.withArgs(certificationCourse.getId()).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: certificationCourseId }).resolves(certificationCourse); certificationCourseRepository.update.resolves(); // when @@ -31,7 +31,9 @@ describe('Unit | UseCase | reject-certification-course', function () { isRejectedForFraud: true, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(expectedCertificationCourse); + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: expectedCertificationCourse, + }); expect(event).to.be.instanceOf(CertificationCourseRejected); expect(event).to.deep.equal( new CertificationCourseRejected({ diff --git a/api/tests/certification/course/unit/domain/usecases/unreject-certification-course_test.js b/api/tests/certification/course/unit/domain/usecases/unreject-certification-course_test.js index f141c7d29b1..46a4cfd4a5b 100644 --- a/api/tests/certification/course/unit/domain/usecases/unreject-certification-course_test.js +++ b/api/tests/certification/course/unit/domain/usecases/unreject-certification-course_test.js @@ -1,6 +1,6 @@ import { CertificationCourseUnrejected } from '../../../../../../lib/domain/events/CertificationCourseUnrejected.js'; -import { CertificationCourse } from '../../../../../../lib/domain/models/index.js'; import { unrejectCertificationCourse } from '../../../../../../src/certification/course/domain/usecases/unreject-certification-course.js'; +import { CertificationCourse } from '../../../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { domainBuilder, expect, sinon } from '../../../../../test-helper.js'; describe('Unit | UseCase | unreject-certification-course', function () { @@ -17,7 +17,7 @@ describe('Unit | UseCase | unreject-certification-course', function () { }); const certificationCourseId = certificationCourse.getId(); - certificationCourseRepository.get.withArgs(certificationCourse.getId()).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: certificationCourseId }).resolves(certificationCourse); certificationCourseRepository.update.resolves(); // when @@ -33,7 +33,9 @@ describe('Unit | UseCase | unreject-certification-course', function () { isRejectedForFraud: false, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(expectedCertificationCourse); + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: expectedCertificationCourse, + }); expect(event).to.be.instanceOf(CertificationCourseUnrejected); expect(event).to.deep.equal( new CertificationCourseUnrejected({ diff --git a/api/tests/certification/course/unit/infrasctructure/serializers/jsonapi/v3-certification-course-details-for-administration-serializer_test.js b/api/tests/certification/course/unit/infrasctructure/serializers/jsonapi/v3-certification-course-details-for-administration-serializer_test.js index 8fe462d5d2f..5465fd78ce2 100644 --- a/api/tests/certification/course/unit/infrasctructure/serializers/jsonapi/v3-certification-course-details-for-administration-serializer_test.js +++ b/api/tests/certification/course/unit/infrasctructure/serializers/jsonapi/v3-certification-course-details-for-administration-serializer_test.js @@ -1,8 +1,8 @@ -import { ABORT_REASONS } from '../../../../../../../lib/domain/models/CertificationCourse.js'; import { V3CertificationChallengeForAdministration } from '../../../../../../../src/certification/course/domain/models/V3CertificationChallengeForAdministration.js'; import { V3CertificationChallengeLiveAlertForAdministration } from '../../../../../../../src/certification/course/domain/models/V3CertificationChallengeLiveAlertForAdministration.js'; import { V3CertificationCourseDetailsForAdministration } from '../../../../../../../src/certification/course/domain/models/V3CertificationCourseDetailsForAdministration.js'; import * as serializer from '../../../../../../../src/certification/course/infrastructure/serializers/jsonapi/v3-certification-course-details-for-administration-serializer.js'; +import { ABORT_REASONS } from '../../../../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { AnswerStatus } from '../../../../../../../src/shared/domain/models/AnswerStatus.js'; import { Assessment } from '../../../../../../../src/shared/domain/models/Assessment.js'; import { AssessmentResult } from '../../../../../../../src/shared/domain/models/AssessmentResult.js'; diff --git a/api/tests/certification/scoring/unit/domain/models/CertificationAssessmentScoreV3_test.js b/api/tests/certification/scoring/unit/domain/models/CertificationAssessmentScoreV3_test.js index fcf237f4cb1..5ab957514e7 100644 --- a/api/tests/certification/scoring/unit/domain/models/CertificationAssessmentScoreV3_test.js +++ b/api/tests/certification/scoring/unit/domain/models/CertificationAssessmentScoreV3_test.js @@ -1,8 +1,8 @@ import _ from 'lodash'; -import { ABORT_REASONS } from '../../../../../../lib/domain/models/CertificationCourse.js'; import { AnswerStatus } from '../../../../../../lib/domain/models/index.js'; import { CertificationAssessmentScoreV3 } from '../../../../../../src/certification/scoring/domain/models/CertificationAssessmentScoreV3.js'; +import { ABORT_REASONS } from '../../../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { config } from '../../../../../../src/shared/config.js'; import { status } from '../../../../../../src/shared/domain/models/AssessmentResult.js'; import { domainBuilder, expect, sinon } from '../../../../../test-helper.js'; diff --git a/api/tests/certification/session/acceptance/application/session-live-alert-controller_test.js b/api/tests/certification/session/acceptance/application/session-live-alert-controller_test.js index 9dcb661b521..5f32278afef 100644 --- a/api/tests/certification/session/acceptance/application/session-live-alert-controller_test.js +++ b/api/tests/certification/session/acceptance/application/session-live-alert-controller_test.js @@ -1,4 +1,4 @@ -import { CertificationChallengeLiveAlertStatus } from '../../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; import { createServer, databaseBuilder, diff --git a/api/tests/certification/session/integration/infrastructure/repositories/candidate-repository_test.js b/api/tests/certification/session/integration/infrastructure/repositories/candidate-repository_test.js index 02afa8e7e1a..e581fc92397 100644 --- a/api/tests/certification/session/integration/infrastructure/repositories/candidate-repository_test.js +++ b/api/tests/certification/session/integration/infrastructure/repositories/candidate-repository_test.js @@ -29,7 +29,7 @@ describe('Integration | Certification | Session | Repository | Candidate', funct context('when there are some certification candidates with the given session id', function () { it('should fetch, alphabetically sorted, the certification candidates with a specific session ID', async function () { // when - const actualCandidates = await candidateRepository.findBySessionId(sessionId); + const actualCandidates = await candidateRepository.findBySessionId({ sessionId }); // then expect(actualCandidates[0].firstName).to.equal('James'); @@ -76,7 +76,7 @@ describe('Integration | Certification | Session | Repository | Candidate', funct await databaseBuilder.commit(); // when - const candidates = await candidateRepository.findBySessionId(sessionId); + const candidates = await candidateRepository.findBySessionId({ sessionId }); // then const firstCandidate = candidates[0]; @@ -100,7 +100,7 @@ describe('Integration | Certification | Session | Repository | Candidate', funct context('when there is no certification candidates with the given session ID', function () { it('should return an empty array', async function () { // when - const actualCandidates = await candidateRepository.findBySessionId(-1); + const actualCandidates = await candidateRepository.findBySessionId({ sessionId: -1 }); // then expect(actualCandidates).to.deep.equal([]); diff --git a/api/tests/certification/session/integration/infrastructure/repositories/certification-candidate-repository_test.js b/api/tests/certification/session/integration/infrastructure/repositories/certification-candidate-repository_test.js index c6c4925aa03..dfc1dd8a4fd 100644 --- a/api/tests/certification/session/integration/infrastructure/repositories/certification-candidate-repository_test.js +++ b/api/tests/certification/session/integration/infrastructure/repositories/certification-candidate-repository_test.js @@ -6,8 +6,8 @@ import { } from '../../../../../../lib/domain/errors.js'; import { BookshelfCertificationCandidate } from '../../../../../../lib/infrastructure/orm-models/CertificationCandidate.js'; import { ComplementaryCertification } from '../../../../../../src/certification/session/domain/models/ComplementaryCertification.js'; +import * as certificationCandidateRepository from '../../../../../../src/certification/session/infrastructure/repositories/certification-candidate-repository.js'; import { ComplementaryCertificationKeys } from '../../../../../../src/certification/shared/domain/models/ComplementaryCertificationKeys.js'; -import * as certificationCandidateRepository from '../../../../../../src/certification/shared/infrastructure/repositories/certification-candidate-repository.js'; import { catchErr, databaseBuilder, domainBuilder, expect, knex } from '../../../../../test-helper.js'; describe('Integration | Repository | CertificationCandidate', function () { @@ -174,7 +174,7 @@ describe('Integration | Repository | CertificationCandidate', function () { it('should return true when deletion goes well', async function () { // when - const isDeleted = await certificationCandidateRepository.remove(certificationCandidateToDeleteId); + const isDeleted = await certificationCandidateRepository.remove({ id: certificationCandidateToDeleteId }); // then expect(isDeleted).to.be.true; @@ -183,7 +183,7 @@ describe('Integration | Repository | CertificationCandidate', function () { it('should delete a single row in the table', async function () { const nbCertifCandidatesBeforeDeletion = await BookshelfCertificationCandidate.count(); // when - await certificationCandidateRepository.remove(certificationCandidateToDeleteId); + await certificationCandidateRepository.remove({ id: certificationCandidateToDeleteId }); const nbCertifCandidatesAfterDeletion = await BookshelfCertificationCandidate.count(); // then @@ -203,7 +203,7 @@ describe('Integration | Repository | CertificationCandidate', function () { await databaseBuilder.commit(); // when - const isDeleted = await certificationCandidateRepository.remove(certificationCandidateId); + const isDeleted = await certificationCandidateRepository.remove({ id: certificationCandidateId }); // then const complementaryCertificationSubscriptions = await knex @@ -228,7 +228,7 @@ describe('Integration | Repository | CertificationCandidate', function () { it('should return false', async function () { // when - const isNotLinked = await certificationCandidateRepository.isNotLinked(certificationCandidateId); + const isNotLinked = await certificationCandidateRepository.isNotLinked({ id: certificationCandidateId }); // then expect(isNotLinked).to.be.false; @@ -246,7 +246,9 @@ describe('Integration | Repository | CertificationCandidate', function () { it('should return true', async function () { // when - const isNotLinked = await certificationCandidateRepository.isNotLinked(certificationCandidateToDeleteId); + const isNotLinked = await certificationCandidateRepository.isNotLinked({ + id: certificationCandidateToDeleteId, + }); // then expect(isNotLinked).to.be.true; diff --git a/api/tests/certification/session/integration/infrastructure/repositories/certification-officer-repository_test.js b/api/tests/certification/session/integration/infrastructure/repositories/certification-officer-repository_test.js index acf7f69ea86..77dac58f376 100644 --- a/api/tests/certification/session/integration/infrastructure/repositories/certification-officer-repository_test.js +++ b/api/tests/certification/session/integration/infrastructure/repositories/certification-officer-repository_test.js @@ -14,7 +14,7 @@ describe('Integration | Repository | CertificationOfficer', function () { it('should return the found certificationOfficer', async function () { // when - const certificationOfficer = await certificationOfficerRepository.get(userInDb.id); + const certificationOfficer = await certificationOfficerRepository.get({ userId: userInDb.id }); // then expect(certificationOfficer).to.be.an.instanceOf(CertificationOfficer); @@ -28,7 +28,7 @@ describe('Integration | Repository | CertificationOfficer', function () { const nonExistentUserId = 678; // when - const result = await catchErr(certificationOfficerRepository.get)(nonExistentUserId); + const result = await catchErr(certificationOfficerRepository.get)({ userId: nonExistentUserId }); // then expect(result).to.be.instanceOf(UserNotFoundError); diff --git a/api/tests/certification/session/integration/infrastructure/repositories/finalized-session-repository_test.js b/api/tests/certification/session/integration/infrastructure/repositories/finalized-session-repository_test.js index dcf24f7647f..a3d8f3ac960 100644 --- a/api/tests/certification/session/integration/infrastructure/repositories/finalized-session-repository_test.js +++ b/api/tests/certification/session/integration/infrastructure/repositories/finalized-session-repository_test.js @@ -19,7 +19,7 @@ describe('Integration | Repository | Finalized-session', function () { }); // when - await finalizedSessionRepository.save(finalizedSession); + await finalizedSessionRepository.save({ finalizedSession }); // then const savedSession = await finalizedSessionRepository.get({ sessionId: 1234 }); @@ -51,8 +51,8 @@ describe('Integration | Repository | Finalized-session', function () { // when expect(async () => { - await finalizedSessionRepository.save(finalizedSession); - await finalizedSessionRepository.save(finalizedSession); + await finalizedSessionRepository.save({ finalizedSession }); + await finalizedSessionRepository.save({ finalizedSession }); done(); }).not.to.throw(); }); @@ -73,7 +73,7 @@ describe('Integration | Repository | Finalized-session', function () { sessionToBeUpdated.assignCertificationOfficer({ certificationOfficerName: 'David Gilmour' }); // when - await finalizedSessionRepository.save(sessionToBeUpdated); + await finalizedSessionRepository.save({ finalizedSession: sessionToBeUpdated }); // then const result = await finalizedSessionRepository.get({ sessionId: 1235 }); diff --git a/api/tests/certification/session/integration/infrastructure/repositories/jury-session-repository_test.js b/api/tests/certification/session/integration/infrastructure/repositories/jury-session-repository_test.js index a97f75961b0..aae57f15080 100644 --- a/api/tests/certification/session/integration/infrastructure/repositories/jury-session-repository_test.js +++ b/api/tests/certification/session/integration/infrastructure/repositories/jury-session-repository_test.js @@ -4,7 +4,7 @@ import { NotFoundError } from '../../../../../../lib/domain/errors.js'; import { JurySession, statuses } from '../../../../../../lib/domain/models/JurySession.js'; import { CertificationOfficer } from '../../../../../../src/certification/session/domain/models/CertificationOfficer.js'; import * as jurySessionRepository from '../../../../../../src/certification/session/infrastructure/repositories/jury-session-repository.js'; -import { catchErr, databaseBuilder, domainBuilder, expect } from '../../../../../test-helper.js'; +import { catchErr, databaseBuilder, domainBuilder, expect, knex } from '../../../../../test-helper.js'; describe('Integration | Repository | JurySession', function () { describe('#get', function () { @@ -75,7 +75,7 @@ describe('Integration | Repository | JurySession', function () { }); // when - const jurySession = await jurySessionRepository.get(sessionId); + const jurySession = await jurySessionRepository.get({ id: sessionId }); // then expect(jurySession).to.deepEqualInstance(expectedJurySession); @@ -85,7 +85,7 @@ describe('Integration | Repository | JurySession', function () { context('when id of session does not exist', function () { it('should throw a NotFoundError', async function () { // when - const error = await catchErr(jurySessionRepository.get)(12345); + const error = await catchErr(jurySessionRepository.get)({ id: 12345 }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -585,23 +585,28 @@ describe('Integration | Repository | JurySession', function () { }); describe('#assignCertificationOfficer', function () { - it('should return an updated Session domain object', async function () { - // given - const sessionId = databaseBuilder.factory.buildSession({ assignedCertificationOfficerId: null }).id; - const assignedCertificationOfficerId = databaseBuilder.factory.buildUser().id; - await databaseBuilder.commit(); - - // when - const updatedSession = await jurySessionRepository.assignCertificationOfficer({ - id: sessionId, - assignedCertificationOfficerId, - }); + context('when assignedCertificationOfficerId provided does exist', function () { + context('when sessionId does not exist', function () { + it("should update the session's assignCertificationOfficer", async function () { + // given + const sessionId = databaseBuilder.factory.buildSession({ assignedCertificationOfficerId: null }).id; + const assignedCertificationOfficerId = databaseBuilder.factory.buildUser().id; + await databaseBuilder.commit(); + + // when + await jurySessionRepository.assignCertificationOfficer({ + id: sessionId, + assignedCertificationOfficerId, + }); - // then - expect(updatedSession).to.be.an.instanceof(JurySession); - expect(updatedSession.id).to.deep.equal(sessionId); - expect(updatedSession.assignedCertificationOfficer.id).to.deep.equal(assignedCertificationOfficerId); - expect(updatedSession.status).to.deep.equal(statuses.IN_PROCESS); + // then + const [sessionAssignedCertificationOfficerId] = await knex('sessions') + .pluck('assignedCertificationOfficerId') + .where({ id: sessionId }); + + expect(sessionAssignedCertificationOfficerId).to.deep.equals(assignedCertificationOfficerId); + }); + }); }); context('when assignedCertificationOfficerId provided does not exist', function () { @@ -620,6 +625,7 @@ describe('Integration | Repository | JurySession', function () { // then expect(error).to.be.instanceOf(NotFoundError); + expect(error.message).to.equal(`L'utilisateur d'id ${unknownUserId} n'existe pas`); }); }); @@ -639,6 +645,7 @@ describe('Integration | Repository | JurySession', function () { // then expect(error).to.be.instanceOf(NotFoundError); + expect(error.message).to.equal(`La session d'id ${unknownSessionId} n'existe pas.`); }); }); }); diff --git a/api/tests/certification/session/integration/infrastructure/repositories/session-for-attendance-sheet-repository_test.js b/api/tests/certification/session/integration/infrastructure/repositories/session-for-attendance-sheet-repository_test.js index c85bdaa6339..dc9cccb0149 100644 --- a/api/tests/certification/session/integration/infrastructure/repositories/session-for-attendance-sheet-repository_test.js +++ b/api/tests/certification/session/integration/infrastructure/repositories/session-for-attendance-sheet-repository_test.js @@ -64,7 +64,9 @@ describe('Integration | Repository | Session-for-attendance-sheet', function () }); // when - const actualSession = await sessionForAttendanceSheetRepository.getWithCertificationCandidates(session.id); + const actualSession = await sessionForAttendanceSheetRepository.getWithCertificationCandidates({ + id: session.id, + }); // then expect(actualSession).to.deepEqualInstance(expectedSessionValues); @@ -133,7 +135,9 @@ describe('Integration | Repository | Session-for-attendance-sheet', function () }); // when - const actualSession = await sessionForAttendanceSheetRepository.getWithCertificationCandidates(session.id); + const actualSession = await sessionForAttendanceSheetRepository.getWithCertificationCandidates({ + id: session.id, + }); // then expect(actualSession).to.deepEqualInstance(expectedSessionValues); @@ -143,7 +147,9 @@ describe('Integration | Repository | Session-for-attendance-sheet', function () context('when no session was found', function () { it('should return a Not found error', async function () { // when - const error = await catchErr(sessionForAttendanceSheetRepository.getWithCertificationCandidates)(12434354); + const error = await catchErr(sessionForAttendanceSheetRepository.getWithCertificationCandidates)({ + id: 12434354, + }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -158,7 +164,9 @@ describe('Integration | Repository | Session-for-attendance-sheet', function () await databaseBuilder.commit(); // when - const error = await catchErr(sessionForAttendanceSheetRepository.getWithCertificationCandidates)(sessionId); + const error = await catchErr(sessionForAttendanceSheetRepository.getWithCertificationCandidates)({ + id: sessionId, + }); // then< expect(error).to.be.instanceOf(NotFoundError); diff --git a/api/tests/certification/session/integration/infrastructure/repositories/session-for-invigilator-kit-repository_test.js b/api/tests/certification/session/integration/infrastructure/repositories/session-for-invigilator-kit-repository_test.js index f7cd4fb545e..bf0e866ed80 100644 --- a/api/tests/certification/session/integration/infrastructure/repositories/session-for-invigilator-kit-repository_test.js +++ b/api/tests/certification/session/integration/infrastructure/repositories/session-for-invigilator-kit-repository_test.js @@ -43,7 +43,7 @@ describe('Integration | Repository | Session-for-invigilator-kit', function () { }); // when - const actualSession = await sessionForInvigilatorKitRepository.get(session.id); + const actualSession = await sessionForInvigilatorKitRepository.get({ id: session.id }); // then expect(actualSession).to.deepEqualInstance(expectedSessionValues); diff --git a/api/tests/certification/session/integration/infrastructure/repositories/session-repository_test.js b/api/tests/certification/session/integration/infrastructure/repositories/session-repository_test.js index 679b620b457..acd5f5a67f2 100644 --- a/api/tests/certification/session/integration/infrastructure/repositories/session-repository_test.js +++ b/api/tests/certification/session/integration/infrastructure/repositories/session-repository_test.js @@ -42,7 +42,7 @@ describe('Integration | Repository | Session', function () { it('should persist the session in db', async function () { // when - await sessionRepository.save(session); + await sessionRepository.save({ session }); // then const sessionSaved = await knex('sessions').select(); @@ -51,7 +51,7 @@ describe('Integration | Repository | Session', function () { it('should return the saved Session', async function () { // when - const savedSession = await sessionRepository.save(session); + const savedSession = await sessionRepository.save({ session }); // then expect(savedSession).to.be.an.instanceOf(Session); @@ -73,7 +73,7 @@ describe('Integration | Repository | Session', function () { it('should return true if the session status is finalized', async function () { // when - const isFinalized = await sessionRepository.isFinalized(finalizedSessionId); + const isFinalized = await sessionRepository.isFinalized({ id: finalizedSessionId }); // then expect(isFinalized).to.be.equal(true); @@ -81,7 +81,7 @@ describe('Integration | Repository | Session', function () { it('should return false if the session status is not finalized', async function () { // when - const isFinalized = await sessionRepository.isFinalized(notFinalizedSessionId); + const isFinalized = await sessionRepository.isFinalized({ id: notFinalizedSessionId }); // then expect(isFinalized).to.be.equal(false); @@ -96,7 +96,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const isPublished = await sessionRepository.isPublished(40); + const isPublished = await sessionRepository.isPublished({ id: 40 }); // then expect(isPublished).to.be.equal(true); @@ -110,7 +110,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const isPublished = await sessionRepository.isPublished(40); + const isPublished = await sessionRepository.isPublished({ id: 40 }); // then expect(isPublished).to.be.equal(false); @@ -154,7 +154,7 @@ describe('Integration | Repository | Session', function () { it('should return session informations in a session Object', async function () { // when - const actualSession = await sessionRepository.get(session.id); + const actualSession = await sessionRepository.get({ id: session.id }); // then expect(actualSession).to.be.instanceOf(Session); @@ -163,7 +163,7 @@ describe('Integration | Repository | Session', function () { it('should return a Not found error when no session was found', async function () { // when - const error = await catchErr(sessionRepository.get)(2); + const error = await catchErr(sessionRepository.get)({ id: 2 }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -190,7 +190,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const actualSession = await sessionRepository.getWithCertificationCandidates(session.id); + const actualSession = await sessionRepository.getWithCertificationCandidates({ id: session.id }); // then const expectedSession = domainBuilder.buildSession(session); @@ -219,7 +219,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const actualSession = await sessionRepository.getWithCertificationCandidates(session.id); + const actualSession = await sessionRepository.getWithCertificationCandidates({ id: session.id }); // then const actualCandidates = _.map(actualSession.certificationCandidates, (item) => @@ -238,7 +238,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const actualSession = await sessionRepository.getWithCertificationCandidates(session.id); + const actualSession = await sessionRepository.getWithCertificationCandidates({ id: session.id }); // then expect(actualSession.certificationCandidates).to.deep.equal([]); @@ -280,7 +280,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const actualSession = await sessionRepository.getWithCertificationCandidates(session.id); + const actualSession = await sessionRepository.getWithCertificationCandidates({ id: session.id }); // then const [firstCandidateFromSession, secondCandidateFromSession] = actualSession.certificationCandidates; @@ -308,7 +308,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const actualSession = await sessionRepository.getWithCertificationCandidates(session.id); + const actualSession = await sessionRepository.getWithCertificationCandidates({ id: session.id }); // then const [firstCandidateFromSession, secondCandidateFromSession] = actualSession.certificationCandidates; @@ -322,7 +322,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const error = await catchErr(sessionRepository.get)(session.id + 1); + const error = await catchErr(sessionRepository.get)({ id: session.id + 1 }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -348,7 +348,7 @@ describe('Integration | Repository | Session', function () { it('should return a Session domain object', async function () { // when - const sessionSaved = await sessionRepository.updateSessionInfo(session); + const sessionSaved = await sessionRepository.updateSessionInfo({ session }); // then expect(sessionSaved).to.be.an.instanceof(Session); @@ -358,7 +358,7 @@ describe('Integration | Repository | Session', function () { // given // when - const sessionSaved = await sessionRepository.updateSessionInfo(session); + const sessionSaved = await sessionRepository.updateSessionInfo({ session }); // then expect(sessionSaved.id).to.equal(session.id); @@ -391,10 +391,10 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasMembership = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession( + const hasMembership = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession({ userId, sessionId, - ); + }); // then expect(hasMembership).to.be.true; @@ -412,10 +412,10 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasMembership = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession( + const hasMembership = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession({ userId, sessionId, - ); + }); // then expect(hasMembership).to.be.false; @@ -439,10 +439,10 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasMembership = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession( - userIdNotAllowed, + const hasMembership = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession({ + userId: userIdNotAllowed, sessionId, - ); + }); // then expect(hasMembership).to.be.false; @@ -495,7 +495,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - await sessionRepository.unfinalize({ sessionId: 99 }); + await sessionRepository.unfinalize({ id: 99 }); // then const dbSession = await knex('sessions').select('*').where({ id: 99 }).first(); @@ -515,7 +515,7 @@ describe('Integration | Repository | Session', function () { // when await DomainTransaction.execute(async (domainTransaction) => { - await sessionRepository.unfinalize({ sessionId: 99, domainTransaction }); + await sessionRepository.unfinalize({ id: 99, domainTransaction }); return domainTransaction.knexTransaction.rollback(); }); @@ -529,7 +529,7 @@ describe('Integration | Repository | Session', function () { it('should throw a not found error', async function () { // given // when - const error = await catchErr(sessionRepository.unfinalize)({ sessionId: 99 }); + const error = await catchErr(sessionRepository.unfinalize)({ id: 99 }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -600,7 +600,7 @@ describe('Integration | Repository | Session', function () { // when const result = await sessionRepository.isSco({ - sessionId: session.id, + id: session.id, }); // then @@ -628,7 +628,7 @@ describe('Integration | Repository | Session', function () { // when const result = await sessionRepository.isSco({ - sessionId: session.id, + id: session.id, }); // then @@ -649,7 +649,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - await sessionRepository.remove(sessionId); + await sessionRepository.remove({ id: sessionId }); // then const foundSession = await knex('sessions').select('id').where({ id: sessionId }).first(); @@ -675,7 +675,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - await sessionRepository.remove(sessionId); + await sessionRepository.remove({ id: sessionId }); // then const foundSession = await knex('sessions').select('id').where({ id: sessionId }).first(); @@ -698,7 +698,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - await sessionRepository.remove(sessionId); + await sessionRepository.remove({ id: sessionId }); // then const foundSession = await knex('sessions').select('id').where({ id: sessionId }).first(); @@ -716,7 +716,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - await sessionRepository.remove(sessionId); + await sessionRepository.remove({ id: sessionId }); // then const foundSession = await knex('sessions').select('id').where({ id: sessionId }).first(); @@ -731,7 +731,7 @@ describe('Integration | Repository | Session', function () { const sessionId = 123456; // when - const error = await catchErr(sessionRepository.remove)(sessionId); + const error = await catchErr(sessionRepository.remove)({ id: sessionId }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -772,7 +772,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired(sessionId); + const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired({ id: sessionId }); // then expect(hasSomeCleaAcquired).to.be.true; @@ -811,7 +811,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired(sessionId); + const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired({ id: sessionId }); // then expect(hasSomeCleaAcquired).to.be.false; @@ -847,7 +847,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired(sessionId); + const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired({ id: sessionId }); // then expect(hasSomeCleaAcquired).to.be.false; @@ -864,7 +864,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired(sessionId); + const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired({ id: sessionId }); // then expect(hasSomeCleaAcquired).to.be.false; @@ -879,7 +879,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired(sessionId); + const hasSomeCleaAcquired = await sessionRepository.hasSomeCleaAcquired({ id: sessionId }); // then expect(hasSomeCleaAcquired).to.be.false; @@ -902,7 +902,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasNoStartedCertification = await sessionRepository.hasNoStartedCertification(sessionId); + const hasNoStartedCertification = await sessionRepository.hasNoStartedCertification({ id: sessionId }); // then expect(hasNoStartedCertification).to.be.false; @@ -917,7 +917,7 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const hasNoStartedCertification = await sessionRepository.hasNoStartedCertification(sessionId); + const hasNoStartedCertification = await sessionRepository.hasNoStartedCertification({ id: sessionId }); // then expect(hasNoStartedCertification).to.be.true; @@ -981,8 +981,9 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const unfinishedCertificationsCount = - await sessionRepository.countUncompletedCertificationsAssessment(sessionId); + const unfinishedCertificationsCount = await sessionRepository.countUncompletedCertificationsAssessment({ + id: sessionId, + }); // then expect(unfinishedCertificationsCount).to.equal(3); @@ -1008,8 +1009,9 @@ describe('Integration | Repository | Session', function () { await databaseBuilder.commit(); // when - const unfinishedCertificationsCount = - await sessionRepository.countUncompletedCertificationsAssessment(sessionId); + const unfinishedCertificationsCount = await sessionRepository.countUncompletedCertificationsAssessment({ + id: sessionId, + }); // then expect(unfinishedCertificationsCount).to.equal(0); diff --git a/api/tests/certification/session/unit/application/attendance-sheet-controller_test.js b/api/tests/certification/session/unit/application/attendance-sheet-controller_test.js index b7c23e0893e..9271466fee3 100644 --- a/api/tests/certification/session/unit/application/attendance-sheet-controller_test.js +++ b/api/tests/certification/session/unit/application/attendance-sheet-controller_test.js @@ -1,5 +1,5 @@ import { attendanceSheetController } from '../../../../../src/certification/session/application/attendance-sheet-controller.js'; -import { usecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; +import { usecases } from '../../../../../src/certification/session/domain/usecases/index.js'; import { expect, hFake, sinon } from '../../../../test-helper.js'; import { getI18n } from '../../../../tooling/i18n/i18n.js'; diff --git a/api/tests/certification/session/unit/application/certification-candidate-controller_test.js b/api/tests/certification/session/unit/application/certification-candidate-controller_test.js index f611739aba5..a72314d2368 100644 --- a/api/tests/certification/session/unit/application/certification-candidate-controller_test.js +++ b/api/tests/certification/session/unit/application/certification-candidate-controller_test.js @@ -1,6 +1,5 @@ import { certificationCandidateController } from '../../../../../src/certification/session/application/certification-candidate-controller.js'; import { usecases } from '../../../../../src/certification/session/domain/usecases/index.js'; -import { usecases as sharedUsecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; import { expect, hFake, sinon } from '../../../../test-helper.js'; describe('Unit | Controller | certification-candidate-controller', function () { @@ -21,8 +20,8 @@ describe('Unit | Controller | certification-candidate-controller', function () { }, }, }; - sinon.stub(sharedUsecases, 'addCertificationCandidateToSession'); - sharedUsecases.addCertificationCandidateToSession + sinon.stub(usecases, 'addCertificationCandidateToSession'); + usecases.addCertificationCandidateToSession .withArgs({ sessionId, certificationCandidate, @@ -91,10 +90,7 @@ describe('Unit | Controller | certification-candidate-controller', function () { request = { params: { id: sessionId, certificationCandidateId }, }; - sinon - .stub(sharedUsecases, 'deleteUnlinkedCertificationCandidate') - .withArgs({ certificationCandidateId }) - .resolves(); + sinon.stub(usecases, 'deleteUnlinkedCertificationCandidate').withArgs({ certificationCandidateId }).resolves(); }); it('should return 204 when deleting successfully the candidate', async function () { diff --git a/api/tests/certification/session/unit/application/certification-officer-controller_test.js b/api/tests/certification/session/unit/application/certification-officer-controller_test.js index 3708c0be9a4..1355e51f2d6 100644 --- a/api/tests/certification/session/unit/application/certification-officer-controller_test.js +++ b/api/tests/certification/session/unit/application/certification-officer-controller_test.js @@ -1,5 +1,5 @@ import { certificationOfficerController } from '../../../../../src/certification/session/application/certification-officer-controller.js'; -import { usecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; +import { usecases } from '../../../../../src/certification/session/domain/usecases/index.js'; import { expect, hFake, sinon } from '../../../../test-helper.js'; describe('Unit | Controller | certification-officer-controller', function () { diff --git a/api/tests/certification/session/unit/application/certification-report-controller_test.js b/api/tests/certification/session/unit/application/certification-report-controller_test.js index ae862f9f708..65df2413e1b 100644 --- a/api/tests/certification/session/unit/application/certification-report-controller_test.js +++ b/api/tests/certification/session/unit/application/certification-report-controller_test.js @@ -1,5 +1,5 @@ import { certificationReportController } from '../../../../../src/certification/session/application/certification-report-controller.js'; -import { usecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; +import { usecases } from '../../../../../src/certification/session/domain/usecases/index.js'; import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js'; describe('Unit | Controller | certification-report-controller', function () { diff --git a/api/tests/certification/session/unit/application/invigilator-kit-controller_test.js b/api/tests/certification/session/unit/application/invigilator-kit-controller_test.js index b4790d5ed1f..88f5fb09621 100644 --- a/api/tests/certification/session/unit/application/invigilator-kit-controller_test.js +++ b/api/tests/certification/session/unit/application/invigilator-kit-controller_test.js @@ -1,5 +1,5 @@ import { invigilatorKitController } from '../../../../../src/certification/session/application/invigilator-kit-controller.js'; -import { usecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; +import { usecases } from '../../../../../src/certification/session/domain/usecases/index.js'; import { LANGUAGES_CODE } from '../../../../../src/shared/domain/services/language-service.js'; import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js'; import { getI18n } from '../../../../tooling/i18n/i18n.js'; diff --git a/api/tests/certification/session/unit/application/session-controller_test.js b/api/tests/certification/session/unit/application/session-controller_test.js index ad9e90d0cbb..c3fe2da8e86 100644 --- a/api/tests/certification/session/unit/application/session-controller_test.js +++ b/api/tests/certification/session/unit/application/session-controller_test.js @@ -1,7 +1,7 @@ import * as events from '../../../../../lib/domain/events/index.js'; import { Session } from '../../../../../lib/domain/models/index.js'; import { sessionController } from '../../../../../src/certification/session/application/session-controller.js'; -import { usecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; +import { usecases } from '../../../../../src/certification/session/domain/usecases/index.js'; import { expect, hFake, sinon } from '../../../../test-helper.js'; describe('Unit | Controller | session-controller', function () { diff --git a/api/tests/certification/session/unit/application/session-live-alert-controller_test.js b/api/tests/certification/session/unit/application/session-live-alert-controller_test.js index 1e08e5c1943..cd8ae5f840d 100644 --- a/api/tests/certification/session/unit/application/session-live-alert-controller_test.js +++ b/api/tests/certification/session/unit/application/session-live-alert-controller_test.js @@ -1,25 +1,27 @@ import { sessionLiveAlertController } from '../../../../../src/certification/session/application/session-live-alert-controller.js'; -import { usecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; +import { usecases } from '../../../../../src/certification/session/domain/usecases/index.js'; import { expect, hFake, sinon } from '../../../../test-helper.js'; -describe('#dismissLiveAlert', function () { - it('should call dismissLiveAlert', async function () { - const sessionId = 123; - const userId = 456; - const request = buildRequest(sessionId); - request.deserializedPayload = { userId }; +describe('Unit | Controller | session-live-alert-controller', function () { + describe('#dismissLiveAlert', function () { + it('should call dismissLiveAlert', async function () { + const sessionId = 123; + const userId = 456; + const request = buildRequest(sessionId); + request.deserializedPayload = { userId }; - sinon.stub(usecases, 'dismissLiveAlert'); - usecases.dismissLiveAlert - .withArgs({ - sessionId, - userId, - }) - .resolves(); + sinon.stub(usecases, 'dismissLiveAlert'); + usecases.dismissLiveAlert + .withArgs({ + sessionId, + userId, + }) + .resolves(); - const response = await sessionLiveAlertController.dismissLiveAlert(request, hFake); + const response = await sessionLiveAlertController.dismissLiveAlert(request, hFake); - expect(response.statusCode).to.equal(204); + expect(response.statusCode).to.equal(204); + }); }); }); diff --git a/api/tests/certification/session/unit/application/session-mass-import-controller_test.js b/api/tests/certification/session/unit/application/session-mass-import-controller_test.js index 9e88d8e2b19..8581da3e2b2 100644 --- a/api/tests/certification/session/unit/application/session-mass-import-controller_test.js +++ b/api/tests/certification/session/unit/application/session-mass-import-controller_test.js @@ -1,7 +1,6 @@ import { usecases as libUsecases } from '../../../../../lib/domain/usecases/index.js'; import { sessionMassImportController } from '../../../../../src/certification/session/application/session-mass-import-controller.js'; import { usecases } from '../../../../../src/certification/session/domain/usecases/index.js'; -import { usecases as sharedUsecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js'; describe('Unit | Controller | mass-import-controller', function () { @@ -24,10 +23,10 @@ describe('Unit | Controller | mass-import-controller', function () { deserializeForSessionsImport: sinon.stub().returns(['session']), }; - sinon.stub(sharedUsecases, 'validateSessions'); + sinon.stub(usecases, 'validateSessions'); sinon.stub(libUsecases, 'getCertificationCenter'); - sharedUsecases.validateSessions.resolves({ cachedValidatedSessionsKey }); + usecases.validateSessions.resolves({ cachedValidatedSessionsKey }); libUsecases.getCertificationCenter.resolves(domainBuilder.buildCertificationCenter()); // when await sessionMassImportController.validateSessions(request, hFake, { @@ -36,7 +35,7 @@ describe('Unit | Controller | mass-import-controller', function () { }); // then - expect(sharedUsecases.validateSessions).to.have.been.calledWithExactly({ + expect(usecases.validateSessions).to.have.been.calledWithExactly({ sessions: ['session'], certificationCenterId: 123, userId: 2, @@ -63,10 +62,10 @@ describe('Unit | Controller | mass-import-controller', function () { deserializeForSessionsImport: sinon.stub().returns(['session']), }; - sinon.stub(sharedUsecases, 'validateSessions'); + sinon.stub(usecases, 'validateSessions'); sinon.stub(libUsecases, 'getCertificationCenter'); - sharedUsecases.validateSessions.resolves({ + usecases.validateSessions.resolves({ cachedValidatedSessionsKey, sessionsCount, sessionsWithoutCandidatesCount, @@ -99,15 +98,15 @@ describe('Unit | Controller | mass-import-controller', function () { auth: { credentials: { userId: 2 } }, }; - sinon.stub(sharedUsecases, 'createSessions'); + sinon.stub(usecases, 'createSessions'); - sharedUsecases.createSessions.resolves(); + usecases.createSessions.resolves(); // when await sessionMassImportController.createSessions(request, hFake); // then - expect(sharedUsecases.createSessions).to.have.been.calledWithExactly({ + expect(usecases.createSessions).to.have.been.calledWithExactly({ cachedValidatedSessionsKey: 'uuid', certificationCenterId: 123, userId: 2, diff --git a/api/tests/certification/session/unit/application/unfinalize-controller_test.js b/api/tests/certification/session/unit/application/unfinalize-controller_test.js index 692cd53e7de..292136f411f 100644 --- a/api/tests/certification/session/unit/application/unfinalize-controller_test.js +++ b/api/tests/certification/session/unit/application/unfinalize-controller_test.js @@ -1,5 +1,5 @@ import { unfinalizeSession } from '../../../../../src/certification/session/application/unfinalize-controller.js'; -import { usecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; +import { usecases } from '../../../../../src/certification/session/domain/usecases/index.js'; import { expect, hFake, sinon } from '../../../../test-helper.js'; describe('Unit | Controller | unfinalize-controller', function () { diff --git a/api/tests/certification/session/unit/domain/services/sessions-import-validation-service_test.js b/api/tests/certification/session/unit/domain/services/sessions-import-validation-service_test.js index 29bbe30768f..d8d85a6b0d2 100644 --- a/api/tests/certification/session/unit/domain/services/sessions-import-validation-service_test.js +++ b/api/tests/certification/session/unit/domain/services/sessions-import-validation-service_test.js @@ -1,8 +1,8 @@ import lodash from 'lodash'; import { CERTIFICATION_CANDIDATES_ERRORS } from '../../../../../../lib/domain/constants/certification-candidates-errors.js'; +import { CpfBirthInformationValidation } from '../../../../../../src/certification/session/domain/services/certification-cpf-service.js'; import * as sessionsImportValidationService from '../../../../../../src/certification/session/domain/services/sessions-import-validation-service.js'; -import { CpfBirthInformationValidation } from '../../../../../../src/certification/shared/domain/services/certification-cpf-service.js'; import { domainBuilder, expect, sinon } from '../../../../../test-helper.js'; const { noop } = lodash; diff --git a/api/tests/certification/course/unit/domain/usecases/abort-certification-course_test.js b/api/tests/certification/session/unit/domain/usecases/abort-certification-course_test.js similarity index 77% rename from api/tests/certification/course/unit/domain/usecases/abort-certification-course_test.js rename to api/tests/certification/session/unit/domain/usecases/abort-certification-course_test.js index 4d230fdd3a6..35638b4b3b2 100644 --- a/api/tests/certification/course/unit/domain/usecases/abort-certification-course_test.js +++ b/api/tests/certification/session/unit/domain/usecases/abort-certification-course_test.js @@ -1,5 +1,5 @@ -import { CertificationCourse } from '../../../../../../lib/domain/models/CertificationCourse.js'; -import { abortCertificationCourse } from '../../../../../../src/certification/course/domain/usecases/abort-certification-course.js'; +import { abortCertificationCourse } from '../../../../../../src/certification/session/domain/usecases/abort-certification-course.js'; +import { CertificationCourse } from '../../../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { EntityValidationError } from '../../../../../../src/shared/domain/errors.js'; import { catchErr, domainBuilder, expect, sinon } from '../../../../../test-helper.js'; @@ -18,7 +18,7 @@ describe('Unit | UseCase | abort-certification-course', function () { // given const abortReason = 'technical'; const certificationCourse = domainBuilder.buildCertificationCourse({ abortReason: null }); - certificationCourseRepository.get.withArgs(certificationCourse.getId()).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: certificationCourse.getId() }).resolves(certificationCourse); // when await abortCertificationCourse({ @@ -28,19 +28,19 @@ describe('Unit | UseCase | abort-certification-course', function () { }); // then - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), abortReason: 'technical', }), - ); + }); }); it('should throw an error if abortReason is not provided', async function () { // given const abortReason = null; const certificationCourse = domainBuilder.buildCertificationCourse({ abortReason: null }); - certificationCourseRepository.get.withArgs(certificationCourse.getId()).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: certificationCourse.getId() }).resolves(certificationCourse); // when const err = await catchErr(abortCertificationCourse)({ diff --git a/api/tests/certification/session/unit/domain/usecases/add-certification-candidate-to-session_test.js b/api/tests/certification/session/unit/domain/usecases/add-certification-candidate-to-session_test.js index a5c0b1f3d57..ab7b1c21069 100644 --- a/api/tests/certification/session/unit/domain/usecases/add-certification-candidate-to-session_test.js +++ b/api/tests/certification/session/unit/domain/usecases/add-certification-candidate-to-session_test.js @@ -4,8 +4,8 @@ import { CertificationCandidateOnFinalizedSessionError, CertificationCandidatesError, } from '../../../../../../lib/domain/errors.js'; +import { CpfBirthInformationValidation } from '../../../../../../src/certification/session/domain/services/certification-cpf-service.js'; import { addCertificationCandidateToSession } from '../../../../../../src/certification/session/domain/usecases/add-certification-candidate-to-session.js'; -import { CpfBirthInformationValidation } from '../../../../../../src/certification/shared/domain/services/certification-cpf-service.js'; import { catchErr, domainBuilder, expect, sinon } from '../../../../../test-helper.js'; describe('Unit | UseCase | add-certification-candidate-to-session', function () { diff --git a/api/tests/certification/session/unit/domain/usecases/create-session_test.js b/api/tests/certification/session/unit/domain/usecases/create-session_test.js index 613cffb86d4..fdb20c7c23a 100644 --- a/api/tests/certification/session/unit/domain/usecases/create-session_test.js +++ b/api/tests/certification/session/unit/domain/usecases/create-session_test.js @@ -1,12 +1,10 @@ import { Session } from '../../../../../../src/certification/session/domain/models/Session.js'; import { createSession } from '../../../../../../src/certification/session/domain/usecases/create-session.js'; -import { ForbiddenAccess } from '../../../../../../src/shared/domain/errors.js'; -import { catchErr, domainBuilder, expect, sinon } from '../../../../../test-helper.js'; +import { domainBuilder, expect, sinon } from '../../../../../test-helper.js'; describe('Unit | UseCase | create-session', function () { let certificationCenterRepository; let sessionRepository; - let userRepository; let userWithMemberships; const userId = 'userId'; const certificationCenterId = 'certificationCenterId'; @@ -16,7 +14,6 @@ describe('Unit | UseCase | create-session', function () { beforeEach(function () { certificationCenterRepository = { get: sinon.stub() }; sessionRepository = { save: sinon.stub() }; - userRepository = { getWithCertificationCenterMemberships: sinon.stub() }; userWithMemberships = { hasAccessToCertificationCenter: sinon.stub() }; }); @@ -32,7 +29,6 @@ describe('Unit | UseCase | create-session', function () { session: sessionToSave, certificationCenterRepository, sessionRepository, - userRepository, sessionValidator: sessionValidatorStub, }); @@ -52,69 +48,42 @@ describe('Unit | UseCase | create-session', function () { sessionValidatorStub = { validate: sinon.stub().returns() }; sessionCodeServiceStub = { getNewSessionCode: sinon.stub().returns(accessCode) }; userWithMemberships.hasAccessToCertificationCenter = sinon.stub(); - userRepository.getWithCertificationCenterMemberships = sinon.stub(); certificationCenterRepository.get = sinon.stub(); sessionRepository.save = sinon.stub(); userWithMemberships.hasAccessToCertificationCenter.withArgs(certificationCenterId).returns(true); - userRepository.getWithCertificationCenterMemberships.withArgs(userId).returns(userWithMemberships); sessionRepository.save.resolves(); }); - context('when user has no certification center membership', function () { - it('should throw a Forbidden error', async function () { - // given - userWithMemberships.hasAccessToCertificationCenter.withArgs(certificationCenterId).returns(false); - sessionCodeServiceStub = { getNewSessionCode: sinon.stub() }; - - // when - const error = await catchErr(createSession)({ - userId, - session: sessionToSave, - certificationCenterRepository, - sessionRepository, - userRepository, - sessionValidator: sessionValidatorStub, - sessionCodeService: sessionCodeServiceStub, - }); - - // then - expect(error).to.be.instanceOf(ForbiddenAccess); + it('should save the session with appropriate arguments', async function () { + // given + const certificationCenter = domainBuilder.buildCertificationCenter({ + id: certificationCenterId, + name: certificationCenterName, }); - }); - - context('when user has certification center membership', function () { - it('should save the session with appropriate arguments', async function () { - // given - const certificationCenter = domainBuilder.buildCertificationCenter({ - id: certificationCenterId, - name: certificationCenterName, - }); - certificationCenterRepository.get.withArgs(certificationCenterId).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenterId }).resolves(certificationCenter); - // when - await createSession({ - userId, - session: sessionToSave, - certificationCenterRepository, - sessionRepository, - userRepository, - sessionValidator: sessionValidatorStub, - sessionCodeService: sessionCodeServiceStub, - }); - - // then - const expectedSession = new Session({ - certificationCenterId, - certificationCenter: certificationCenterName, - accessCode, - supervisorPassword: sinon.match(/^[2346789BCDFGHJKMPQRTVWXY]{5}$/), - version: 2, - createdBy: userId, - }); + // when + await createSession({ + userId, + session: sessionToSave, + certificationCenterRepository, + sessionRepository, + sessionValidator: sessionValidatorStub, + sessionCodeService: sessionCodeServiceStub, + }); - expect(sessionRepository.save).to.have.been.calledWithExactly(expectedSession); + // then + const expectedSession = new Session({ + certificationCenterId, + certificationCenter: certificationCenterName, + accessCode, + supervisorPassword: sinon.match(/^[2346789BCDFGHJKMPQRTVWXY]{5}$/), + version: 2, + createdBy: userId, }); + + expect(sessionRepository.save).to.have.been.calledWithExactly({ session: expectedSession }); }); context('when session is created by a V3 pilot certification center', function () { @@ -126,7 +95,9 @@ describe('Unit | UseCase | create-session', function () { isV3Pilot: true, }); - certificationCenterRepository.get.withArgs(certificationCenterId).resolves(v3PilotCertificationCenter); + certificationCenterRepository.get + .withArgs({ id: certificationCenterId }) + .resolves(v3PilotCertificationCenter); // when await createSession({ @@ -134,7 +105,6 @@ describe('Unit | UseCase | create-session', function () { session: sessionToSave, certificationCenterRepository, sessionRepository, - userRepository, sessionValidator: sessionValidatorStub, sessionCodeService: sessionCodeServiceStub, }); @@ -149,7 +119,7 @@ describe('Unit | UseCase | create-session', function () { createdBy: userId, }); - expect(sessionRepository.save).to.have.been.calledWithExactly(expectedSession); + expect(sessionRepository.save).to.have.been.calledWithExactly({ session: expectedSession }); }); }); }); diff --git a/api/tests/certification/session/unit/domain/usecases/create-sessions_test.js b/api/tests/certification/session/unit/domain/usecases/create-sessions_test.js index 404a1ce9613..efc9f19ebe4 100644 --- a/api/tests/certification/session/unit/domain/usecases/create-sessions_test.js +++ b/api/tests/certification/session/unit/domain/usecases/create-sessions_test.js @@ -3,7 +3,7 @@ import { CertificationCenter } from '../../../../../../lib/domain/models/Certifi import { DomainTransaction } from '../../../../../../lib/infrastructure/DomainTransaction.js'; import { Session } from '../../../../../../src/certification/session/domain/models/Session.js'; import { createSessions } from '../../../../../../src/certification/session/domain/usecases/create-sessions.js'; -import { CertificationVersion } from '../../../../../../src/shared/domain/models/CertificationVersion.js'; +import { CertificationVersion } from '../../../../../../src/certification/shared/domain/models/CertificationVersion.js'; import { catchErr, domainBuilder, expect, sinon } from '../../../../../test-helper.js'; describe('Unit | UseCase | sessions-mass-import | create-sessions', function () { @@ -55,7 +55,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () it('should should only save the session', async function () { // given const certificationCenter = new CertificationCenter(); - certificationCenterRepository.get.withArgs(certificationCenter.id).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenter.id }).resolves(certificationCenter); const temporaryCachedSessions = [ { id: undefined, @@ -89,7 +89,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () // then const expectedSession = new Session({ ...temporaryCachedSessions[0], createdBy: sessionCreatorId }); - expect(sessionRepository.save).to.have.been.calledOnceWith(expectedSession, domainTransaction); + expect(sessionRepository.save).to.have.been.calledOnceWith({ session: expectedSession, domainTransaction }); expect(certificationCandidateRepository.saveInSession).to.not.have.been.called; }); }); @@ -98,7 +98,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () it('should save the session and the candidates', async function () { // given const certificationCenter = new CertificationCenter({ id: 567 }); - certificationCenterRepository.get.withArgs(certificationCenter.id).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenter.id }).resolves(certificationCenter); const certificationCandidate = domainBuilder.buildCertificationCandidate({ sessionId: undefined }); const sessionCreatorId = 1234; const temporaryCachedSessions = [ @@ -134,7 +134,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () // then const expectedSession = new Session({ ...temporaryCachedSessions[0], createdBy: sessionCreatorId }); - expect(sessionRepository.save).to.have.been.calledOnceWith(expectedSession, domainTransaction); + expect(sessionRepository.save).to.have.been.calledOnceWith({ session: expectedSession, domainTransaction }); expect(certificationCandidateRepository.saveInSession).to.have.been.calledOnceWith({ sessionId: 1234, certificationCandidate, @@ -147,7 +147,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () it('should save the session with the V3 version', async function () { // given const certificationCenter = new CertificationCenter({ id: 567, isV3Pilot: true }); - certificationCenterRepository.get.withArgs(certificationCenter.id).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenter.id }).resolves(certificationCenter); const sessionCreatorId = 1234; const temporaryCachedSessions = [ { @@ -186,7 +186,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () version: CertificationVersion.V3, createdBy: sessionCreatorId, }); - expect(sessionRepository.save).to.have.been.calledOnceWith(expectedSession, domainTransaction); + expect(sessionRepository.save).to.have.been.calledOnceWith({ session: expectedSession, domainTransaction }); }); }); @@ -195,7 +195,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () // given const sessionCreatorId = 1234; const certificationCenter = new CertificationCenter({ id: 567, isV3Pilot: false }); - certificationCenterRepository.get.withArgs(certificationCenter.id).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenter.id }).resolves(certificationCenter); const temporaryCachedSessions = [ { id: undefined, @@ -234,7 +234,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () version: CertificationVersion.V2, createdBy: sessionCreatorId, }); - expect(sessionRepository.save).to.have.been.calledOnceWith(expectedSession, domainTransaction); + expect(sessionRepository.save).to.have.been.calledOnceWith({ session: expectedSession, domainTransaction }); }); }); }); @@ -243,7 +243,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () it('should delete previous candidates and save the new candidates', async function () { // given const certificationCenter = new CertificationCenter(); - certificationCenterRepository.get.withArgs(certificationCenter.id).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenter.id }).resolves(certificationCenter); const certificationCandidate = domainBuilder.buildCertificationCandidate({ sessionId: undefined }); const temporaryCachedSessions = [ { @@ -281,7 +281,7 @@ describe('Unit | UseCase | sessions-mass-import | create-sessions', function () it('should delete cached sessions', async function () { // given const certificationCenter = new CertificationCenter(); - certificationCenterRepository.get.withArgs(certificationCenter.id).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenter.id }).resolves(certificationCenter); const certificationCandidate = domainBuilder.buildCertificationCandidate({ sessionId: undefined }); const temporaryCachedSessions = [ { diff --git a/api/tests/certification/session/unit/domain/usecases/delete-unlinked-certification-candidate_test.js b/api/tests/certification/session/unit/domain/usecases/delete-unlinked-certification-candidate_test.js index 524d88f75fd..c6e7bea8ec9 100644 --- a/api/tests/certification/session/unit/domain/usecases/delete-unlinked-certification-candidate_test.js +++ b/api/tests/certification/session/unit/domain/usecases/delete-unlinked-certification-candidate_test.js @@ -16,8 +16,8 @@ describe('Unit | UseCase | delete-unlinked-sertification-candidate', function () context('When the certification candidate is not linked to a user', function () { beforeEach(function () { - certificationCandidateRepository.isNotLinked.withArgs(certificationCandidateId).resolves(true); - certificationCandidateRepository.remove.withArgs(certificationCandidateId).resolves(true); + certificationCandidateRepository.isNotLinked.withArgs({ id: certificationCandidateId }).resolves(true); + certificationCandidateRepository.remove.withArgs({ id: certificationCandidateId }).resolves(true); }); it('should delete the certification candidate', async function () { @@ -34,7 +34,7 @@ describe('Unit | UseCase | delete-unlinked-sertification-candidate', function () context('When the certification candidate is linked to a user ', function () { beforeEach(function () { - certificationCandidateRepository.isNotLinked.withArgs(certificationCandidateId).resolves(false); + certificationCandidateRepository.isNotLinked.withArgs({ id: certificationCandidateId }).resolves(false); }); it('should throw a forbidden deletion error', async function () { diff --git a/api/tests/certification/session/unit/domain/usecases/dismiss-live-alert_test.js b/api/tests/certification/session/unit/domain/usecases/dismiss-live-alert_test.js index 6d0209d454a..a3726ed6763 100644 --- a/api/tests/certification/session/unit/domain/usecases/dismiss-live-alert_test.js +++ b/api/tests/certification/session/unit/domain/usecases/dismiss-live-alert_test.js @@ -1,6 +1,6 @@ import { NotFoundError } from '../../../../../../lib/domain/errors.js'; -import { CertificationChallengeLiveAlertStatus } from '../../../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; import { dismissLiveAlert } from '../../../../../../src/certification/session/domain/usecases/dismiss-live-alert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; import { catchErr, domainBuilder, expect, sinon } from '../../../../../test-helper.js'; describe('Unit | UseCase | dismiss-live-alert', function () { diff --git a/api/tests/certification/session/unit/domain/usecases/finalize-session_test.js b/api/tests/certification/session/unit/domain/usecases/finalize-session_test.js index 2adf49ee2f6..9a07a6b3d9c 100644 --- a/api/tests/certification/session/unit/domain/usecases/finalize-session_test.js +++ b/api/tests/certification/session/unit/domain/usecases/finalize-session_test.js @@ -46,11 +46,10 @@ describe('Unit | UseCase | finalize-session', function () { }); context('When the session status is already finalized', function () { - beforeEach(function () { - sessionRepository.isFinalized.withArgs(sessionId).resolves(true); - }); - it('should throw a SessionAlreadyFinalizedError error', async function () { + // given + sessionRepository.isFinalized.withArgs({ id: sessionId }).resolves(true); + // when const err = await catchErr(finalizeSession)({ sessionId, @@ -68,7 +67,7 @@ describe('Unit | UseCase | finalize-session', function () { context('When the session has not started yet', function () { it('should throw a SessionWithoutStartedCertificationError error', async function () { // given - sessionRepository.hasNoStartedCertification.withArgs(sessionId).resolves(true); + sessionRepository.hasNoStartedCertification.withArgs({ id: sessionId }).resolves(true); // when const err = await catchErr(finalizeSession)({ @@ -122,7 +121,7 @@ describe('Unit | UseCase | finalize-session', function () { abortReason: 'candidate', completedAt: '2022-01-01', }); - sessionRepository.countUncompletedCertificationsAssessment.withArgs(sessionId).resolves(0); + sessionRepository.countUncompletedCertificationsAssessment.withArgs({ id: sessionId }).resolves(0); certificationCourseRepository.findCertificationCoursesBySessionId .withArgs({ sessionId }) .resolves([completedCertificationCourse]); @@ -156,7 +155,7 @@ describe('Unit | UseCase | finalize-session', function () { abortReason: null, completedAt: null, }); - sessionRepository.countUncompletedCertificationsAssessment.withArgs(sessionId).resolves(1); + sessionRepository.countUncompletedCertificationsAssessment.withArgs({ id: sessionId }).resolves(1); certificationCourseRepository.findCertificationCoursesBySessionId .withArgs({ sessionId }) .resolves([uncompletedCertificationCourse]); @@ -191,8 +190,8 @@ describe('Unit | UseCase | finalize-session', function () { hasSeenEndTestScreen: false, }); certificationReports = [validReportForFinalization]; - sessionRepository.isFinalized.withArgs(sessionId).resolves(false); - certificationReportRepository.finalizeAll.withArgs(certificationReports).resolves(); + sessionRepository.isFinalized.withArgs({ id: sessionId }).resolves(false); + certificationReportRepository.finalizeAll.withArgs({ certificationReports }).resolves(); sessionRepository.finalize .withArgs({ id: sessionId, @@ -215,8 +214,8 @@ describe('Unit | UseCase | finalize-session', function () { isCompleted: true, }); certificationReports = [validReportForFinalization]; - sessionRepository.isFinalized.withArgs(sessionId).resolves(false); - certificationReportRepository.finalizeAll.withArgs(certificationReports).resolves(); + sessionRepository.isFinalized.withArgs({ id: sessionId }).resolves(false); + certificationReportRepository.finalizeAll.withArgs({ certificationReports }).resolves(); sessionRepository.finalize .withArgs({ id: sessionId, @@ -268,7 +267,7 @@ describe('Unit | UseCase | finalize-session', function () { }); certificationReports = [validReportForFinalization]; sessionRepository.isFinalized.withArgs(sessionId).resolves(false); - certificationReportRepository.finalizeAll.withArgs(certificationReports).resolves(); + certificationReportRepository.finalizeAll.withArgs({ certificationReports }).resolves(); sessionRepository.finalize .withArgs({ id: sessionId, diff --git a/api/tests/certification/session/unit/domain/usecases/get-attendance-sheet_test.js b/api/tests/certification/session/unit/domain/usecases/get-attendance-sheet_test.js index b1f3843b659..2074144c2a7 100644 --- a/api/tests/certification/session/unit/domain/usecases/get-attendance-sheet_test.js +++ b/api/tests/certification/session/unit/domain/usecases/get-attendance-sheet_test.js @@ -12,7 +12,7 @@ describe('Unit | UseCase | get-attendance-sheet', function () { const session = _buildSessionWithCandidate('SUP', true); sessionRepository.doesUserHaveCertificationCenterMembershipForSession.resolves(true); - sessionForAttendanceSheetRepository.getWithCertificationCandidates.withArgs(1).resolves(session); + sessionForAttendanceSheetRepository.getWithCertificationCandidates.withArgs({ id: 1 }).resolves(session); const pdfBuffer = Buffer.from('some pdf file'); const fileName = 'attendance-sheet-example.pdf'; diff --git a/api/tests/certification/session/unit/domain/usecases/get-invigilator-kit-session-info_test.js b/api/tests/certification/session/unit/domain/usecases/get-invigilator-kit-session-info_test.js index 84c8b64acf0..642a2bb5526 100644 --- a/api/tests/certification/session/unit/domain/usecases/get-invigilator-kit-session-info_test.js +++ b/api/tests/certification/session/unit/domain/usecases/get-invigilator-kit-session-info_test.js @@ -19,7 +19,7 @@ describe('Unit | UseCase | get-invigilator-kit-info', function () { invigilatorPassword: '12AB5', accessCode: '1B3DE6', }); - sessionForInvigilatorKitRepository.get.withArgs(sessionId).resolves(sessionForInvigilatorKit); + sessionForInvigilatorKitRepository.get.withArgs({ id: sessionId }).resolves(sessionForInvigilatorKit); const sessionRepository = { doesUserHaveCertificationCenterMembershipForSession: sinon.stub() }; sessionRepository.doesUserHaveCertificationCenterMembershipForSession.resolves(true); diff --git a/api/tests/certification/session/unit/domain/usecases/get-session-certification-candidates_test.js b/api/tests/certification/session/unit/domain/usecases/get-session-certification-candidates_test.js index a358436178f..c6440ab13d4 100644 --- a/api/tests/certification/session/unit/domain/usecases/get-session-certification-candidates_test.js +++ b/api/tests/certification/session/unit/domain/usecases/get-session-certification-candidates_test.js @@ -21,7 +21,7 @@ describe('Unit | UseCase | get-session-certification-candidates', function () { domainBuilder.certification.session.buildCertificationSessionComplementaryCertification({ id: candidate.complementaryCertificationId, }); - candidateRepository.findBySessionId.withArgs(sessionId).resolves([candidate]); + candidateRepository.findBySessionId.withArgs({ sessionId }).resolves([candidate]); complementaryCertificationRepository.getById .withArgs({ complementaryCertificationId: candidate.complementaryCertificationId, @@ -52,7 +52,7 @@ describe('Unit | UseCase | get-session-certification-candidates', function () { const candidate = domainBuilder.certification.session.buildCertificationSessionCandidate({ complementaryCertificationId: undefined, }); - candidateRepository.findBySessionId.withArgs(sessionId).resolves([candidate]); + candidateRepository.findBySessionId.withArgs({ sessionId }).resolves([candidate]); const expectedCandidate = domainBuilder.certification.session.buildCertificationSessionEnrolledCandidate({ isLinked: true, }); diff --git a/api/tests/certification/session/unit/domain/usecases/unfinalize-session_test.js b/api/tests/certification/session/unit/domain/usecases/unfinalize-session_test.js index a98e447e4c1..0334a5e0484 100644 --- a/api/tests/certification/session/unit/domain/usecases/unfinalize-session_test.js +++ b/api/tests/certification/session/unit/domain/usecases/unfinalize-session_test.js @@ -25,11 +25,11 @@ describe('Unit | UseCase | unfinalize-session', function () { // then expect(sessionRepository.unfinalize).to.have.been.calledWithMatch({ - sessionId: 99, + id: 99, domainTransaction: sinon.match.object, }); - expect(sessionRepository.isPublished).to.have.been.calledWithMatch(99); + expect(sessionRepository.isPublished).to.have.been.calledWithMatch({ id: 99 }); expect(finalizedSessionRepository.remove).to.have.been.calledWithMatch({ sessionId: 99, diff --git a/api/tests/certification/session/unit/domain/usecases/update-session_test.js b/api/tests/certification/session/unit/domain/usecases/update-session_test.js index 24ecd723fc7..6ab56615bfa 100644 --- a/api/tests/certification/session/unit/domain/usecases/update-session_test.js +++ b/api/tests/certification/session/unit/domain/usecases/update-session_test.js @@ -25,8 +25,8 @@ describe('Unit | UseCase | update-session', function () { get: sinon.stub(), updateSessionInfo: sinon.stub(), }; - sessionRepository.get.withArgs(originalSession.id).resolves(originalSession); - sessionRepository.updateSessionInfo.callsFake((updatedSession) => updatedSession); + sessionRepository.get.withArgs({ id: originalSession.id }).resolves(originalSession); + sessionRepository.updateSessionInfo.callsFake(({ session: updatedSession }) => updatedSession); sessionValidator = { validate: sinon.stub() }; sessionValidator.validate.withArgs(originalSession).returns(); }); @@ -56,7 +56,7 @@ describe('Unit | UseCase | update-session', function () { // then return promise.then((resultSession) => { - expect(sessionRepository.updateSessionInfo).to.have.been.calledWithExactly(updatedSession); + expect(sessionRepository.updateSessionInfo).to.have.been.calledWithExactly({ session: updatedSession }); expect(resultSession.address).to.equal(updatedSession.address); }); }); @@ -85,7 +85,7 @@ describe('Unit | UseCase | update-session', function () { // then return promise.then((resultSession) => { - expect(sessionRepository.updateSessionInfo).to.have.been.calledWithExactly(updatedSession); + expect(sessionRepository.updateSessionInfo).to.have.been.calledWithExactly({ session: updatedSession }); expect(resultSession.address).to.equal(updatedSession.address); }); }); @@ -94,7 +94,7 @@ describe('Unit | UseCase | update-session', function () { context('when an error occurred', function () { it('should throw an error when the session could not be retrieved', function () { // given - sessionRepository.get.withArgs(originalSession.id).rejects(); + sessionRepository.get.withArgs({ id: originalSession.id }).rejects(); // when const promise = updateSession({ @@ -124,7 +124,7 @@ describe('Unit | UseCase | update-session', function () { it('should throw an error when the session could not be updated', function () { // given - sessionRepository.updateSessionInfo.withArgs(originalSession).rejects(); + sessionRepository.updateSessionInfo.withArgs({ session: originalSession }).rejects(); // when const promise = updateSession({ diff --git a/api/tests/certification/session/unit/domain/usecases/validate-live-alert_test.js b/api/tests/certification/session/unit/domain/usecases/validate-live-alert_test.js index b2042bec194..221af21eeba 100644 --- a/api/tests/certification/session/unit/domain/usecases/validate-live-alert_test.js +++ b/api/tests/certification/session/unit/domain/usecases/validate-live-alert_test.js @@ -1,6 +1,6 @@ import { NotFoundError } from '../../../../../../lib/domain/errors.js'; -import { CertificationChallengeLiveAlertStatus } from '../../../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; import { validateLiveAlert } from '../../../../../../src/certification/session/domain/usecases/validate-live-alert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; import { CertificationIssueReportCategory, CertificationIssueReportSubcategories, @@ -135,7 +135,9 @@ describe('Unit | UseCase | validate-live-alert', function () { expectedCertificationIssueReport.id = undefined; expectedCertificationIssueReport.description = undefined; - expect(certificationIssueReportRepository.save).to.have.been.calledWith(expectedCertificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledWith({ + certificationIssueReport: expectedCertificationIssueReport, + }); }); }); }); diff --git a/api/tests/certification/session/unit/domain/usecases/validate-sessions_test.js b/api/tests/certification/session/unit/domain/usecases/validate-sessions_test.js index 05d721d164f..e8e06c185e4 100644 --- a/api/tests/certification/session/unit/domain/usecases/validate-sessions_test.js +++ b/api/tests/certification/session/unit/domain/usecases/validate-sessions_test.js @@ -3,8 +3,8 @@ import { CERTIFICATION_SESSIONS_ERRORS } from '../../../../../../lib/domain/cons import { CertificationCandidate } from '../../../../../../lib/domain/models/CertificationCandidate.js'; import { Session } from '../../../../../../src/certification/session/domain/models/Session.js'; import { SessionMassImportReport } from '../../../../../../src/certification/session/domain/models/SessionMassImportReport.js'; +import { CpfBirthInformationValidation } from '../../../../../../src/certification/session/domain/services/certification-cpf-service.js'; import { validateSessions } from '../../../../../../src/certification/session/domain/usecases/validate-sessions.js'; -import { CpfBirthInformationValidation } from '../../../../../../src/certification/shared/domain/services/certification-cpf-service.js'; import { domainBuilder, expect, sinon } from '../../../../../test-helper.js'; import { getI18n } from '../../../../../tooling/i18n/i18n.js'; @@ -34,7 +34,7 @@ describe('Unit | UseCase | sessions-mass-import | validate-sessions', function ( complementaryCertificationRepository = { getByLabel: sinon.stub() }; certificationCourseRepository = sinon.stub(); sessionCodeService = { getNewSessionCode: sinon.stub().returns(accessCode) }; - certificationCenterRepository.get.withArgs(certificationCenterId).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenterId }).resolves(certificationCenter); sessionsImportValidationService = { getValidatedComplementaryCertificationForMassImport: sinon.stub(), @@ -410,7 +410,7 @@ describe('Unit | UseCase | sessions-mass-import | validate-sessions', function ( ], }); - certificationCenterRepository.get.withArgs(certificationCenterId).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenterId }).resolves(certificationCenter); // when const sessionsMassImportReport = await validateSessions({ @@ -496,7 +496,7 @@ describe('Unit | UseCase | sessions-mass-import | validate-sessions', function ( duplicateCandidateErrors: [], }); - certificationCenterRepository.get.withArgs(certificationCenterId).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: certificationCenterId }).resolves(certificationCenter); // when const sessionsMassImportReport = await validateSessions({ diff --git a/api/tests/certification/shared/integration/infrastructure/repositories/certification-center-repository_test.js b/api/tests/certification/shared/integration/infrastructure/repositories/certification-center-repository_test.js index 00107a130e2..6758c3275ff 100644 --- a/api/tests/certification/shared/integration/infrastructure/repositories/certification-center-repository_test.js +++ b/api/tests/certification/shared/integration/infrastructure/repositories/certification-center-repository_test.js @@ -44,7 +44,7 @@ describe('Integration | Repository | Certification Center', function () { await databaseBuilder.commit(); // when - const certificationCenter = await certificationCenterRepository.get(1); + const certificationCenter = await certificationCenterRepository.get({ id: 1 }); // then expect(certificationCenter).to.deepEqualInstance(expectedCertificationCenter); @@ -102,7 +102,7 @@ describe('Integration | Repository | Certification Center', function () { await databaseBuilder.commit(); // when - const certificationCenter = await certificationCenterRepository.get(1); + const certificationCenter = await certificationCenterRepository.get({ id: 1 }); expect(certificationCenter).to.deepEqualInstance(expectedCertificationCenter); }); @@ -112,7 +112,7 @@ describe('Integration | Repository | Certification Center', function () { it('should throw a NotFound error', async function () { // when const nonExistentId = 1; - const error = await catchErr(certificationCenterRepository.get)(nonExistentId); + const error = await catchErr(certificationCenterRepository.get)({ id: nonExistentId }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -146,7 +146,7 @@ describe('Integration | Repository | Certification Center', function () { await databaseBuilder.commit(); // when - const certificationCenter = await certificationCenterRepository.getBySessionId(sessionId); + const certificationCenter = await certificationCenterRepository.getBySessionId({ sessionId }); // then expect(certificationCenter).to.deepEqualInstance(expectedCertificationCenter); @@ -191,7 +191,7 @@ describe('Integration | Repository | Certification Center', function () { await databaseBuilder.commit(); // when - const certificationCenter = await certificationCenterRepository.getBySessionId(sessionId); + const certificationCenter = await certificationCenterRepository.getBySessionId({ sessionId }); expect(certificationCenter).to.deepEqualInstance(expectedCertificationCenter); }); @@ -210,7 +210,7 @@ describe('Integration | Repository | Certification Center', function () { await databaseBuilder.commit(); // when - const error = await catchErr(certificationCenterRepository.getBySessionId)(8); + const error = await catchErr(certificationCenterRepository.getBySessionId)({ sessionId: 8 }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -227,7 +227,7 @@ describe('Integration | Repository | Certification Center', function () { }); // when - const savedCertificationCenter = await certificationCenterRepository.save(certificationCenter); + const savedCertificationCenter = await certificationCenterRepository.save({ certificationCenter }); // then expect(savedCertificationCenter).to.be.instanceof(CertificationCenter); @@ -245,7 +245,7 @@ describe('Integration | Repository | Certification Center', function () { await databaseBuilder.commit(); // when - const savedCertificationCenter = await certificationCenterRepository.save(certificationCenter); + const savedCertificationCenter = await certificationCenterRepository.save({ certificationCenter }); // then expect(savedCertificationCenter.updatedAt).to.deep.equal(now); @@ -681,7 +681,7 @@ describe('Integration | Repository | Certification Center', function () { await databaseBuilder.commit(); // when - const refererEmails = await certificationCenterRepository.getRefererEmails(certificationCenterId); + const refererEmails = await certificationCenterRepository.getRefererEmails({ id: certificationCenterId }); // then expect(refererEmails).to.be.empty; @@ -712,7 +712,7 @@ describe('Integration | Repository | Certification Center', function () { await databaseBuilder.commit(); // when - const refererEmails = await certificationCenterRepository.getRefererEmails(certificationCenterId); + const refererEmails = await certificationCenterRepository.getRefererEmails({ id: certificationCenterId }); // then expect(refererEmails).to.deepEqualArray([ diff --git a/api/tests/certification/session/integration/infrastructure/repositories/certification-challenge-live-alert-repository_test.js b/api/tests/certification/shared/integration/infrastructure/repositories/certification-challenge-live-alert-repository_test.js similarity index 93% rename from api/tests/certification/session/integration/infrastructure/repositories/certification-challenge-live-alert-repository_test.js rename to api/tests/certification/shared/integration/infrastructure/repositories/certification-challenge-live-alert-repository_test.js index cbaea55afe4..8e8435dfad0 100644 --- a/api/tests/certification/session/integration/infrastructure/repositories/certification-challenge-live-alert-repository_test.js +++ b/api/tests/certification/shared/integration/infrastructure/repositories/certification-challenge-live-alert-repository_test.js @@ -1,7 +1,7 @@ import _ from 'lodash'; -import { CertificationChallengeLiveAlertStatus } from '../../../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; -import * as certificationChallengeLiveAlertRepository from '../../../../../../src/certification/session/infrastructure/repositories/certification-challenge-live-alert-repository.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; +import * as certificationChallengeLiveAlertRepository from '../../../../../../src/certification/shared/infrastructure/repositories/certification-challenge-live-alert-repository.js'; import { databaseBuilder, domainBuilder, expect, knex } from '../../../../../test-helper.js'; const assessmentIdWithNoAlerts = 123; @@ -77,7 +77,9 @@ describe('Integration | Repository | Certification Challenge Live Alert', functi describe('when no liveAlert is linked to the assessment id', function () { it('should return an empty array', async function () { // given / when - const liveAlerts = await certificationChallengeLiveAlertRepository.getByAssessmentId(assessmentIdWithNoAlerts); + const liveAlerts = await certificationChallengeLiveAlertRepository.getByAssessmentId({ + assessmentId: assessmentIdWithNoAlerts, + }); // then expect(liveAlerts).to.have.length(0); @@ -98,7 +100,9 @@ describe('Integration | Repository | Certification Challenge Live Alert', functi await databaseBuilder.commit(); // when - const liveAlerts = await certificationChallengeLiveAlertRepository.getByAssessmentId(assessmentIdWithLiveAlert); + const liveAlerts = await certificationChallengeLiveAlertRepository.getByAssessmentId({ + assessmentId: assessmentIdWithLiveAlert, + }); // then expect(liveAlerts).to.have.length(1); @@ -131,9 +135,9 @@ describe('Integration | Repository | Certification Challenge Live Alert', functi // when const liveAlertValidatedChallengeIds = - await certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId( - assessmentIdWithLiveAlert, - ); + await certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId({ + assessmentId: assessmentIdWithLiveAlert, + }); // then expect(liveAlertValidatedChallengeIds).to.deep.equal([challengeId]); @@ -158,9 +162,9 @@ describe('Integration | Repository | Certification Challenge Live Alert', functi // when const liveAlertValidatedChallengeIds = - await certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId( - assessmentIdWithLiveAlert, - ); + await certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId({ + assessmentId: assessmentIdWithLiveAlert, + }); // then expect(liveAlertValidatedChallengeIds).to.have.length(0); @@ -193,9 +197,9 @@ describe('Integration | Repository | Certification Challenge Live Alert', functi // when const liveAlertValidatedChallengeIds = - await certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId( - assessmentIdWithLiveAlert, - ); + await certificationChallengeLiveAlertRepository.getLiveAlertValidatedChallengeIdsByAssessmentId({ + assessmentId: assessmentIdWithLiveAlert, + }); // then expect(liveAlertValidatedChallengeIds).to.deep.equal([challengeId]); diff --git a/api/tests/certification/shared/integration/infrastructure/repositories/certification-challenge-repository_test.js b/api/tests/certification/shared/integration/infrastructure/repositories/certification-challenge-repository_test.js index 2c248b07304..a427323d36c 100644 --- a/api/tests/certification/shared/integration/infrastructure/repositories/certification-challenge-repository_test.js +++ b/api/tests/certification/shared/integration/infrastructure/repositories/certification-challenge-repository_test.js @@ -2,8 +2,8 @@ import _ from 'lodash'; import { AssessmentEndedError } from '../../../../../../lib/domain/errors.js'; import { CertificationChallenge } from '../../../../../../lib/domain/models/CertificationChallenge.js'; +import { CertificationVersion } from '../../../../../../src/certification/shared/domain/models/CertificationVersion.js'; import * as certificationChallengeRepository from '../../../../../../src/certification/shared/infrastructure/repositories/certification-challenge-repository.js'; -import { CertificationVersion } from '../../../../../../src/shared/domain/models/CertificationVersion.js'; import { databaseBuilder, domainBuilder, expect } from '../../../../../test-helper.js'; describe('Integration | Repository | Certification Challenge', function () { diff --git a/api/tests/certification/shared/integration/infrastructure/repositories/certification-course-repository_test.js b/api/tests/certification/shared/integration/infrastructure/repositories/certification-course-repository_test.js index c1c6474e05b..4f72a9d4dc8 100644 --- a/api/tests/certification/shared/integration/infrastructure/repositories/certification-course-repository_test.js +++ b/api/tests/certification/shared/integration/infrastructure/repositories/certification-course-repository_test.js @@ -1,8 +1,8 @@ import _ from 'lodash'; import { NotFoundError } from '../../../../../../lib/domain/errors.js'; -import { CertificationCourse } from '../../../../../../lib/domain/models/index.js'; import { BookshelfCertificationCourse } from '../../../../../../lib/infrastructure/orm-models/CertificationCourse.js'; +import { CertificationCourse } from '../../../../../../src/certification/shared/domain/models/CertificationCourse.js'; import * as certificationCourseRepository from '../../../../../../src/certification/shared/infrastructure/repositories/certification-course-repository.js'; import { catchErr, databaseBuilder, domainBuilder, expect } from '../../../../../test-helper.js'; @@ -37,7 +37,9 @@ describe('Integration | Repository | Certification Course', function () { const savedCertificationCourse = await certificationCourseRepository.save({ certificationCourse }); // then - const retrievedCertificationCourse = await certificationCourseRepository.get(savedCertificationCourse.getId()); + const retrievedCertificationCourse = await certificationCourseRepository.get({ + id: savedCertificationCourse.getId(), + }); const fieldsToOmitInCertificationCourse = [ 'id', 'assessment', @@ -105,7 +107,9 @@ describe('Integration | Repository | Certification Course', function () { const savedCertificationCourse = await certificationCourseRepository.save({ certificationCourse }); // then - const retrievedCertificationCourse = await certificationCourseRepository.get(savedCertificationCourse.getId()); + const retrievedCertificationCourse = await certificationCourseRepository.get({ + id: savedCertificationCourse.getId(), + }); expect(retrievedCertificationCourse.getVersion()).to.equal(3); }); @@ -128,7 +132,7 @@ describe('Integration | Repository | Certification Course', function () { await databaseBuilder.commit(); // when - const sessionId = await certificationCourseRepository.getSessionId(77); + const sessionId = await certificationCourseRepository.getSessionId({ id: 77 }); // then expect(sessionId).to.deep.equal(99); @@ -136,7 +140,7 @@ describe('Integration | Repository | Certification Course', function () { it('should throw an error if not found', async function () { // when - const error = await catchErr(certificationCourseRepository.getSessionId)(77); + const error = await catchErr(certificationCourseRepository.getSessionId)({ id: 77 }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -159,7 +163,9 @@ describe('Integration | Repository | Certification Course', function () { }); it('should retrieve certification course informations', async function () { // when - const actualCertificationCourse = await certificationCourseRepository.get(expectedCertificationCourse.id); + const actualCertificationCourse = await certificationCourseRepository.get({ + id: expectedCertificationCourse.id, + }); // then const actualCertificationCourseDTO = actualCertificationCourse.toDTO(); @@ -179,7 +185,9 @@ describe('Integration | Repository | Certification Course', function () { it('should retrieve associated challenges with the certification course', async function () { // when - const thisCertificationCourse = await certificationCourseRepository.get(expectedCertificationCourse.id); + const thisCertificationCourse = await certificationCourseRepository.get({ + id: expectedCertificationCourse.id, + }); // then expect(thisCertificationCourse.toDTO().challenges.length).to.equal(2); @@ -198,7 +206,9 @@ describe('Integration | Repository | Certification Course', function () { it('should retrieve associated assessment', async function () { // when - const thisCertificationCourse = await certificationCourseRepository.get(expectedCertificationCourse.id); + const thisCertificationCourse = await certificationCourseRepository.get({ + id: expectedCertificationCourse.id, + }); // then expect(thisCertificationCourse.toDTO().assessment.id).to.equal(assessmentId); @@ -235,7 +245,9 @@ describe('Integration | Repository | Certification Course', function () { await databaseBuilder.commit(); // when - const actualCertificationCourse = await certificationCourseRepository.get(expectedCertificationCourse.id); + const actualCertificationCourse = await certificationCourseRepository.get({ + id: expectedCertificationCourse.id, + }); // then expect(actualCertificationCourse.getNumberOfChallenges()).to.equal(maximumAssessmentLength); @@ -246,7 +258,7 @@ describe('Integration | Repository | Certification Course', function () { context('When the certification course does not exist', function () { it('should retrieve a NotFoundError Error', function () { // when - const promise = certificationCourseRepository.get(3); + const promise = certificationCourseRepository.get({ id: 3 }); // then return expect(promise).to.be.rejectedWith(NotFoundError); @@ -361,7 +373,7 @@ describe('Integration | Repository | Certification Course', function () { const countCertificationCoursesBeforeUpdate = await BookshelfCertificationCourse.count(); // when - await certificationCourseRepository.update(certificationCourse); + await certificationCourseRepository.update({ certificationCourse }); // then const countCertificationCoursesAfterUpdate = await BookshelfCertificationCourse.count(); @@ -386,13 +398,13 @@ describe('Integration | Repository | Certification Course', function () { }); // when - await certificationCourseRepository.update(unpersistedUpdatedCertificationCourse); + await certificationCourseRepository.update({ certificationCourse: unpersistedUpdatedCertificationCourse }); // then const unpersistedUpdatedCertificationCourseDTO = unpersistedUpdatedCertificationCourse.toDTO(); - const persistedUpdatedCertificationCourse = await certificationCourseRepository.get( - unpersistedUpdatedCertificationCourseDTO.id, - ); + const persistedUpdatedCertificationCourse = await certificationCourseRepository.get({ + id: unpersistedUpdatedCertificationCourseDTO.id, + }); const persistedUpdatedCertificationCourseDTO = persistedUpdatedCertificationCourse.toDTO(); expect(persistedUpdatedCertificationCourse.getId()).to.equal(unpersistedUpdatedCertificationCourse.getId()); expect(persistedUpdatedCertificationCourseDTO.firstName).to.equal( @@ -427,10 +439,10 @@ describe('Integration | Repository | Certification Course', function () { certificationCourse.version = 1; // when - await certificationCourseRepository.update(certificationCourse); + await certificationCourseRepository.update({ certificationCourse }); // then - const certificationCourseUpdated = await certificationCourseRepository.get(certificationCourse.getId()); + const certificationCourseUpdated = await certificationCourseRepository.get({ id: certificationCourse.getId() }); expect(certificationCourseUpdated.toDTO().version).to.equal(2); }); @@ -443,7 +455,7 @@ describe('Integration | Repository | Certification Course', function () { }); // when - const promise = certificationCourseRepository.update(certificationCourseToBeUpdated); + const promise = certificationCourseRepository.update({ certificationCourse: certificationCourseToBeUpdated }); // then return expect(promise).to.be.rejectedWith(NotFoundError); @@ -455,7 +467,7 @@ describe('Integration | Repository | Certification Course', function () { it('should return true if certification code does not exist', async function () { // when - const result = await certificationCourseRepository.isVerificationCodeAvailable(verificationCode); + const result = await certificationCourseRepository.isVerificationCodeAvailable({ verificationCode }); // then expect(result).to.equal(true); @@ -467,7 +479,7 @@ describe('Integration | Repository | Certification Course', function () { await databaseBuilder.commit(); // when - const result = await certificationCourseRepository.isVerificationCodeAvailable(verificationCode); + const result = await certificationCourseRepository.isVerificationCodeAvailable({ verificationCode }); // then expect(result).to.equal(false); diff --git a/api/tests/certification/shared/integration/infrastructure/repositories/certification-cpf-city-repository_test.js b/api/tests/certification/shared/integration/infrastructure/repositories/certification-cpf-city-repository_test.js index 99606f509e1..fc0741fca5b 100644 --- a/api/tests/certification/shared/integration/infrastructure/repositories/certification-cpf-city-repository_test.js +++ b/api/tests/certification/shared/integration/infrastructure/repositories/certification-cpf-city-repository_test.js @@ -1,5 +1,5 @@ +import * as certificationCpfCityRepository from '../../../../../../src/certification/session/infrastructure/repositories/certification-cpf-city-repository.js'; import { CertificationCpfCity } from '../../../../../../src/certification/shared/domain/models/CertificationCpfCity.js'; -import * as certificationCpfCityRepository from '../../../../../../src/certification/shared/infrastructure/repositories/certification-cpf-city-repository.js'; import { databaseBuilder, domainBuilder, expect } from '../../../../../test-helper.js'; describe('Integration | Repository | certificationCpfCityRepository', function () { diff --git a/api/tests/certification/shared/integration/infrastructure/repositories/certification-cpf-country-repository_test.js b/api/tests/certification/shared/integration/infrastructure/repositories/certification-cpf-country-repository_test.js index 27fd38f4ce6..fe65bf69671 100644 --- a/api/tests/certification/shared/integration/infrastructure/repositories/certification-cpf-country-repository_test.js +++ b/api/tests/certification/shared/integration/infrastructure/repositories/certification-cpf-country-repository_test.js @@ -1,5 +1,5 @@ +import * as certificationCpfCountryRepository from '../../../../../../src/certification/session/infrastructure/repositories/certification-cpf-country-repository.js'; import { CertificationCpfCountry } from '../../../../../../src/certification/shared/domain/models/CertificationCpfCountry.js'; -import * as certificationCpfCountryRepository from '../../../../../../src/certification/shared/infrastructure/repositories/certification-cpf-country-repository.js'; import { databaseBuilder, domainBuilder, expect } from '../../../../../test-helper.js'; describe('Integration | Repository | certificationCpfCountryRepository', function () { diff --git a/api/tests/certification/shared/integration/infrastructure/repositories/certification-issue-report-repository_test.js b/api/tests/certification/shared/integration/infrastructure/repositories/certification-issue-report-repository_test.js index e3d890f1c55..494113f1ee8 100644 --- a/api/tests/certification/shared/integration/infrastructure/repositories/certification-issue-report-repository_test.js +++ b/api/tests/certification/shared/integration/infrastructure/repositories/certification-issue-report-repository_test.js @@ -31,7 +31,9 @@ describe('Integration | Repository | Certification Issue Report', function () { }); // when - const savedCertificationIssueReport = await certificationIssueReportRepository.save(certificationIssueReport); + const savedCertificationIssueReport = await certificationIssueReportRepository.save({ + certificationIssueReport, + }); // then const expectedSavedCertificationIssueReport = domainBuilder.buildCertificationIssueReport({ @@ -86,7 +88,9 @@ describe('Integration | Repository | Certification Issue Report', function () { }; // when - const savedCertificationIssueReport = await certificationIssueReportRepository.save(updatedIssueReport); + const savedCertificationIssueReport = await certificationIssueReportRepository.save({ + certificationIssueReport: updatedIssueReport, + }); // then const expectedSavedCertificationIssueReport = domainBuilder.buildCertificationIssueReport({ @@ -115,7 +119,7 @@ describe('Integration | Repository | Certification Issue Report', function () { await databaseBuilder.commit(); // when - await certificationIssueReportRepository.remove(certificationIssueReportToDeleteId); + await certificationIssueReportRepository.remove({ id: certificationIssueReportToDeleteId }); // then const exists = await knex('certification-issue-reports') @@ -132,7 +136,7 @@ describe('Integration | Repository | Certification Issue Report', function () { await databaseBuilder.commit(); // when - const result = await certificationIssueReportRepository.get(issueReport.id); + const result = await certificationIssueReportRepository.get({ id: issueReport.id }); // then const expectedIssueReport = domainBuilder.buildCertificationIssueReport({ @@ -149,7 +153,7 @@ describe('Integration | Repository | Certification Issue Report', function () { const unknownCertificationIssueReportId = 999999; // when - const error = await catchErr(certificationIssueReportRepository.get)(unknownCertificationIssueReportId); + const error = await catchErr(certificationIssueReportRepository.get)({ id: unknownCertificationIssueReportId }); // then expect(error).to.be.instanceOf(NotFoundError); @@ -184,9 +188,9 @@ describe('Integration | Repository | Certification Issue Report', function () { await databaseBuilder.commit(); // when - const results = await certificationIssueReportRepository.findByCertificationCourseId( - targetCertificationCourse.id, - ); + const results = await certificationIssueReportRepository.findByCertificationCourseId({ + certificationCourseId: targetCertificationCourse.id, + }); // then const expectedIssueReports = [ diff --git a/api/tests/certification/shared/integration/infrastructure/repositories/certification-report-repository_test.js b/api/tests/certification/shared/integration/infrastructure/repositories/certification-report-repository_test.js index 5b6425ecfab..e8be9f725d6 100644 --- a/api/tests/certification/shared/integration/infrastructure/repositories/certification-report-repository_test.js +++ b/api/tests/certification/shared/integration/infrastructure/repositories/certification-report-repository_test.js @@ -37,7 +37,7 @@ describe('Integration | Repository | CertificationReport', function () { await databaseBuilder.commit(); // when - const certificationReports = await certificationReportRepository.findBySessionId(sessionId); + const certificationReports = await certificationReportRepository.findBySessionId({ sessionId }); // then const expectedCertificationReport1 = domainBuilder.buildCertificationReport({ @@ -68,7 +68,7 @@ describe('Integration | Repository | CertificationReport', function () { const sessionId = databaseBuilder.factory.buildSession().id; // when - const certificationReports = await certificationReportRepository.findBySessionId(sessionId); + const certificationReports = await certificationReportRepository.findBySessionId({ sessionId }); // then expect(certificationReports).to.deep.equal([]); @@ -114,10 +114,12 @@ describe('Integration | Repository | CertificationReport', function () { }); // when - await certificationReportRepository.finalizeAll([certificationReport1, certificationReport2]); + await certificationReportRepository.finalizeAll({ + certificationReports: [certificationReport1, certificationReport2], + }); // then - const actualCertificationReports = await certificationReportRepository.findBySessionId(sessionId); + const actualCertificationReports = await certificationReportRepository.findBySessionId({ sessionId }); const actualReport1 = _.find(actualCertificationReports, { id: certificationReport1.id }); expect(actualReport1.hasSeenEndTestScreen).to.equal(true); @@ -157,10 +159,10 @@ describe('Integration | Repository | CertificationReport', function () { const error = await catchErr( certificationReportRepository.finalizeAll, certificationReportRepository, - )([certificationReport1, certificationReport2]); + )({ certificationRepports: [certificationReport1, certificationReport2] }); // then - const actualCertificationReports = await certificationReportRepository.findBySessionId(sessionId); + const actualCertificationReports = await certificationReportRepository.findBySessionId({ sessionId }); const actualReport1 = _.find(actualCertificationReports, { id: certificationReport1.id }); const actualReport2 = _.find(actualCertificationReports, { id: certificationReport2.id }); diff --git a/api/tests/unit/domain/models/CertificationCourse_test.js b/api/tests/certification/shared/unit/domain/models/CertificationCourse_test.js similarity index 97% rename from api/tests/unit/domain/models/CertificationCourse_test.js rename to api/tests/certification/shared/unit/domain/models/CertificationCourse_test.js index 534c835861f..b28ce62d53b 100644 --- a/api/tests/unit/domain/models/CertificationCourse_test.js +++ b/api/tests/certification/shared/unit/domain/models/CertificationCourse_test.js @@ -1,7 +1,7 @@ -import { EntityValidationError } from '../../../../src/shared/domain/errors.js'; -import { CertificationVersion } from '../../../../src/shared/domain/models/CertificationVersion.js'; -import { generateChallengeList } from '../../../certification/shared/fixtures/challenges.js'; -import { domainBuilder, expect } from '../../../test-helper.js'; +import { CertificationVersion } from '../../../../../../src/certification/shared/domain/models/CertificationVersion.js'; +import { EntityValidationError } from '../../../../../../src/shared/domain/errors.js'; +import { domainBuilder, expect } from '../../../../../test-helper.js'; +import { generateChallengeList } from '../../../fixtures/challenges.js'; describe('Unit | Domain | Models | CertificationCourse', function () { describe('#cancel #isCancelled', function () { diff --git a/api/tests/certification/shared/unit/domain/services/certification-cpf-service_test.js b/api/tests/certification/shared/unit/domain/services/certification-cpf-service_test.js index 109d16d13ba..47ed52bb947 100644 --- a/api/tests/certification/shared/unit/domain/services/certification-cpf-service_test.js +++ b/api/tests/certification/shared/unit/domain/services/certification-cpf-service_test.js @@ -2,7 +2,7 @@ import { CERTIFICATION_CANDIDATES_ERRORS } from '../../../../../../lib/domain/co import { CpfBirthInformationValidation, getBirthInformation, -} from '../../../../../../src/certification/shared/domain/services/certification-cpf-service.js'; +} from '../../../../../../src/certification/session/domain/services/certification-cpf-service.js'; import { domainBuilder, expect, sinon } from '../../../../../test-helper.js'; describe('Unit | Service | Certification CPF service', function () { diff --git a/api/tests/integration/domain/services/certification-candidates-ods-service/certification-candidates-ods-service_test.js b/api/tests/integration/domain/services/certification-candidates-ods-service/certification-candidates-ods-service_test.js index e17b5a76fe1..045635c38f1 100644 --- a/api/tests/integration/domain/services/certification-candidates-ods-service/certification-candidates-ods-service_test.js +++ b/api/tests/integration/domain/services/certification-candidates-ods-service/certification-candidates-ods-service_test.js @@ -7,11 +7,11 @@ import { CertificationCandidatesError } from '../../../../../lib/domain/errors.j import { CertificationCandidate } from '../../../../../lib/domain/models/index.js'; import * as certificationCandidatesOdsService from '../../../../../lib/domain/services/certification-candidates-ods-service.js'; import * as complementaryCertificationRepository from '../../../../../lib/infrastructure/repositories/complementary-certification-repository.js'; +import * as certificationCpfService from '../../../../../src/certification/session/domain/services/certification-cpf-service.js'; +import * as certificationCpfCityRepository from '../../../../../src/certification/session/infrastructure/repositories/certification-cpf-city-repository.js'; +import * as certificationCpfCountryRepository from '../../../../../src/certification/session/infrastructure/repositories/certification-cpf-country-repository.js'; import { ComplementaryCertificationKeys } from '../../../../../src/certification/shared/domain/models/ComplementaryCertificationKeys.js'; -import * as certificationCpfService from '../../../../../src/certification/shared/domain/services/certification-cpf-service.js'; import * as certificationCenterRepository from '../../../../../src/certification/shared/infrastructure/repositories/certification-center-repository.js'; -import * as certificationCpfCityRepository from '../../../../../src/certification/shared/infrastructure/repositories/certification-cpf-city-repository.js'; -import * as certificationCpfCountryRepository from '../../../../../src/certification/shared/infrastructure/repositories/certification-cpf-country-repository.js'; import { catchErr, databaseBuilder, domainBuilder, expect, sinon } from '../../../../test-helper.js'; import { getI18n } from '../../../../tooling/i18n/i18n.js'; diff --git a/api/tests/integration/infrastructure/repositories/sessions/session-for-supervising-repository_test.js b/api/tests/integration/infrastructure/repositories/sessions/session-for-supervising-repository_test.js index 9bb0300f999..e01f330f4e6 100644 --- a/api/tests/integration/infrastructure/repositories/sessions/session-for-supervising-repository_test.js +++ b/api/tests/integration/infrastructure/repositories/sessions/session-for-supervising-repository_test.js @@ -3,9 +3,9 @@ import _ from 'lodash'; import { NotFoundError } from '../../../../../lib/domain/errors.js'; import { SessionForSupervising } from '../../../../../lib/domain/read-models/SessionForSupervising.js'; import * as sessionForSupervisingRepository from '../../../../../lib/infrastructure/repositories/sessions/session-for-supervising-repository.js'; -import { CertificationChallengeLiveAlertStatus } from '../../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationVersion } from '../../../../../src/certification/shared/domain/models/CertificationVersion.js'; import { Assessment } from '../../../../../src/shared/domain/models/Assessment.js'; -import { CertificationVersion } from '../../../../../src/shared/domain/models/CertificationVersion.js'; import { catchErr, databaseBuilder, expect } from '../../../../test-helper.js'; describe('Integration | Repository | SessionForSupervising', function () { diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-certification_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-certification_test.js index 0c343924514..8228e8668be 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-certification_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-get-next-challenge-for-certification_test.js @@ -1,5 +1,5 @@ +import { CertificationVersion } from '../../../../../src/certification/shared/domain/models/CertificationVersion.js'; import { Assessment } from '../../../../../src/shared/domain/models/Assessment.js'; -import { CertificationVersion } from '../../../../../src/shared/domain/models/CertificationVersion.js'; import { createServer, databaseBuilder, diff --git a/api/tests/shared/acceptance/application/assessments/assessment-controller-get_test.js b/api/tests/shared/acceptance/application/assessments/assessment-controller-get_test.js index e5e5b7a8955..0cd414c260b 100644 --- a/api/tests/shared/acceptance/application/assessments/assessment-controller-get_test.js +++ b/api/tests/shared/acceptance/application/assessments/assessment-controller-get_test.js @@ -5,33 +5,118 @@ import { databaseBuilder, expect, generateValidRequestAuthorizationHeader, + learningContentBuilder, + mockLearningContent, } from '../../../../test-helper.js'; const { FRENCH_SPOKEN } = LOCALE; describe('Acceptance | API | assessment-controller-get', function () { let server; - let userId; - const courseId = 'courseId'; - - beforeEach(async function () { - server = await createServer(); - userId = databaseBuilder.factory.buildUser({}).id; - await databaseBuilder.commit(); - }); + const courseId = 'course_id'; describe('(no provided answer) GET /api/assessments/:id', function () { let options; - let assessmentId; - beforeEach(async function () { - assessmentId = databaseBuilder.factory.buildAssessment({ + // Rule disabled to allow dynamic generated tests. See https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-setup-in-describe.md#disallow-setup-in-describe-blocks-mochano-setup-in-describe + /* eslint-disable mocha/no-setup-in-describe */ + [ + Assessment.types.CERTIFICATION, + Assessment.types.PREVIEW, + Assessment.types.CAMPAIGN, + Assessment.types.PIX1D_MISSION, + ].forEach(function (type) { + /* eslint-enable mocha/no-setup-in-describe */ + context(`when the assessment is of type ${type}`, function () { + it('should return 200 HTTP status code', async function () { + // given + server = await createServer(); + const userId = databaseBuilder.factory.buildUser({}).id; + const assessmentId = databaseBuilder.factory.buildAssessment({ + userId, + courseId, + state: Assessment.states.STARTED, + type, + }).id; + await databaseBuilder.commit(); + + options = { + method: 'GET', + url: `/api/assessments/${assessmentId}`, + headers: { + authorization: generateValidRequestAuthorizationHeader(userId), + 'accept-language': FRENCH_SPOKEN, + }, + }; + + // when + const response = await server.inject(options); + + // then + expect(response.statusCode).to.equal(200); + }); + }); + }); + + /* eslint-enable-next-line mocha/no-setup-in-describe */ + context(`when the assessment is of type DEMO`, function () { + it('should return 200 HTTP status code', async function () { + // given + const learningContent = [ + { + id: '1. Information et données', + competences: [], + courses: [ + { + id: 'course_id', + isActive: true, + competenceId: 'competence_id', + challengeIds: ['first_challenge', 'second_challenge'], + }, + ], + }, + ]; + const learningContentObjects = learningContentBuilder.fromAreas(learningContent); + mockLearningContent(learningContentObjects); + + const assessmentId = databaseBuilder.factory.buildAssessment({ + userId: null, + courseId, + state: Assessment.states.STARTED, + type: Assessment.types.DEMO, + }).id; + server = await createServer(); + + await databaseBuilder.commit(); + + options = { + method: 'GET', + url: `/api/assessments/${assessmentId}`, + headers: { + 'accept-language': FRENCH_SPOKEN, + }, + }; + + // when + const response = await server.inject(options); + + // then + expect(response.statusCode).to.equal(200); + }); + }); + + it('should return application/json', async function () { + // given + server = await createServer(); + const userId = databaseBuilder.factory.buildUser({}).id; + const assessmentId = databaseBuilder.factory.buildAssessment({ userId, courseId, state: Assessment.states.STARTED, type: Assessment.types.PREVIEW, }).id; await databaseBuilder.commit(); + options = { method: 'GET', url: `/api/assessments/${assessmentId}`, @@ -40,17 +125,7 @@ describe('Acceptance | API | assessment-controller-get', function () { 'accept-language': FRENCH_SPOKEN, }, }; - }); - it('should return 200 HTTP status code', async function () { - // when - const response = await server.inject(options); - - // then - expect(response.statusCode).to.equal(200); - }); - - it('should return application/json', async function () { // when const response = await server.inject(options); @@ -60,6 +135,26 @@ describe('Acceptance | API | assessment-controller-get', function () { }); it('should return the expected assessment', async function () { + // given + server = await createServer(); + const userId = databaseBuilder.factory.buildUser({}).id; + const assessmentId = databaseBuilder.factory.buildAssessment({ + userId, + courseId, + state: Assessment.states.STARTED, + type: Assessment.types.PREVIEW, + }).id; + await databaseBuilder.commit(); + + options = { + method: 'GET', + url: `/api/assessments/${assessmentId}`, + headers: { + authorization: generateValidRequestAuthorizationHeader(userId), + 'accept-language': FRENCH_SPOKEN, + }, + }; + // when const response = await server.inject(options); @@ -80,7 +175,7 @@ describe('Acceptance | API | assessment-controller-get', function () { relationships: { course: { data: { - id: 'courseId', + id: 'course_id', type: 'courses', }, }, @@ -98,11 +193,16 @@ describe('Acceptance | API | assessment-controller-get', function () { }); describe('(when userId and assessmentId match) GET /api/assessments/:id', function () { - let assessmentId; let options; beforeEach(async function () { - assessmentId = databaseBuilder.factory.buildAssessment({ userId, courseId, type: Assessment.types.PREVIEW }).id; + server = await createServer(); + const userId = databaseBuilder.factory.buildUser({}).id; + const assessmentId = databaseBuilder.factory.buildAssessment({ + userId, + courseId, + type: Assessment.types.PREVIEW, + }).id; await databaseBuilder.commit(); options = { headers: { @@ -124,9 +224,11 @@ describe('Acceptance | API | assessment-controller-get', function () { }); describe('(answers provided, assessment completed) GET /api/assessments/:id', function () { - let assessmentId, answer1, answer2; + let assessmentId, userId, answer1, answer2; beforeEach(async function () { + server = await createServer(); + userId = databaseBuilder.factory.buildUser({}).id; assessmentId = databaseBuilder.factory.buildAssessment({ userId, courseId, diff --git a/api/tests/shared/unit/domain/models/Assessment_test.js b/api/tests/shared/unit/domain/models/Assessment_test.js index ea891350f61..765812e8078 100644 --- a/api/tests/shared/unit/domain/models/Assessment_test.js +++ b/api/tests/shared/unit/domain/models/Assessment_test.js @@ -1,4 +1,4 @@ -import { CertificationChallengeLiveAlertStatus } from '../../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; import { Assessment } from '../../../../../src/shared/domain/models/Assessment.js'; import { domainBuilder, expect } from '../../../../test-helper.js'; diff --git a/api/tests/tooling/domain-builder/factory/build-certification-challenge-live-alert.js b/api/tests/tooling/domain-builder/factory/build-certification-challenge-live-alert.js index 75a8e8918df..801b11f415b 100644 --- a/api/tests/tooling/domain-builder/factory/build-certification-challenge-live-alert.js +++ b/api/tests/tooling/domain-builder/factory/build-certification-challenge-live-alert.js @@ -1,7 +1,7 @@ import { CertificationChallengeLiveAlert, CertificationChallengeLiveAlertStatus, -} from '../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; +} from '../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; const buildCertificationChallengeLiveAlert = function ({ id = 456, diff --git a/api/tests/tooling/domain-builder/factory/build-certification-course.js b/api/tests/tooling/domain-builder/factory/build-certification-course.js index 76a1d3a1650..0c0f89219d5 100644 --- a/api/tests/tooling/domain-builder/factory/build-certification-course.js +++ b/api/tests/tooling/domain-builder/factory/build-certification-course.js @@ -1,4 +1,4 @@ -import { CertificationCourse } from '../../../../lib/domain/models/CertificationCourse.js'; +import { CertificationCourse } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { CertificationIssueReport } from '../../../../src/certification/shared/domain/models/CertificationIssueReport.js'; import { CertificationIssueReportCategory } from '../../../../src/certification/shared/domain/models/CertificationIssueReportCategory.js'; import { buildAssessment } from './build-assessment.js'; diff --git a/api/tests/tooling/domain-builder/factory/build-jury-certification.js b/api/tests/tooling/domain-builder/factory/build-jury-certification.js index 741f61f4f9e..1e432e0701c 100644 --- a/api/tests/tooling/domain-builder/factory/build-jury-certification.js +++ b/api/tests/tooling/domain-builder/factory/build-jury-certification.js @@ -1,6 +1,6 @@ import { JuryCertification } from '../../../../lib/domain/models/JuryCertification.js'; +import { CertificationVersion } from '../../../../src/certification/shared/domain/models/CertificationVersion.js'; import { JuryComment, JuryCommentContexts } from '../../../../src/certification/shared/domain/models/JuryComment.js'; -import { CertificationVersion } from '../../../../src/shared/domain/models/CertificationVersion.js'; import { buildCertificationIssueReport } from './build-certification-issue-report.js'; import { buildCompetenceMark } from './build-competence-mark.js'; diff --git a/api/tests/unit/application/certification-courses/certification-course-controller_test.js b/api/tests/unit/application/certification-courses/certification-course-controller_test.js index a129485d319..5d4528163a2 100644 --- a/api/tests/unit/application/certification-courses/certification-course-controller_test.js +++ b/api/tests/unit/application/certification-courses/certification-course-controller_test.js @@ -1,7 +1,7 @@ import { certificationCourseController } from '../../../../lib/application/certification-courses/certification-course-controller.js'; -import { CertificationCourse } from '../../../../lib/domain/models/index.js'; import { usecases } from '../../../../lib/domain/usecases/index.js'; import { DomainTransaction } from '../../../../lib/infrastructure/DomainTransaction.js'; +import { CertificationCourse } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { domainBuilder, expect, generateValidRequestAuthorizationHeader, hFake, sinon } from '../../../test-helper.js'; import { getI18n } from '../../../tooling/i18n/i18n.js'; diff --git a/api/tests/unit/application/preHandlers/authorization_test.js b/api/tests/unit/application/preHandlers/authorization_test.js index a28eeb2a86b..14dbcd94f65 100644 --- a/api/tests/unit/application/preHandlers/authorization_test.js +++ b/api/tests/unit/application/preHandlers/authorization_test.js @@ -30,7 +30,7 @@ describe('Unit | Pre-handler | Authorization', function () { it('should reply with true', async function () { // given sessionRepository.doesUserHaveCertificationCenterMembershipForSession - .withArgs(userId, sessionId) + .withArgs({ userId, sessionId }) .resolves(true); // when @@ -45,7 +45,7 @@ describe('Unit | Pre-handler | Authorization', function () { it('should throw a NotFoundError', async function () { // given sessionRepository.doesUserHaveCertificationCenterMembershipForSession - .withArgs(userId, sessionId) + .withArgs({ userId, sessionId }) .resolves(false); // when @@ -70,8 +70,10 @@ describe('Unit | Pre-handler | Authorization', function () { id: 77, }, }; - certificationCourseRepository.getSessionId.withArgs(77).resolves(99); - sessionRepository.doesUserHaveCertificationCenterMembershipForSession.withArgs(userId, 99).resolves(true); + certificationCourseRepository.getSessionId.withArgs({ id: 77 }).resolves(99); + sessionRepository.doesUserHaveCertificationCenterMembershipForSession + .withArgs({ userId, sessionId: 99 }) + .resolves(true); // when const response = await verifyCertificationSessionAuthorization(request, hFake, dependencies); @@ -92,8 +94,10 @@ describe('Unit | Pre-handler | Authorization', function () { id: 77, }, }; - certificationCourseRepository.getSessionId.withArgs(77).resolves(99); - sessionRepository.doesUserHaveCertificationCenterMembershipForSession.withArgs(userId, 99).resolves(false); + certificationCourseRepository.getSessionId.withArgs({ id: 77 }).resolves(99); + sessionRepository.doesUserHaveCertificationCenterMembershipForSession + .withArgs({ userId, sessionId: 99 }) + .resolves(false); // when const error = await catchErr(verifyCertificationSessionAuthorization)(request, hFake, dependencies); diff --git a/api/tests/unit/application/usecases/checkUserIsMemberOfCertificationCenterSession_test.js b/api/tests/unit/application/usecases/checkUserIsMemberOfCertificationCenterSession_test.js index 0c1032ab32b..6de93c7a5c5 100644 --- a/api/tests/unit/application/usecases/checkUserIsMemberOfCertificationCenterSession_test.js +++ b/api/tests/unit/application/usecases/checkUserIsMemberOfCertificationCenterSession_test.js @@ -24,9 +24,9 @@ describe('Unit | Application | Use Case | CheckUserIsMemberOfCertificationCenter getSessionId: () => sessionId, }; - certificationCourseRepositoryStub.get.withArgs(certificationCourseId).resolves(certificationCourse); + certificationCourseRepositoryStub.get.withArgs({ id: certificationCourseId }).resolves(certificationCourse); sessionRepositoryStub.doesUserHaveCertificationCenterMembershipForSession - .withArgs(userId, sessionId) + .withArgs({ userId, sessionId }) .resolves(true); // when diff --git a/api/tests/unit/application/usecases/checkUserOwnsCertificationCourse_test.js b/api/tests/unit/application/usecases/checkUserOwnsCertificationCourse_test.js index 05b44a3e9b3..767519be9de 100644 --- a/api/tests/unit/application/usecases/checkUserOwnsCertificationCourse_test.js +++ b/api/tests/unit/application/usecases/checkUserOwnsCertificationCourse_test.js @@ -16,7 +16,9 @@ describe('Unit | Application | Use Case | checkUserOwnsCertificationCourse', fun get: sinon.stub(), }; - certificationCourseRepositoryStub.get.withArgs(certificationCourseId).resolves(certificationCourseBookshelfStub); + certificationCourseRepositoryStub.get + .withArgs({ id: certificationCourseId }) + .resolves(certificationCourseBookshelfStub); // when const response = await usecase.execute({ diff --git a/api/tests/unit/domain/events/handle-auto-jury_test.js b/api/tests/unit/domain/events/handle-auto-jury_test.js index 575262a8d3a..77df1df734d 100644 --- a/api/tests/unit/domain/events/handle-auto-jury_test.js +++ b/api/tests/unit/domain/events/handle-auto-jury_test.js @@ -2,8 +2,8 @@ import { AutoJuryDone } from '../../../../lib/domain/events/AutoJuryDone.js'; import { CertificationJuryDone } from '../../../../lib/domain/events/CertificationJuryDone.js'; import { handleAutoJury } from '../../../../lib/domain/events/handle-auto-jury.js'; import { SessionFinalized } from '../../../../lib/domain/events/SessionFinalized.js'; -import { ABORT_REASONS } from '../../../../lib/domain/models/CertificationCourse.js'; import { CertificationAssessment } from '../../../../lib/domain/models/index.js'; +import { ABORT_REASONS } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { CertificationIssueReportCategory, CertificationIssueReportSubcategories, @@ -66,7 +66,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) + .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves([certificationIssueReport, certificationIssueReport2]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) @@ -122,7 +122,9 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { certificationCourseRepository.findCertificationCoursesBySessionId .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); - certificationIssueReportRepository.findByCertificationCourseId.withArgs(certificationCourse.getId()).resolves([]); + certificationIssueReportRepository.findByCertificationCourseId + .withArgs({ certificationCourseId: certificationCourse.getId() }) + .resolves([]); const event = new SessionFinalized({ sessionId: 1234, @@ -181,7 +183,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) + .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves([certificationIssueReport1]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) @@ -230,7 +232,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) + .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves([]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) @@ -292,7 +294,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) + .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves([]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) @@ -360,7 +362,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) + .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves([]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) @@ -431,9 +433,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { certificationCourseRepository.findCertificationCoursesBySessionId .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); - certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) - .resolves([]); + certificationIssueReportRepository.findByCertificationCourseId.resolves([]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves(certificationAssessment); @@ -509,7 +509,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) + .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves([]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) @@ -566,7 +566,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) + .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves([]); const event = new SessionFinalized({ sessionId: 1234, @@ -618,7 +618,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) + .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves([certificationIssueReport1]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) @@ -694,7 +694,7 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); certificationIssueReportRepository.findByCertificationCourseId - .withArgs(certificationCourse.getId()) + .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves([certificationIssueReport, certificationIssueReport2]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) @@ -774,7 +774,9 @@ describe('Unit | Domain | Events | handle-auto-jury', function () { certificationCourseRepository.findCertificationCoursesBySessionId .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); - certificationIssueReportRepository.findByCertificationCourseId.withArgs(certificationCourse.getId()).resolves([]); + certificationIssueReportRepository.findByCertificationCourseId + .withArgs({ certificationCourseId: certificationCourse.getId() }) + .resolves([]); const event = new SessionFinalized({ sessionId: 1234, @@ -1155,7 +1157,9 @@ function _initializeV3CourseAndAssessment({ certificationCourseRepository.findCertificationCoursesBySessionId .withArgs({ sessionId: 1234 }) .resolves([certificationCourse]); - certificationIssueReportRepository.findByCertificationCourseId.withArgs(certificationCourse.getId()).resolves([]); + certificationIssueReportRepository.findByCertificationCourseId + .withArgs({ certificationCourseId: certificationCourse.getId() }) + .resolves([]); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves(certificationAssessment); 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 f6ce12be9f3..403ed78fe5f 100644 --- a/api/tests/unit/domain/events/handle-certification-rescoring_test.js +++ b/api/tests/unit/domain/events/handle-certification-rescoring_test.js @@ -5,11 +5,11 @@ import { CertificationJuryDone } from '../../../../lib/domain/events/Certificati import { ChallengeDeneutralized } from '../../../../lib/domain/events/ChallengeDeneutralized.js'; import { ChallengeNeutralized } from '../../../../lib/domain/events/ChallengeNeutralized.js'; import { _forTestOnly } from '../../../../lib/domain/events/index.js'; -import { ABORT_REASONS } from '../../../../lib/domain/models/CertificationCourse.js'; import { AssessmentResult, CertificationAssessment, CertificationResult } from '../../../../lib/domain/models/index.js'; +import { ABORT_REASONS } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; +import { CertificationVersion } from '../../../../src/certification/shared/domain/models/CertificationVersion.js'; import { AutoJuryCommentKeys } from '../../../../src/certification/shared/domain/models/JuryComment.js'; import { config } from '../../../../src/shared/config.js'; -import { CertificationVersion } from '../../../../src/shared/domain/models/CertificationVersion.js'; import { generateAnswersForChallenges, generateChallengeList, @@ -146,7 +146,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () answerRepository.findByAssessment.withArgs(certificationAssessment.id).resolves(answers); certificationCourseRepository.get - .withArgs(certificationAssessment.certificationCourseId) + .withArgs({ id: certificationAssessment.certificationCourseId }) .resolves(abortedCertificationCourse); flashAlgorithmService.getEstimatedLevelAndErrorRate @@ -264,7 +264,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () answerRepository.findByAssessment.withArgs(certificationAssessment.id).resolves(answers); certificationCourseRepository.get - .withArgs(certificationAssessment.certificationCourseId) + .withArgs({ id: certificationAssessment.certificationCourseId }) .resolves(abortedCertificationCourse); flashAlgorithmService.getEstimatedLevelAndErrorRate @@ -332,7 +332,9 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () expect(assessmentResultRepository.save).to.have.been.calledWith(expectedResult); expect(certificationCourseRepository.update).to.have.been.calledOnce; - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(expectedCertificationCourse); + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: expectedCertificationCourse, + }); const expectedEvent = domainBuilder.buildCertificationRescoringCompletedEvent({ certificationCourseId, @@ -394,7 +396,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () answerRepository.findByAssessment.withArgs(certificationAssessment.id).resolves(answers); certificationCourseRepository.get - .withArgs(certificationAssessment.certificationCourseId) + .withArgs({ id: certificationAssessment.certificationCourseId }) .resolves(abortedCertificationCourse); flashAlgorithmConfigurationRepository.getMostRecentBeforeDate @@ -517,7 +519,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () answerRepository.findByAssessment.withArgs(certificationAssessment.id).resolves(answers); certificationCourseRepository.get - .withArgs(certificationAssessment.certificationCourseId) + .withArgs({ id: certificationAssessment.certificationCourseId }) .resolves(abortedCertificationCourse); flashAlgorithmService.getEstimatedLevelAndErrorRate @@ -645,7 +647,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () answerRepository.findByAssessment.withArgs(certificationAssessment.id).resolves(answers); certificationCourseRepository.get - .withArgs(certificationAssessment.certificationCourseId) + .withArgs({ id: certificationAssessment.certificationCourseId }) .resolves(abortedCertificationCourse); flashAlgorithmService.getEstimatedLevelAndErrorRate @@ -760,7 +762,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () answerRepository.findByAssessment.withArgs(certificationAssessment.id).resolves(answers); certificationCourseRepository.get - .withArgs(certificationAssessment.certificationCourseId) + .withArgs({ id: certificationAssessment.certificationCourseId }) .resolves(abortedCertificationCourse); flashAlgorithmService.getEstimatedLevelAndErrorRate @@ -859,7 +861,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: certificationCourse.getId() }) .resolves(certificationAssessment); - certificationCourseRepository.get.withArgs(certificationCourse.getId()).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: certificationCourse.getId() }).resolves(certificationCourse); const competenceMark2 = domainBuilder.buildCompetenceMark({ score: 5 }); const competenceMark1 = domainBuilder.buildCompetenceMark({ score: 4 }); @@ -911,7 +913,9 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () competenceMark2.assessmentResultId = savedAssessmentResult.id; expect(competenceMarkRepository.save).to.have.been.calledWithExactly(competenceMark1); expect(competenceMarkRepository.save).to.have.been.calledWithExactly(competenceMark2); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(expectedSaveCertificationCourse); + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: expectedSaveCertificationCourse, + }); }); context('when the certification has not enough non neutralized challenges to be trusted', function () { @@ -945,7 +949,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: 789 }) .resolves(certificationAssessment); - certificationCourseRepository.get.withArgs(789).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: 789 }).resolves(certificationCourse); const competenceMark2 = domainBuilder.buildCompetenceMark({ score: 12 }); const competenceMark1 = domainBuilder.buildCompetenceMark({ score: 18 }); const certificationAssessmentScore = domainBuilder.buildCertificationAssessmentScore({ @@ -995,7 +999,9 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () certificationCourseId: 789, assessmentResult: assessmentResultToBeSaved, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(expectedCertificationCourse); + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: expectedCertificationCourse, + }); }); }); @@ -1030,7 +1036,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: 789 }) .resolves(certificationAssessment); - certificationCourseRepository.get.withArgs(789).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: 789 }).resolves(certificationCourse); const competenceMark2 = domainBuilder.buildCompetenceMark({ score: 12 }); const competenceMark1 = domainBuilder.buildCompetenceMark({ score: 18 }); const certificationAssessmentScore = domainBuilder.buildCertificationAssessmentScore({ @@ -1078,7 +1084,9 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () certificationCourseId: 789, assessmentResult: assessmentResultToBeSaved, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(expectedCertificationCourse); + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: expectedCertificationCourse, + }); }); }); @@ -1117,7 +1125,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: 789 }) .resolves(certificationAssessment); - certificationCourseRepository.get.withArgs(789).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: 789 }).resolves(certificationCourse); const competenceMark2 = domainBuilder.buildCompetenceMark({ score: 12 }); const competenceMark1 = domainBuilder.buildCompetenceMark({ score: 18 }); const certificationAssessmentScore = domainBuilder.buildCertificationAssessmentScore({ @@ -1165,7 +1173,9 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () certificationCourseId: 789, assessmentResult: assessmentResultToBeSaved, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(expectedCertificationCourse); + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: expectedCertificationCourse, + }); }); }); @@ -1203,7 +1213,7 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: 789 }) .resolves(certificationAssessment); - certificationCourseRepository.get.withArgs(789).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: 789 }).resolves(certificationCourse); const competenceMark1 = domainBuilder.buildCompetenceMark({ score: 0 }); const competenceMark2 = domainBuilder.buildCompetenceMark({ score: 0 }); const competenceMark3 = domainBuilder.buildCompetenceMark({ score: 0 }); @@ -1253,234 +1263,239 @@ describe('Unit | Domain | Events | handle-certification-rescoring', function () certificationCourseId: 789, assessmentResult: assessmentResultToBeSaved, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(expectedCertificationCourse); + + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: expectedCertificationCourse, + }); }); }); - }); - it('returns a CertificationRescoringCompleted event', async function () { - // given - const certificationCourseRepository = { - get: sinon.stub(), - update: sinon.stub(), - }; - const assessmentResultRepository = { save: sinon.stub() }; - const certificationAssessmentRepository = { getByCertificationCourseId: sinon.stub() }; - const competenceMarkRepository = { save: sinon.stub() }; - const scoringCertificationService = { calculateCertificationAssessmentScore: sinon.stub() }; - const certificationCourse = domainBuilder.buildCertificationCourse(); + it('returns a CertificationRescoringCompleted event', async function () { + // given + const certificationCourseRepository = { + get: sinon.stub(), + update: sinon.stub(), + }; + const assessmentResultRepository = { save: sinon.stub() }; + const certificationAssessmentRepository = { getByCertificationCourseId: sinon.stub() }; + const competenceMarkRepository = { save: sinon.stub() }; + const scoringCertificationService = { calculateCertificationAssessmentScore: sinon.stub() }; + const certificationCourse = domainBuilder.buildCertificationCourse(); - const event = new ChallengeNeutralized({ certificationCourseId: certificationCourse.getId(), juryId: 7 }); - const certificationAssessment = domainBuilder.buildCertificationAssessment({ - userId: 123, - certificationCourseId: certificationCourse.getId(), - }); - certificationAssessmentRepository.getByCertificationCourseId - .withArgs({ certificationCourseId: certificationCourse.getId() }) - .resolves(certificationAssessment); - certificationCourseRepository.get.withArgs(certificationCourse.getId()).resolves(certificationCourse); + const event = new ChallengeNeutralized({ certificationCourseId: certificationCourse.getId(), juryId: 7 }); + const certificationAssessment = domainBuilder.buildCertificationAssessment({ + userId: 123, + certificationCourseId: certificationCourse.getId(), + }); + certificationAssessmentRepository.getByCertificationCourseId + .withArgs({ certificationCourseId: certificationCourse.getId() }) + .resolves(certificationAssessment); + certificationCourseRepository.get.withArgs({ id: certificationCourse.getId() }).resolves(certificationCourse); - const certificationAssessmentScore = domainBuilder.buildCertificationAssessmentScore({ - competenceMarks: [], - percentageCorrectAnswers: 80, - hasEnoughNonNeutralizedChallengesToBeTrusted: true, - }); - scoringCertificationService.calculateCertificationAssessmentScore - .withArgs({ certificationAssessment, continueOnError: false }) - .resolves(certificationAssessmentScore); - assessmentResultRepository.save.resolves(domainBuilder.buildAssessmentResult()); + const certificationAssessmentScore = domainBuilder.buildCertificationAssessmentScore({ + competenceMarks: [], + percentageCorrectAnswers: 80, + hasEnoughNonNeutralizedChallengesToBeTrusted: true, + }); + scoringCertificationService.calculateCertificationAssessmentScore + .withArgs({ certificationAssessment, continueOnError: false }) + .resolves(certificationAssessmentScore); + assessmentResultRepository.save.resolves(domainBuilder.buildAssessmentResult()); - const dependendencies = { - assessmentResultRepository, - certificationAssessmentRepository, - competenceMarkRepository, - scoringCertificationService, - certificationCourseRepository, - }; + const dependendencies = { + assessmentResultRepository, + certificationAssessmentRepository, + competenceMarkRepository, + scoringCertificationService, + certificationCourseRepository, + }; - // when - const returnedEvent = await handleCertificationRescoring({ - ...dependendencies, - event, - }); + // when + const returnedEvent = await handleCertificationRescoring({ + ...dependendencies, + event, + }); - // then - const expectedReturnedEvent = domainBuilder.buildCertificationRescoringCompletedEvent({ - certificationCourseId: certificationCourse.getId(), - userId: 123, - reproducibilityRate: 80, + // then + const expectedReturnedEvent = domainBuilder.buildCertificationRescoringCompletedEvent({ + certificationCourseId: certificationCourse.getId(), + userId: 123, + reproducibilityRate: 80, + }); + expect(returnedEvent).to.deep.equal(expectedReturnedEvent); }); - expect(returnedEvent).to.deep.equal(expectedReturnedEvent); - }); - it('computes and persists the assessment result in error when computation fails', async function () { - // given - const assessmentResultRepository = { save: sinon.stub() }; - const certificationAssessmentRepository = { getByCertificationCourseId: sinon.stub() }; - const competenceMarkRepository = { save: sinon.stub() }; - const scoringCertificationService = { calculateCertificationAssessmentScore: sinon.stub() }; + it('computes and persists the assessment result in error when computation fails', async function () { + // given + const assessmentResultRepository = { save: sinon.stub() }; + const certificationAssessmentRepository = { getByCertificationCourseId: sinon.stub() }; + const competenceMarkRepository = { save: sinon.stub() }; + const scoringCertificationService = { calculateCertificationAssessmentScore: sinon.stub() }; - 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: 2, - certificationChallenges: [ - domainBuilder.buildCertificationChallengeWithType({ isNeutralized: false }), - domainBuilder.buildCertificationChallengeWithType({ isNeutralized: false }), - ], - certificationAnswersByDate: ['answer'], - }); - certificationAssessmentRepository.getByCertificationCourseId - .withArgs({ certificationCourseId: 1 }) - .resolves(certificationAssessment); + 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: 2, + certificationChallenges: [ + domainBuilder.buildCertificationChallengeWithType({ isNeutralized: false }), + domainBuilder.buildCertificationChallengeWithType({ isNeutralized: false }), + ], + certificationAnswersByDate: ['answer'], + }); + certificationAssessmentRepository.getByCertificationCourseId + .withArgs({ certificationCourseId: 1 }) + .resolves(certificationAssessment); - scoringCertificationService.calculateCertificationAssessmentScore - .withArgs({ certificationAssessment, continueOnError: false }) - .rejects(new CertificationComputeError('Oopsie')); + scoringCertificationService.calculateCertificationAssessmentScore + .withArgs({ certificationAssessment, continueOnError: false }) + .rejects(new CertificationComputeError('Oopsie')); + + const assessmentResultToBeSaved = new AssessmentResult({ + id: undefined, + emitter: CERTIFICATION_RESULT_EMITTER_NEUTRALIZATION, + commentByJury: 'Oopsie', + pixScore: 0, + reproducibilityRate: 0, + status: AssessmentResult.status.ERROR, + assessmentId: 123, + juryId: 7, + }); + const savedAssessmentResult = new AssessmentResult({ ...assessmentResultToBeSaved, id: 4 }); + assessmentResultRepository.save + .withArgs({ + certificationCourseId: 123, + assessmentResult: assessmentResultToBeSaved, + }) + .resolves(savedAssessmentResult); - const assessmentResultToBeSaved = new AssessmentResult({ - id: undefined, - emitter: CERTIFICATION_RESULT_EMITTER_NEUTRALIZATION, - commentByJury: 'Oopsie', - pixScore: 0, - reproducibilityRate: 0, - status: AssessmentResult.status.ERROR, - assessmentId: 123, - juryId: 7, - }); - const savedAssessmentResult = new AssessmentResult({ ...assessmentResultToBeSaved, id: 4 }); - assessmentResultRepository.save - .withArgs({ - certificationCourseId: 123, - assessmentResult: assessmentResultToBeSaved, - }) - .resolves(savedAssessmentResult); + const dependendencies = { + assessmentResultRepository, + certificationAssessmentRepository, + competenceMarkRepository, + scoringCertificationService, + }; - const dependendencies = { - assessmentResultRepository, - certificationAssessmentRepository, - competenceMarkRepository, - scoringCertificationService, - }; + // when + await handleCertificationRescoring({ + ...dependendencies, + event, + }); - // when - await handleCertificationRescoring({ - ...dependendencies, - event, + // then + expect(assessmentResultRepository.save).to.have.been.calledOnce; }); - // then - expect(assessmentResultRepository.save).to.have.been.calledOnce; - }); - - // Rule disabled to allow dynamic generated tests. See https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-setup-in-describe.md#disallow-setup-in-describe-blocks-mochano-setup-in-describe - // eslint-disable-next-line mocha/no-setup-in-describe - [ - { - eventType: CertificationJuryDone, - emitter: CERTIFICATION_RESULT_EMITTER_AUTOJURY, - }, - { - eventType: ChallengeNeutralized, - emitter: CERTIFICATION_RESULT_EMITTER_NEUTRALIZATION, - }, - { - eventType: ChallengeDeneutralized, - emitter: CERTIFICATION_RESULT_EMITTER_NEUTRALIZATION, - }, - { - eventType: CertificationCourseRejected, - emitter: CERTIFICATION_RESULT_EMITTER_FRAUD_REJECTION, - }, - { - eventType: CertificationCourseUnrejected, - emitter: CERTIFICATION_RESULT_EMITTER_FRAUD_REJECTION, - }, - ].forEach(({ eventType, emitter }) => { - context(`when event is of type ${eventType}`, function () { - it(`should save an assessment result with a ${emitter} emitter`, async function () { - // given - const certificationCourseRepository = { - get: sinon.stub(), - update: sinon.stub(), - }; - const assessmentResultRepository = { save: sinon.stub() }; - const certificationAssessmentRepository = { getByCertificationCourseId: sinon.stub() }; - const competenceMarkRepository = { save: sinon.stub() }; - const scoringCertificationService = { calculateCertificationAssessmentScore: sinon.stub() }; - const certificationCourse = domainBuilder.buildCertificationCourse({ - id: 789, - isCancelled: false, - }); - - const event = new eventType({ certificationCourseId: certificationCourse.getId() }); - const certificationAssessment = new CertificationAssessment({ - id: 123, - userId: 123, - certificationCourseId: certificationCourse.getId(), - createdAt: new Date('2020-01-01'), - completedAt: new Date('2020-01-01'), - state: CertificationAssessment.states.STARTED, - version: 2, - certificationChallenges: [ - domainBuilder.buildCertificationChallengeWithType({ isNeutralized: false }), - domainBuilder.buildCertificationChallengeWithType({ isNeutralized: false }), - ], - certificationAnswersByDate: ['answer'], - }); - certificationAssessmentRepository.getByCertificationCourseId - .withArgs({ certificationCourseId: certificationCourse.getId() }) - .resolves(certificationAssessment); - certificationCourseRepository.get.withArgs(certificationCourse.getId()).resolves(certificationCourse); - - const competenceMark2 = domainBuilder.buildCompetenceMark({ score: 5 }); - const competenceMark1 = domainBuilder.buildCompetenceMark({ score: 4 }); - const certificationAssessmentScore = domainBuilder.buildCertificationAssessmentScore({ - nbPix: 9, - status: AssessmentResult.status.VALIDATED, - competenceMarks: [competenceMark1, competenceMark2], - percentageCorrectAnswers: 80, - hasEnoughNonNeutralizedChallengesToBeTrusted: true, - }); - scoringCertificationService.calculateCertificationAssessmentScore - .withArgs({ certificationAssessment, continueOnError: false }) - .resolves(certificationAssessmentScore); - - const assessmentResultToBeSaved = new AssessmentResult({ - id: undefined, - emitter, - pixScore: 9, - reproducibilityRate: 80, - status: AssessmentResult.status.VALIDATED, - assessmentId: 123, - juryId: undefined, - }); - const savedAssessmentResult = new AssessmentResult({ ...assessmentResultToBeSaved, id: 4 }); - assessmentResultRepository.save.resolves(savedAssessmentResult); - - const dependendencies = { - assessmentResultRepository, - certificationAssessmentRepository, - competenceMarkRepository, - scoringCertificationService, - certificationCourseRepository, - }; + // Rule disabled to allow dynamic generated tests. See https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-setup-in-describe.md#disallow-setup-in-describe-blocks-mochano-setup-in-describe + // eslint-disable-next-line mocha/no-setup-in-describe + [ + { + eventType: CertificationJuryDone, + emitter: CERTIFICATION_RESULT_EMITTER_AUTOJURY, + }, + { + eventType: ChallengeNeutralized, + emitter: CERTIFICATION_RESULT_EMITTER_NEUTRALIZATION, + }, + { + eventType: ChallengeDeneutralized, + emitter: CERTIFICATION_RESULT_EMITTER_NEUTRALIZATION, + }, + { + eventType: CertificationCourseRejected, + emitter: CERTIFICATION_RESULT_EMITTER_FRAUD_REJECTION, + }, + { + eventType: CertificationCourseUnrejected, + emitter: CERTIFICATION_RESULT_EMITTER_FRAUD_REJECTION, + }, + ].forEach(({ eventType, emitter }) => { + context(`when event is of type ${eventType}`, function () { + it(`should save an assessment result with a ${emitter} emitter`, async function () { + // given + const certificationCourseRepository = { + get: sinon.stub(), + update: sinon.stub(), + }; + const assessmentResultRepository = { save: sinon.stub() }; + const certificationAssessmentRepository = { getByCertificationCourseId: sinon.stub() }; + const competenceMarkRepository = { save: sinon.stub() }; + const scoringCertificationService = { calculateCertificationAssessmentScore: sinon.stub() }; + const certificationCourse = domainBuilder.buildCertificationCourse({ + id: 789, + isCancelled: false, + }); - // when - await handleCertificationRescoring({ - ...dependendencies, - event, - }); + const event = new eventType({ certificationCourseId: certificationCourse.getId() }); + const certificationAssessment = new CertificationAssessment({ + id: 123, + userId: 123, + certificationCourseId: certificationCourse.getId(), + createdAt: new Date('2020-01-01'), + completedAt: new Date('2020-01-01'), + state: CertificationAssessment.states.STARTED, + version: 2, + certificationChallenges: [ + domainBuilder.buildCertificationChallengeWithType({ isNeutralized: false }), + domainBuilder.buildCertificationChallengeWithType({ isNeutralized: false }), + ], + certificationAnswersByDate: ['answer'], + }); + certificationAssessmentRepository.getByCertificationCourseId + .withArgs({ certificationCourseId: certificationCourse.getId() }) + .resolves(certificationAssessment); + certificationCourseRepository.get + .withArgs({ id: certificationCourse.getId() }) + .resolves(certificationCourse); + + const competenceMark2 = domainBuilder.buildCompetenceMark({ score: 5 }); + const competenceMark1 = domainBuilder.buildCompetenceMark({ score: 4 }); + const certificationAssessmentScore = domainBuilder.buildCertificationAssessmentScore({ + nbPix: 9, + status: AssessmentResult.status.VALIDATED, + competenceMarks: [competenceMark1, competenceMark2], + percentageCorrectAnswers: 80, + hasEnoughNonNeutralizedChallengesToBeTrusted: true, + }); + scoringCertificationService.calculateCertificationAssessmentScore + .withArgs({ certificationAssessment, continueOnError: false }) + .resolves(certificationAssessmentScore); + + const assessmentResultToBeSaved = new AssessmentResult({ + id: undefined, + emitter, + pixScore: 9, + reproducibilityRate: 80, + status: AssessmentResult.status.VALIDATED, + assessmentId: 123, + juryId: undefined, + }); + const savedAssessmentResult = new AssessmentResult({ ...assessmentResultToBeSaved, id: 4 }); + assessmentResultRepository.save.resolves(savedAssessmentResult); + + const dependendencies = { + assessmentResultRepository, + certificationAssessmentRepository, + competenceMarkRepository, + scoringCertificationService, + certificationCourseRepository, + }; + + // when + await handleCertificationRescoring({ + ...dependendencies, + event, + }); - // then - expect(assessmentResultRepository.save).to.have.been.calledWithExactly({ - certificationCourseId: 789, - assessmentResult: assessmentResultToBeSaved, + // then + expect(assessmentResultRepository.save).to.have.been.calledWithExactly({ + certificationCourseId: 789, + assessmentResult: assessmentResultToBeSaved, + }); }); }); }); diff --git a/api/tests/unit/domain/events/handle-certification-scoring_test.js b/api/tests/unit/domain/events/handle-certification-scoring_test.js index 2f9e0079180..9ebf9a511fc 100644 --- a/api/tests/unit/domain/events/handle-certification-scoring_test.js +++ b/api/tests/unit/domain/events/handle-certification-scoring_test.js @@ -2,9 +2,12 @@ import { CertificationComputeError } from '../../../../lib/domain/errors.js'; import { AssessmentCompleted } from '../../../../lib/domain/events/AssessmentCompleted.js'; import { CertificationScoringCompleted } from '../../../../lib/domain/events/CertificationScoringCompleted.js'; import { _forTestOnly } from '../../../../lib/domain/events/index.js'; -import { ABORT_REASONS, CertificationCourse } from '../../../../lib/domain/models/CertificationCourse.js'; import { CertificationChallengeForScoring } from '../../../../src/certification/scoring/domain/models/CertificationChallengeForScoring.js'; import { AssessmentResultFactory } from '../../../../src/certification/scoring/domain/models/factories/AssessmentResultFactory.js'; +import { + ABORT_REASONS, + CertificationCourse, +} from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { AutoJuryCommentKeys } from '../../../../src/certification/shared/domain/models/JuryComment.js'; import { config } from '../../../../src/shared/config.js'; import { AssessmentResult, status } from '../../../../src/shared/domain/models/AssessmentResult.js'; @@ -144,7 +147,7 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { sinon.stub(AssessmentResultFactory, 'buildAlgoErrorResult').returns(errorAssessmentResult); assessmentResultRepository.save.resolves(errorAssessmentResult); certificationCourseRepository.get - .withArgs(certificationAssessment.certificationCourseId) + .withArgs({ id: certificationAssessment.certificationCourseId }) .resolves(certificationCourse); certificationCourseRepository.update.resolves(certificationCourse); }); @@ -188,12 +191,12 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { certificationCourseId: 1234, assessmentResult: errorAssessmentResult, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), completedAt: now, }), - ); + }); }); }); @@ -225,7 +228,7 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { competenceMarkRepository.save.resolves(); scoringCertificationService.calculateCertificationAssessmentScore.resolves(certificationAssessmentScore); certificationCourseRepository.get - .withArgs(certificationAssessment.certificationCourseId) + .withArgs({ id: certificationAssessment.certificationCourseId }) .resolves(certificationCourse); certificationCourseRepository.update.resolves(certificationCourse); }); @@ -254,12 +257,12 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { certificationCourseId: 1234, assessmentResult: expectedAssessmentResult, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), completedAt: now, }), - ); + }); }); it('should return a CertificationScoringCompleted', async function () { @@ -318,7 +321,7 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { competenceMarkRepository.save.resolves(); scoringCertificationService.calculateCertificationAssessmentScore.resolves(certificationAssessmentScore); certificationCourseRepository.get - .withArgs(certificationAssessment.certificationCourseId) + .withArgs({ id: certificationAssessment.certificationCourseId }) .resolves(certificationCourse); certificationCourseRepository.update.resolves(certificationCourse); // when @@ -351,12 +354,12 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { assessmentResult: expectedAssessmentResult, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), completedAt: now, }), - ); + }); }); }); }); @@ -437,7 +440,9 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { .withArgs({ certificationCourseId }) .resolves(challenges); answerRepository.findByAssessment.withArgs(assessmentId).resolves(answers); - certificationCourseRepository.get.withArgs(certificationCourseId).resolves(abortedCertificationCourse); + certificationCourseRepository.get + .withArgs({ id: certificationCourseId }) + .resolves(abortedCertificationCourse); flashAlgorithmService.getEstimatedLevelAndErrorRate .withArgs({ @@ -509,13 +514,13 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { expect(certificationAssessmentHistoryRepository.save).to.have.been.calledWithExactly( certificationAssessmentHistory, ); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), completedAt: now, abortReason: 'candidate', }), - ); + }); }); }); @@ -558,7 +563,9 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { .resolves(challenges); answerRepository.findByAssessment.withArgs(assessmentId).resolves(answers); - certificationCourseRepository.get.withArgs(certificationCourseId).resolves(abortedCertificationCourse); + certificationCourseRepository.get + .withArgs({ id: certificationCourseId }) + .resolves(abortedCertificationCourse); flashAlgorithmService.getEstimatedLevelAndErrorRate .withArgs({ @@ -628,21 +635,21 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { assessmentResult: expectedAssessmentResult, }); - expect(certificationCourseRepository.update.firstCall.args[0]).to.deep.equal( - new CertificationCourse({ + expect(certificationCourseRepository.update.firstCall.args[0]).to.deep.equal({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), isCancelled: true, abortReason, }), - ); + }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), isCancelled: true, abortReason, }), - ); + }); expect(certificationAssessmentHistoryRepository.save).to.have.been.calledWithExactly( certificationAssessmentHistory, @@ -676,7 +683,7 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { .withArgs({ certificationCourseId }) .resolves(challenges); answerRepository.findByAssessment.withArgs(assessmentId).resolves(answers); - certificationCourseRepository.get.withArgs(certificationCourseId).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: certificationCourseId }).resolves(certificationCourse); flashAlgorithmConfigurationRepository.getMostRecentBeforeDate .withArgs(certificationCourseStartDate) .resolves(baseFlashAlgorithmConfiguration); @@ -741,12 +748,12 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { certificationCourseId: 1234, assessmentResult: expectedAssessmentResult, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), completedAt: now, }), - ); + }); expect(competenceMarkRepository.save).to.have.been.calledWithExactly( domainBuilder.buildCompetenceMark({ id: undefined, @@ -787,7 +794,7 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { .withArgs({ certificationCourseId }) .resolves(challenges); answerRepository.findByAssessment.withArgs(assessmentId).resolves(answers); - certificationCourseRepository.get.withArgs(certificationCourseId).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: certificationCourseId }).resolves(certificationCourse); flashAlgorithmConfigurationRepository.getMostRecentBeforeDate .withArgs(certificationCourseStartDate) .resolves(baseFlashAlgorithmConfiguration); @@ -892,7 +899,9 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { .withArgs({ certificationCourseId }) .resolves(challenges); answerRepository.findByAssessment.withArgs(assessmentId).resolves(answers); - certificationCourseRepository.get.withArgs(certificationCourseId).resolves(abortedCertificationCourse); + certificationCourseRepository.get + .withArgs({ id: certificationCourseId }) + .resolves(abortedCertificationCourse); flashAlgorithmConfigurationRepository.getMostRecentBeforeDate .withArgs(certificationCourseStartDate) .resolves(baseFlashAlgorithmConfiguration); @@ -956,13 +965,13 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { certificationCourseId: 1234, assessmentResult: expectedAssessmentResult, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), completedAt: now, abortReason, }), - ); + }); expect(certificationAssessmentHistoryRepository.save).to.have.been.calledWithExactly( certificationAssessmentHistory, ); @@ -1002,7 +1011,9 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { .withArgs({ certificationCourseId }) .resolves(challenges); answerRepository.findByAssessment.withArgs(assessmentId).resolves(answers); - certificationCourseRepository.get.withArgs(certificationCourseId).resolves(abortedCertificationCourse); + certificationCourseRepository.get + .withArgs({ id: certificationCourseId }) + .resolves(abortedCertificationCourse); flashAlgorithmConfigurationRepository.getMostRecentBeforeDate .withArgs(certificationCourseStartDate) .resolves(baseFlashAlgorithmConfiguration); @@ -1065,13 +1076,13 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { certificationCourseId: 1234, assessmentResult: expectedAssessmentResult, }); - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourse.toDTO(), completedAt: now, abortReason, }), - ); + }); expect(certificationAssessmentHistoryRepository.save).to.have.been.calledWithExactly( certificationAssessmentHistory, ); @@ -1105,7 +1116,7 @@ describe('Unit | Domain | Events | handle-certification-scoring', function () { .withArgs({ certificationCourseId }) .resolves(challenges); answerRepository.findByAssessment.withArgs(assessmentId).resolves(answers); - certificationCourseRepository.get.withArgs(certificationCourseId).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: certificationCourseId }).resolves(certificationCourse); flashAlgorithmConfigurationRepository.getMostRecentBeforeDate .withArgs(certificationCourseStartDate) .resolves(baseFlashAlgorithmConfiguration); diff --git a/api/tests/unit/domain/events/handle-complementary-certifications-scoring_test.js b/api/tests/unit/domain/events/handle-complementary-certifications-scoring_test.js index 0fa73c3cc60..aa2242dbd9f 100644 --- a/api/tests/unit/domain/events/handle-complementary-certifications-scoring_test.js +++ b/api/tests/unit/domain/events/handle-complementary-certifications-scoring_test.js @@ -59,7 +59,7 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', complementaryCertificationScoringCriteriaRepository.findByCertificationCourseId .withArgs({ certificationCourseId: 123 }) .resolves([]); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(domainBuilder.buildCertificationCourse()); // when await handleComplementaryCertificationsScoring({ event, ...dependencies }); @@ -113,7 +113,7 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', .withArgs({ certificationCourseId: 123 }) .resolves(domainBuilder.buildAssessmentResult()); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(domainBuilder.buildCertificationCourse()); // when await handleComplementaryCertificationsScoring({ event, ...dependencies }); @@ -409,7 +409,9 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', }), ); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get + .withArgs({ id: 123 }) + .resolves(domainBuilder.buildCertificationCourse()); // when await handleComplementaryCertificationsScoring({ event, ...dependencies }); @@ -455,7 +457,7 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', assessmentResultRepository.getByCertificationCourseId .withArgs({ certificationCourseId: 123 }) .resolves(domainBuilder.buildAssessmentResult.rejected()); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(domainBuilder.buildCertificationCourse()); const complementaryCertificationScoringCriteria = [ domainBuilder.buildComplementaryCertificationScoringCriteria({ complementaryCertificationCourseId: 999, @@ -511,7 +513,9 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', certificationChallenges: [certificationChallenge1, certificationChallenge2], certificationAnswersByDate: [certificationAnswer1, certificationAnswer2], }); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get + .withArgs({ id: 123 }) + .resolves(domainBuilder.buildCertificationCourse()); complementaryCertificationScoringCriteriaRepository.findByCertificationCourseId .withArgs({ @@ -588,7 +592,9 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', hasComplementaryReferential: true, }), ]); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get + .withArgs({ id: 123 }) + .resolves(domainBuilder.buildCertificationCourse()); certificationAssessmentRepository.getByCertificationCourseId .withArgs({ certificationCourseId: 123 }) @@ -671,7 +677,9 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', complementaryCertificationId: 123, }), ]); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get + .withArgs({ id: 123 }) + .resolves(domainBuilder.buildCertificationCourse()); complementaryCertificationBadgesRepository.getAllWithSameTargetProfile.withArgs(888).resolves([ domainBuilder.certification.complementary.buildComplementaryCertificationBadge({ @@ -758,7 +766,9 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', complementaryCertificationId: 123, }), ]); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get + .withArgs({ id: 123 }) + .resolves(domainBuilder.buildCertificationCourse()); complementaryCertificationBadgesRepository.getAllWithSameTargetProfile.withArgs(888).resolves([ domainBuilder.certification.complementary.buildComplementaryCertificationBadge({ @@ -844,7 +854,9 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', complementaryCertificationId: 123, }), ]); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get + .withArgs({ id: 123 }) + .resolves(domainBuilder.buildCertificationCourse()); complementaryCertificationBadgesRepository.getAllWithSameTargetProfile.withArgs(888).resolves([ domainBuilder.certification.complementary.buildComplementaryCertificationBadge({ @@ -929,7 +941,7 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', assessmentResultRepository.getByCertificationCourseId .withArgs({ certificationCourseId: 123 }) .resolves(domainBuilder.buildAssessmentResult({ pixScore: 128, reproducibilityRate: 100 })); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(domainBuilder.buildCertificationCourse()); // when await handleComplementaryCertificationsScoring({ event, ...dependencies }); @@ -989,7 +1001,7 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', certificationCourseId: 123, }) .resolves(complementaryCertificationScoringCriteria); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(domainBuilder.buildCertificationCourse()); // when await handleComplementaryCertificationsScoring({ event, ...dependencies }); @@ -1052,7 +1064,7 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', reproducibilityRate: 70, }), ); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(domainBuilder.buildCertificationCourse()); // when await handleComplementaryCertificationsScoring({ event, ...dependencies }); @@ -1115,7 +1127,7 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', reproducibilityRate: 75, }), ); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(domainBuilder.buildCertificationCourse()); // when await handleComplementaryCertificationsScoring({ event, ...dependencies }); @@ -1178,7 +1190,7 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', reproducibilityRate: 75, }), ); - certificationCourseRepository.get.withArgs(123).resolves(domainBuilder.buildCertificationCourse()); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(domainBuilder.buildCertificationCourse()); // when await handleComplementaryCertificationsScoring({ event, ...dependencies }); @@ -1242,7 +1254,7 @@ describe('Unit | Domain | Events | Handle Complementary Certifications Scoring', }), ); certificationCourseRepository.get - .withArgs(123) + .withArgs({ id: 123 }) .resolves(domainBuilder.buildCertificationCourse({ isRejectedForFraud: true })); // when diff --git a/api/tests/unit/domain/events/handle-session-finalized_test.js b/api/tests/unit/domain/events/handle-session-finalized_test.js index 92393f2450e..1a288d0b6c4 100644 --- a/api/tests/unit/domain/events/handle-session-finalized_test.js +++ b/api/tests/unit/domain/events/handle-session-finalized_test.js @@ -76,8 +76,8 @@ describe('Unit | Domain | Events | handle-session-finalized', function () { hasSupervisorAccess: true, juryCertificationSummaries: [juryCertificationSummary], }); - expect(finalizedSessionRepository.save).to.have.been.calledWithExactly( - new FinalizedSession({ + expect(finalizedSessionRepository.save).to.have.been.calledWithExactly({ + finalizedSession: new FinalizedSession({ sessionId: event.sessionId, finalizedAt: event.finalizedAt, certificationCenterName: event.certificationCenterName, @@ -87,6 +87,6 @@ describe('Unit | Domain | Events | handle-session-finalized', function () { hasSupervisorAccess: true, publishedAt: null, }), - ); + }); }); }); diff --git a/api/tests/unit/domain/models/CertificationIssueReportResolutionStrategies_test.js b/api/tests/unit/domain/models/CertificationIssueReportResolutionStrategies_test.js index f27958f1d02..64a4cc9b321 100644 --- a/api/tests/unit/domain/models/CertificationIssueReportResolutionStrategies_test.js +++ b/api/tests/unit/domain/models/CertificationIssueReportResolutionStrategies_test.js @@ -90,7 +90,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -151,7 +153,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); }); @@ -226,7 +230,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -298,7 +304,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); }); @@ -356,7 +364,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -431,7 +441,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -502,7 +514,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); }); @@ -582,7 +596,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -639,7 +655,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -708,7 +726,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -783,7 +803,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); }); @@ -863,7 +885,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -920,7 +944,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -989,7 +1015,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -1064,7 +1092,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); }); @@ -1148,7 +1178,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; expect(certificationIssueReport.resolution).to.equal('Cette question a été neutralisée automatiquement'); - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -1229,7 +1261,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; expect(certificationIssueReport.resolution).to.equal('Cette réponse a été acceptée automatiquement'); - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); }); @@ -1288,7 +1322,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' // then expect(certificationIssueReport.isResolved()).to.be.true; expect(certificationIssueReport.resolution).to.equal(`Aucune question ne correspond au numéro 1`); - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); @@ -1360,7 +1396,9 @@ describe('Unit | Domain | Models | CertificationIssueReportResolutionStrategies' expect(certificationIssueReport.resolution).to.equal( "Cette question n'a pas été neutralisée car ce n'est pas une question focus", ); - expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly(certificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledOnceWithExactly({ + certificationIssueReport, + }); }); }); }); diff --git a/api/tests/unit/domain/services/session-publication-service_test.js b/api/tests/unit/domain/services/session-publication-service_test.js index fcaf5bfca46..e8ab004b832 100644 --- a/api/tests/unit/domain/services/session-publication-service_test.js +++ b/api/tests/unit/domain/services/session-publication-service_test.js @@ -77,7 +77,7 @@ describe('Unit | UseCase | session-publication-service', function () { get: sinon.stub(), save: sinon.stub(), }; - sessionRepository.getWithCertificationCandidates.withArgs(sessionId).resolves(originalSession); + sessionRepository.getWithCertificationCandidates.withArgs({ id: sessionId }).resolves(originalSession); }); context('when the session is already published', function () { @@ -85,7 +85,7 @@ describe('Unit | UseCase | session-publication-service', function () { // given const session = domainBuilder.buildSession({ id: 'sessionId', publishedAt: new Date() }); const sessionRepository = { getWithCertificationCandidates: sinon.stub() }; - sessionRepository.getWithCertificationCandidates.withArgs('sessionId').resolves(session); + sessionRepository.getWithCertificationCandidates.withArgs({ id: 'sessionId' }).resolves(session); // when const error = await catchErr(publishSession)({ @@ -128,7 +128,7 @@ describe('Unit | UseCase | session-publication-service', function () { // then expect(finalizedSession.publishedAt).to.equal(now); - expect(finalizedSessionRepository.save).to.have.been.calledWithExactly(finalizedSession); + expect(finalizedSessionRepository.save).to.have.been.calledWithExactly({ finalizedSession }); expect(certificationRepository.publishCertificationCourses).to.have.been.calledWithExactly( certificationStatuses, ); @@ -141,7 +141,7 @@ describe('Unit | UseCase | session-publication-service', function () { // given const session = domainBuilder.buildSession({ id: 'sessionId', publishedAt: null }); const sessionRepository = { getWithCertificationCandidates: sinon.stub() }; - sessionRepository.getWithCertificationCandidates.withArgs('sessionId').resolves(session); + sessionRepository.getWithCertificationCandidates.withArgs({ id: 'sessionId' }).resolves(session); certificationRepository.getStatusesBySessionId .withArgs('sessionId') .resolves([{ pixCertificationStatus: status.ERROR }]); @@ -169,7 +169,7 @@ describe('Unit | UseCase | session-publication-service', function () { get: sinon.stub(), save: sinon.stub(), }; - sessionRepository.getWithCertificationCandidates.withArgs('sessionId').resolves(session); + sessionRepository.getWithCertificationCandidates.withArgs({ id: 'sessionId' }).resolves(session); certificationRepository.getStatusesBySessionId .withArgs('sessionId') .resolves([{ pixCertificationStatus: status.ERROR, isCancelled: true }]); @@ -195,7 +195,7 @@ describe('Unit | UseCase | session-publication-service', function () { // given const session = domainBuilder.buildSession({ id: 'sessionId', publishedAt: null }); const sessionRepository = { getWithCertificationCandidates: sinon.stub() }; - sessionRepository.getWithCertificationCandidates.withArgs('sessionId').resolves(session); + sessionRepository.getWithCertificationCandidates.withArgs({ id: 'sessionId' }).resolves(session); certificationRepository.getStatusesBySessionId .withArgs('sessionId') .resolves([{ pixCertificationStatus: null }]); @@ -218,7 +218,7 @@ describe('Unit | UseCase | session-publication-service', function () { // given const session = domainBuilder.buildSession({ id: 'sessionId', publishedAt: null }); const sessionRepository = { getWithCertificationCandidates: sinon.stub(), updatePublishedAt: sinon.stub() }; - sessionRepository.getWithCertificationCandidates.withArgs('sessionId').resolves(session); + sessionRepository.getWithCertificationCandidates.withArgs({ id: 'sessionId' }).resolves(session); certificationRepository.getStatusesBySessionId .withArgs('sessionId') .resolves([{ pixCertificationStatus: null, isCancelled: true }]); @@ -416,9 +416,9 @@ describe('Unit | UseCase | session-publication-service', function () { mailService.sendCertificationResultEmail.onCall(0).resolves(EmailingAttempt.success(recipient1)); mailService.sendCertificationResultEmail.onCall(1).resolves(EmailingAttempt.success(recipient2)); - sessionRepository.hasSomeCleaAcquired.withArgs(session.id).resolves(true); + sessionRepository.hasSomeCleaAcquired.withArgs({ id: session.id }).resolves(true); certificationCenterRepository.getRefererEmails - .withArgs(session.certificationCenterId) + .withArgs({ id: session.certificationCenterId }) .resolves([{ email: user.email }]); // when @@ -461,9 +461,9 @@ describe('Unit | UseCase | session-publication-service', function () { mailService.sendCertificationResultEmail.onCall(0).resolves(EmailingAttempt.success(recipient1)); mailService.sendCertificationResultEmail.onCall(1).resolves(EmailingAttempt.success(recipient2)); - sessionRepository.hasSomeCleaAcquired.withArgs(session.id).resolves(true); + sessionRepository.hasSomeCleaAcquired.withArgs({ id: session.id }).resolves(true); certificationCenterRepository.getRefererEmails - .withArgs(session.certificationCenterId) + .withArgs({ id: session.certificationCenterId }) .resolves([{ email: user.email }]); // when @@ -488,8 +488,10 @@ describe('Unit | UseCase | session-publication-service', function () { it('should send result emails', async function () { // given mailService.sendCertificationResultEmail.resolves(EmailingAttempt.success(recipient1)); - sessionRepository.hasSomeCleaAcquired.withArgs(originalSession.id).resolves(true); - certificationCenterRepository.getRefererEmails.withArgs(originalSession.certificationCenterId).resolves([]); + sessionRepository.hasSomeCleaAcquired.withArgs({ id: originalSession.id }).resolves(true); + certificationCenterRepository.getRefererEmails + .withArgs({ id: originalSession.certificationCenterId }) + .resolves([]); // when await manageEmails({ diff --git a/api/tests/unit/domain/usecases/assign-certification-officer-to-session_test.js b/api/tests/unit/domain/usecases/assign-certification-officer-to-jury-session_test.js similarity index 79% rename from api/tests/unit/domain/usecases/assign-certification-officer-to-session_test.js rename to api/tests/unit/domain/usecases/assign-certification-officer-to-jury-session_test.js index 45c5e647bde..7889875d1b0 100644 --- a/api/tests/unit/domain/usecases/assign-certification-officer-to-session_test.js +++ b/api/tests/unit/domain/usecases/assign-certification-officer-to-jury-session_test.js @@ -7,24 +7,27 @@ describe('Unit | UseCase | assign-certification-officer-to-session', function () const returnedSessionId = Symbol('returnedSessionId'); const sessionId = 1; const certificationOfficerId = 2; + const finalizedSession = domainBuilder.buildFinalizedSession(); const jurySessionRepository = { assignCertificationOfficer: sinon.stub(), + get: sinon.stub(), }; - jurySessionRepository.assignCertificationOfficer.resolves(returnedSessionId); + jurySessionRepository.assignCertificationOfficer + .withArgs({ id: sessionId, assignedCertificationOfficerId: certificationOfficerId }) + .resolves(); + jurySessionRepository.get.withArgs({ id: finalizedSession.sessionId }).resolves(returnedSessionId); const finalizedSessionRepository = { get: sinon.stub(), save: sinon.stub(), }; - const finalizedSession = domainBuilder.buildFinalizedSession(); - finalizedSessionRepository.get.withArgs({ sessionId }).resolves(finalizedSession); const certificationOfficerRepository = { get: sinon.stub() }; const certificationOfficer = domainBuilder.buildCertificationOfficer(); - certificationOfficerRepository.get.withArgs(2).resolves(certificationOfficer); + certificationOfficerRepository.get.withArgs({ userId: 2 }).resolves(certificationOfficer); // when const actualSessionId = await assignCertificationOfficerToJurySession({ @@ -40,7 +43,7 @@ describe('Unit | UseCase | assign-certification-officer-to-session', function () id: finalizedSession.sessionId, assignedCertificationOfficerId: certificationOfficer.id, }); - expect(finalizedSessionRepository.save).to.have.been.calledWithExactly(finalizedSession); + expect(finalizedSessionRepository.save).to.have.been.calledWithExactly({ finalizedSession }); expect(actualSessionId).to.equal(returnedSessionId); }); }); diff --git a/api/tests/unit/domain/usecases/cancel-certification-course_test.js b/api/tests/unit/domain/usecases/cancel-certification-course_test.js index 9b4d1c529e7..610af59092e 100644 --- a/api/tests/unit/domain/usecases/cancel-certification-course_test.js +++ b/api/tests/unit/domain/usecases/cancel-certification-course_test.js @@ -10,7 +10,7 @@ describe('Unit | UseCase | cancel-certification-course', function () { update: sinon.stub(), get: sinon.stub(), }; - certificationCourseRepository.get.withArgs(123).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(certificationCourse); certificationCourseRepository.update.resolves(); // when @@ -21,6 +21,6 @@ describe('Unit | UseCase | cancel-certification-course', function () { // then expect(certificationCourse.cancel).to.have.been.calledOnce; - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(certificationCourse); + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ certificationCourse }); }); }); diff --git a/api/tests/unit/domain/usecases/correct-candidate-identity-in-certification-course_test.js b/api/tests/unit/domain/usecases/correct-candidate-identity-in-certification-course_test.js index 19ba168f5ff..01872ab3f67 100644 --- a/api/tests/unit/domain/usecases/correct-candidate-identity-in-certification-course_test.js +++ b/api/tests/unit/domain/usecases/correct-candidate-identity-in-certification-course_test.js @@ -1,7 +1,7 @@ import { CertificationCandidatesError } from '../../../../lib/domain/errors.js'; -import { CertificationCourse } from '../../../../lib/domain/models/CertificationCourse.js'; import { correctCandidateIdentityInCertificationCourse } from '../../../../lib/domain/usecases/correct-candidate-identity-in-certification-course.js'; -import { CpfBirthInformationValidation } from '../../../../src/certification/shared/domain/services/certification-cpf-service.js'; +import { CpfBirthInformationValidation } from '../../../../src/certification/session/domain/services/certification-cpf-service.js'; +import { CertificationCourse } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { catchErr, domainBuilder, expect, sinon } from '../../../test-helper.js'; describe('Unit | UseCase | correct-candidate-identity-in-certification-course', function () { @@ -45,7 +45,7 @@ describe('Unit | UseCase | correct-candidate-identity-in-certification-course', const cpfBirthInformationValidation = new CpfBirthInformationValidation(); cpfBirthInformationValidation.success({ birthCountry, birthINSEECode, birthPostalCode, birthCity }); - certificationCourseRepository.get.withArgs(4).resolves(certificationCourseToBeModified); + certificationCourseRepository.get.withArgs({ id: 4 }).resolves(certificationCourseToBeModified); certificationCpfService.getBirthInformation .withArgs({ birthCountry, @@ -79,8 +79,8 @@ describe('Unit | UseCase | correct-candidate-identity-in-certification-course', }); // then - expect(certificationCourseRepository.update).to.have.been.calledWithExactly( - new CertificationCourse({ + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ + certificationCourse: new CertificationCourse({ ...certificationCourseToBeModified.toDTO(), firstName: 'Maurice', lastName: 'Dupont', @@ -91,7 +91,7 @@ describe('Unit | UseCase | correct-candidate-identity-in-certification-course', birthINSEECode: null, birthPostalCode: '75015', }), - ); + }); }); it('should throws a CertificationCandidatesError if birth information validation fails', async function () { @@ -113,7 +113,7 @@ describe('Unit | UseCase | correct-candidate-identity-in-certification-course', birthINSEECode: '99404', }); - certificationCourseRepository.get.withArgs(4).resolves(certificationCourseToBeModified); + certificationCourseRepository.get.withArgs({ id: 4 }).resolves(certificationCourseToBeModified); const certificationCandidateError = { code: '', getMessage: () => 'Failure message' }; const cpfBirthInformationValidation = new CpfBirthInformationValidation(); cpfBirthInformationValidation.failure({ certificationCandidateError }); diff --git a/api/tests/unit/domain/usecases/create-or-update-certification-center-invitation_test.js b/api/tests/unit/domain/usecases/create-or-update-certification-center-invitation_test.js index 6d5832f27c8..61df42e519c 100644 --- a/api/tests/unit/domain/usecases/create-or-update-certification-center-invitation_test.js +++ b/api/tests/unit/domain/usecases/create-or-update-certification-center-invitation_test.js @@ -36,7 +36,7 @@ describe('Unit | Domain | UseCases | CreateOrUpdateCertificationCenterInvitation }); // then - expect(certificationCenterRepository.get).to.have.been.calledWith(certificationCenterId); + expect(certificationCenterRepository.get).to.have.been.calledWith({ id: certificationCenterId }); expect(createOrUpdateCertificationCenterInvitationInjectorStub).to.have.been.calledOnceWithExactly({ certificationCenterInvitationRepository, }); @@ -82,7 +82,7 @@ describe('Unit | Domain | UseCases | CreateOrUpdateCertificationCenterInvitation }); // then - expect(certificationCenterRepository.get).to.have.been.calledWith(certificationCenterId); + expect(certificationCenterRepository.get).to.have.been.calledWith({ id: certificationCenterId }); expect(createOrUpdateCertificationCenterInvitationInjectorStub).to.have.been.callCount(2); expect(createOrUpdateCertificationCenterInvitationStub).to.have.been.callCount(2); }); diff --git a/api/tests/unit/domain/usecases/delete-certification-issue-report_test.js b/api/tests/unit/domain/usecases/delete-certification-issue-report_test.js index f511501fee9..b9412ab5788 100644 --- a/api/tests/unit/domain/usecases/delete-certification-issue-report_test.js +++ b/api/tests/unit/domain/usecases/delete-certification-issue-report_test.js @@ -16,19 +16,21 @@ describe('Unit | UseCase | delete-certification-issue-report', function () { const certificationIssueReport = domainBuilder.buildCertificationIssueReport({ id: certificationIssueReportId }); sinon.stub(certificationCourseRepository, 'getSessionId'); certificationCourseRepository.getSessionId - .withArgs(certificationIssueReport.certificationCourseId) + .withArgs({ id: certificationIssueReport.certificationCourseId }) .resolves(sessionId); certificationIssueReportRepository = { remove: sinon.stub(), get: sinon.stub(), }; - certificationIssueReportRepository.get.withArgs(certificationIssueReportId).resolves(certificationIssueReport); + certificationIssueReportRepository.get + .withArgs({ id: certificationIssueReportId }) + .resolves(certificationIssueReport); sinon.stub(sessionRepository, 'isFinalized'); }); it('should throw a ForbiddenAccess error when session is already finalized', async function () { // given - sessionRepository.isFinalized.withArgs(sessionId).resolves(true); + sessionRepository.isFinalized.withArgs({ id: sessionId }).resolves(true); // when const error = await catchErr(deleteCertificationIssueReport)({ @@ -46,8 +48,8 @@ describe('Unit | UseCase | delete-certification-issue-report', function () { it('should return deletion result', async function () { // given const deletionResult = Symbol('someValue'); - sessionRepository.isFinalized.withArgs(sessionId).resolves(false); - certificationIssueReportRepository.remove.withArgs(certificationIssueReportId).resolves(deletionResult); + sessionRepository.isFinalized.withArgs({ id: sessionId }).resolves(false); + certificationIssueReportRepository.remove.withArgs({ id: certificationIssueReportId }).resolves(deletionResult); // when const actualDeletionResult = await deleteCertificationIssueReport({ diff --git a/api/tests/unit/domain/usecases/enroll-students-to-session_test.js b/api/tests/unit/domain/usecases/enroll-students-to-session_test.js index 2a11dc842ff..04dee3d099a 100644 --- a/api/tests/unit/domain/usecases/enroll-students-to-session_test.js +++ b/api/tests/unit/domain/usecases/enroll-students-to-session_test.js @@ -43,7 +43,7 @@ describe('Unit | UseCase | enrol-students-to-session', function () { countryRepository.findAll.resolves([country]); organizationLearnerRepository.findByIds.withArgs({ ids: studentIds }).resolves(organizationLearners); const sessionRepository = { get: sinon.stub() }; - sessionRepository.get.withArgs(sessionId).resolves(session); + sessionRepository.get.withArgs({ id: sessionId }).resolves(session); const certificationCenterMembershipRepository = { findByUserId: sinon.stub() }; certificationCenterMembershipRepository.findByUserId .withArgs(referentId) @@ -114,7 +114,7 @@ describe('Unit | UseCase | enrol-students-to-session', function () { countryRepository.findAll.resolves([country]); organizationLearnerRepository.findByIds.withArgs({ ids: [1] }).resolves([organizationLearner]); const sessionRepository = { get: sinon.stub() }; - sessionRepository.get.withArgs(sessionId).resolves(session); + sessionRepository.get.withArgs({ id: sessionId }).resolves(session); const certificationCenterMembershipRepository = { findByUserId: sinon.stub() }; certificationCenterMembershipRepository.findByUserId .withArgs(referentId) @@ -156,7 +156,7 @@ describe('Unit | UseCase | enrol-students-to-session', function () { const organizationLearnerRepository = { findByIds: sinon.stub() }; organizationLearnerRepository.findByIds.withArgs({ ids: studentIds }).resolves(organizationLearners); const sessionRepository = { get: sinon.stub() }; - sessionRepository.get.withArgs(session.id).resolves(session); + sessionRepository.get.withArgs({ id: session.id }).resolves(session); const certificationCenterMembershipRepository = { findByUserId: sinon.stub() }; certificationCenterMembershipRepository.findByUserId .withArgs(referentId) @@ -192,7 +192,7 @@ describe('Unit | UseCase | enrol-students-to-session', function () { .withArgs(referentId) .resolves(certificationCenterMemberships); const sessionRepository = { get: sinon.stub() }; - sessionRepository.get.withArgs(session.id).resolves(session); + sessionRepository.get.withArgs({ id: session.id }).resolves(session); // when const error = await catchErr(enrolStudentsToSession)({ @@ -230,7 +230,7 @@ describe('Unit | UseCase | enrol-students-to-session', function () { const countryRepository = { findAll: sinon.stub() }; countryRepository.findAll.resolves([country]); const sessionRepository = { get: sinon.stub() }; - sessionRepository.get.withArgs(sessionId).resolves(session); + sessionRepository.get.withArgs({ id: sessionId }).resolves(session); const certificationCenterMembershipRepository = { findByUserId: sinon.stub() }; certificationCenterMembershipRepository.findByUserId .withArgs(referentId) @@ -277,7 +277,7 @@ describe('Unit | UseCase | enrol-students-to-session', function () { countryRepository.findAll.resolves([country]); organizationLearnerRepository.findByIds.withArgs({ ids: studentIds }).resolves(organizationLearners); const sessionRepository = { get: sinon.stub() }; - sessionRepository.get.withArgs(sessionId).resolves(session); + sessionRepository.get.withArgs({ id: sessionId }).resolves(session); const certificationCenterMembershipRepository = { findByUserId: sinon.stub() }; certificationCenterMembershipRepository.findByUserId .withArgs(referentId) diff --git a/api/tests/unit/domain/usecases/flag-session-results-as-sent-to-prescriber_test.js b/api/tests/unit/domain/usecases/flag-session-results-as-sent-to-prescriber_test.js index d5ef574eaeb..ea1f1749b7a 100644 --- a/api/tests/unit/domain/usecases/flag-session-results-as-sent-to-prescriber_test.js +++ b/api/tests/unit/domain/usecases/flag-session-results-as-sent-to-prescriber_test.js @@ -34,7 +34,7 @@ describe('Unit | UseCase | flag-session-results-as-sent-to-prescriber', function it('should return a NON updated session with a flag to indicate that results has already been sent', async function () { // given - sessionRepository.get.withArgs(sessionId).resolves(alreadyFlaggedResultsAsSentSession); + sessionRepository.get.withArgs({ id: sessionId }).resolves(alreadyFlaggedResultsAsSentSession); // when const { resultsFlaggedAsSent, session } = await flagSessionResultsAsSentToPrescriber({ @@ -57,7 +57,7 @@ describe('Unit | UseCase | flag-session-results-as-sent-to-prescriber', function updatedSession = Symbol('updatedSession'); clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); notFlaggedSession = new Session({ resultsSentToPrescriberAt: null }); - sessionRepository.get.withArgs(sessionId).resolves(notFlaggedSession); + sessionRepository.get.withArgs({ id: sessionId }).resolves(notFlaggedSession); }); afterEach(function () { diff --git a/api/tests/unit/domain/usecases/get-assessment_test.js b/api/tests/unit/domain/usecases/get-assessment_test.js index fad3c7fd11b..022daf50764 100644 --- a/api/tests/unit/domain/usecases/get-assessment_test.js +++ b/api/tests/unit/domain/usecases/get-assessment_test.js @@ -1,7 +1,7 @@ import { NotFoundError } from '../../../../lib/domain/errors.js'; import { Assessment } from '../../../../lib/domain/models/index.js'; import { getAssessment } from '../../../../lib/domain/usecases/get-assessment.js'; -import { CertificationChallengeLiveAlertStatus } from '../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; import { catchErr, domainBuilder, expect, sinon } from '../../../test-helper.js'; describe('Unit | UseCase | get-assessment', function () { @@ -189,8 +189,9 @@ describe('Unit | UseCase | get-assessment', function () { assessmentId: assessment.id, }); certificationChallengeLiveAlertRepository.getByAssessmentId - .withArgs(assessment.id) + .withArgs({ assessmentId: assessment.id }) .resolves([ongoingLiveAlert]); + // when const result = await getAssessment({ assessmentId: assessment.id, diff --git a/api/tests/unit/domain/usecases/get-candidate-import-sheet-data_test.js b/api/tests/unit/domain/usecases/get-candidate-import-sheet-data_test.js index 4e24118a318..91b059437e1 100644 --- a/api/tests/unit/domain/usecases/get-candidate-import-sheet-data_test.js +++ b/api/tests/unit/domain/usecases/get-candidate-import-sheet-data_test.js @@ -19,21 +19,23 @@ describe('Unit | UseCase | get-candidate-import-sheet-data', function () { // given const userId = 123; const sessionId = 456; - sessionRepository.doesUserHaveCertificationCenterMembershipForSession.withArgs(userId, sessionId).resolves(true); + sessionRepository.doesUserHaveCertificationCenterMembershipForSession + .withArgs({ userId, sessionId }) + .resolves(true); const session = domainBuilder.buildSession({ certificationCandidates: [ domainBuilder.buildCertificationCandidate(), domainBuilder.buildCertificationCandidate(), ], }); - sessionRepository.getWithCertificationCandidates.withArgs(sessionId).resolves(session); + sessionRepository.getWithCertificationCandidates.withArgs({ id: sessionId }).resolves(session); const complementaryCertification1 = domainBuilder.buildComplementaryCertification({ name: 'Pix+Droit' }); const complementaryCertification2 = domainBuilder.buildComplementaryCertification({ name: 'Pix+Penché' }); const certificationCenter = domainBuilder.buildCertificationCenter({ habilitations: [complementaryCertification1, complementaryCertification2], type: 'SCO', }); - certificationCenterRepository.getBySessionId.withArgs(sessionId).resolves(certificationCenter); + certificationCenterRepository.getBySessionId.withArgs({ sessionId }).resolves(certificationCenter); // when const result = await getCandidateImportSheetData({ diff --git a/api/tests/unit/domain/usecases/get-certification-candidate-subscription_test.js b/api/tests/unit/domain/usecases/get-certification-candidate-subscription_test.js index 69ccecb347a..e5309e462f7 100644 --- a/api/tests/unit/domain/usecases/get-certification-candidate-subscription_test.js +++ b/api/tests/unit/domain/usecases/get-certification-candidate-subscription_test.js @@ -52,7 +52,7 @@ describe('Unit | UseCase | get-certification-candidate-subscription', function ( .withArgs(certificationCandidateId) .resolves(candidateWithComplementaryCertification); - certificationCenterRepository.getBySessionId.withArgs(sessionId).resolves(certificationCenter); + certificationCenterRepository.getBySessionId.withArgs({ sessionId }).resolves(certificationCenter); certificationBadgesService.findStillValidBadgeAcquisitions .withArgs({ userId }) @@ -111,7 +111,7 @@ describe('Unit | UseCase | get-certification-candidate-subscription', function ( .withArgs(certificationCandidateId) .resolves(candidateWithoutComplementaryCertification); - certificationCenterRepository.getBySessionId.withArgs(sessionId).resolves(certificationCenter); + certificationCenterRepository.getBySessionId.withArgs({ sessionId }).resolves(certificationCenter); certificationBadgesService.findStillValidBadgeAcquisitions .withArgs({ userId }) diff --git a/api/tests/unit/domain/usecases/get-certification-center_test.js b/api/tests/unit/domain/usecases/get-certification-center_test.js index 865637154e7..185dee8f20b 100644 --- a/api/tests/unit/domain/usecases/get-certification-center_test.js +++ b/api/tests/unit/domain/usecases/get-certification-center_test.js @@ -15,7 +15,7 @@ describe('Unit | UseCase | get-certification-center', function () { it('should get the certification center', async function () { // given - certificationCenterRepository.get.withArgs(1234).resolves(certificationCenter); + certificationCenterRepository.get.withArgs({ id: 1234 }).resolves(certificationCenter); // when const actualCertificationCourse = await getCertificationCenter({ diff --git a/api/tests/unit/domain/usecases/get-certification-course_test.js b/api/tests/unit/domain/usecases/get-certification-course_test.js index cd1c3bb2217..622355df765 100644 --- a/api/tests/unit/domain/usecases/get-certification-course_test.js +++ b/api/tests/unit/domain/usecases/get-certification-course_test.js @@ -1,5 +1,5 @@ -import { CertificationCourse } from '../../../../lib/domain/models/CertificationCourse.js'; import { getCertificationCourse } from '../../../../lib/domain/usecases/get-certification-course.js'; +import { CertificationCourse } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { expect, sinon } from '../../../test-helper.js'; describe('Unit | UseCase | get-certification-course', function () { @@ -17,7 +17,7 @@ describe('Unit | UseCase | get-certification-course', function () { it('should get the certificationCourse', async function () { // given - certificationCourseRepository.get.withArgs(certificationCourse.getId()).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: certificationCourse.getId() }).resolves(certificationCourse); // when const actualCertificationCourse = await getCertificationCourse({ diff --git a/api/tests/unit/domain/usecases/get-clea-certified-candidate-by-session_test.js b/api/tests/unit/domain/usecases/get-clea-certified-candidate-by-session_test.js index afb619f2a34..304ebde62c8 100644 --- a/api/tests/unit/domain/usecases/get-clea-certified-candidate-by-session_test.js +++ b/api/tests/unit/domain/usecases/get-clea-certified-candidate-by-session_test.js @@ -13,7 +13,7 @@ describe('Unit | UseCase | getCleaCertifiedCandidateBySession', function () { it('should return session', async function () { // given const expectedSession = domainBuilder.buildSession(); - sessionRepository.get.withArgs(123).resolves(expectedSession); + sessionRepository.get.withArgs({ id: 123 }).resolves(expectedSession); cleaCertifiedCandidateRepository.getBySessionId.withArgs(123).resolves([]); // when diff --git a/api/tests/unit/domain/usecases/get-jury-session_test.js b/api/tests/unit/domain/usecases/get-jury-session_test.js index 48f755ed9f8..65b99381a6a 100644 --- a/api/tests/unit/domain/usecases/get-jury-session_test.js +++ b/api/tests/unit/domain/usecases/get-jury-session_test.js @@ -20,7 +20,7 @@ describe('Unit | UseCase | get-jury-session', function () { // given const sessionId = 123; const sessionToFind = domainBuilder.buildJurySession({ id: sessionId }); - jurySessionRepository.get.withArgs(sessionId).resolves(sessionToFind); + jurySessionRepository.get.withArgs({ id: sessionId }).resolves(sessionToFind); // when const { jurySession: actualSession } = await getJurySession({ @@ -39,7 +39,7 @@ describe('Unit | UseCase | get-jury-session', function () { // given const sessionId = 123; const sessionToFind = domainBuilder.buildJurySession({ id: sessionId }); - jurySessionRepository.get.withArgs(sessionId).resolves({ session: sessionToFind }); + jurySessionRepository.get.withArgs({ id: sessionId }).resolves({ session: sessionToFind }); supervisorAccessRepository.sessionHasSupervisorAccess.withArgs({ sessionId }).resolves(true); // when @@ -59,7 +59,7 @@ describe('Unit | UseCase | get-jury-session', function () { // given const sessionId = 123; const sessionToFind = domainBuilder.buildJurySession({ id: sessionId }); - jurySessionRepository.get.withArgs(sessionId).resolves({ session: sessionToFind }); + jurySessionRepository.get.withArgs({ id: sessionId }).resolves({ session: sessionToFind }); supervisorAccessRepository.sessionHasSupervisorAccess.withArgs({ sessionId }).resolves(false); // when @@ -78,7 +78,7 @@ describe('Unit | UseCase | get-jury-session', function () { it('should throw an error the session', async function () { // given const sessionId = 123; - jurySessionRepository.get.withArgs(sessionId).rejects(new NotFoundError()); + jurySessionRepository.get.withArgs({ id: sessionId }).rejects(new NotFoundError()); // when const err = await catchErr(getJurySession)({ sessionId, jurySessionRepository, supervisorAccessRepository }); diff --git a/api/tests/unit/domain/usecases/get-session-results-by-result-recipient-email_test.js b/api/tests/unit/domain/usecases/get-session-results-by-result-recipient-email_test.js index a2647fcb26d..dbb74d6e247 100644 --- a/api/tests/unit/domain/usecases/get-session-results-by-result-recipient-email_test.js +++ b/api/tests/unit/domain/usecases/get-session-results-by-result-recipient-email_test.js @@ -15,7 +15,7 @@ describe('Unit | Domain | Use Cases | get-session-results-by-result-recipient-em const expectedSession = domainBuilder.buildSession({ certificationCandidates: [], }); - sessionRepository.getWithCertificationCandidates.withArgs(123).resolves(expectedSession); + sessionRepository.getWithCertificationCandidates.withArgs({ id: 123 }).resolves(expectedSession); certificationResultRepository.findByCertificationCandidateIds .withArgs({ certificationCandidateIds: [] }) .resolves([]); @@ -47,7 +47,7 @@ describe('Unit | Domain | Use Cases | get-session-results-by-result-recipient-em date: '2019-06-06', time: '12:05:30', }); - sessionRepository.getWithCertificationCandidates.withArgs(123).resolves(expectedSession); + sessionRepository.getWithCertificationCandidates.withArgs({ id: 123 }).resolves(expectedSession); const certificationResult = domainBuilder.buildCertificationResult({ firstName: 'Buffy' }); certificationResultRepository.findByCertificationCandidateIds .withArgs({ certificationCandidateIds: [789] }) diff --git a/api/tests/unit/domain/usecases/get-session-results_test.js b/api/tests/unit/domain/usecases/get-session-results_test.js index c2d46274293..5fa6e4098d2 100644 --- a/api/tests/unit/domain/usecases/get-session-results_test.js +++ b/api/tests/unit/domain/usecases/get-session-results_test.js @@ -13,7 +13,7 @@ describe('Unit | Domain | Use Cases | get-session-results', function () { it('should return the session and the certificationResults', async function () { // given const expectedSession = domainBuilder.buildSession(); - sessionRepository.get.withArgs(123).resolves(expectedSession); + sessionRepository.get.withArgs({ id: 123 }).resolves(expectedSession); const certificationResult1 = domainBuilder.buildCertificationResult({ firstName: 'Buffy' }); const certificationResult2 = domainBuilder.buildCertificationResult({ firstName: 'Spike' }); certificationResultRepository.findBySessionId diff --git a/api/tests/unit/domain/usecases/get-session_test.js b/api/tests/unit/domain/usecases/get-session_test.js index 7b97ad49529..0a1d8b309c2 100644 --- a/api/tests/unit/domain/usecases/get-session_test.js +++ b/api/tests/unit/domain/usecases/get-session_test.js @@ -21,8 +21,8 @@ describe('Unit | UseCase | get-session', function () { // given const sessionId = 123; const sessionToFind = domainBuilder.buildSession({ id: sessionId }); - sessionRepository.get.withArgs(sessionId).resolves(sessionToFind); - sessionRepository.hasSomeCleaAcquired.withArgs(sessionId).resolves(false); + sessionRepository.get.withArgs({ id: sessionId }).resolves(sessionToFind); + sessionRepository.hasSomeCleaAcquired.withArgs({ id: sessionId }).resolves(false); supervisorAccessRepository.sessionHasSupervisorAccess.resolves(true); // when @@ -37,8 +37,8 @@ describe('Unit | UseCase | get-session', function () { // given const sessionId = 123; const sessionToFind = domainBuilder.buildSession({ id: sessionId }); - sessionRepository.get.withArgs(sessionId).resolves(sessionToFind); - sessionRepository.hasSomeCleaAcquired.withArgs(sessionId).resolves(false); + sessionRepository.get.withArgs({ id: sessionId }).resolves(sessionToFind); + sessionRepository.hasSomeCleaAcquired.withArgs({ id: sessionId }).resolves(false); supervisorAccessRepository.sessionHasSupervisorAccess.resolves(true); // when @@ -54,8 +54,8 @@ describe('Unit | UseCase | get-session', function () { // given const sessionId = 123; const sessionToFind = domainBuilder.buildSession({ id: sessionId }); - sessionRepository.get.withArgs(sessionId).resolves(sessionToFind); - sessionRepository.hasSomeCleaAcquired.withArgs(sessionId).resolves(false); + sessionRepository.get.withArgs({ id: sessionId }).resolves(sessionToFind); + sessionRepository.hasSomeCleaAcquired.withArgs({ id: sessionId }).resolves(false); supervisorAccessRepository.sessionHasSupervisorAccess.resolves(false); // when @@ -71,8 +71,8 @@ describe('Unit | UseCase | get-session', function () { // given const sessionId = 123; const sessionToFind = domainBuilder.buildSession({ id: sessionId }); - sessionRepository.get.withArgs(sessionId).resolves(sessionToFind); - sessionRepository.hasSomeCleaAcquired.withArgs(sessionId).resolves(true); + sessionRepository.get.withArgs({ id: sessionId }).resolves(sessionToFind); + sessionRepository.hasSomeCleaAcquired.withArgs({ id: sessionId }).resolves(true); supervisorAccessRepository.sessionHasSupervisorAccess.resolves(true); // when @@ -92,8 +92,8 @@ describe('Unit | UseCase | get-session', function () { // given const sessionId = 123; const sessionToFind = domainBuilder.buildSession({ id: sessionId }); - sessionRepository.get.withArgs(sessionId).resolves(sessionToFind); - sessionRepository.hasSomeCleaAcquired.withArgs(sessionId).resolves(false); + sessionRepository.get.withArgs({ id: sessionId }).resolves(sessionToFind); + sessionRepository.hasSomeCleaAcquired.withArgs({ id: sessionId }).resolves(false); supervisorAccessRepository.sessionHasSupervisorAccess.resolves(true); // when @@ -113,7 +113,7 @@ describe('Unit | UseCase | get-session', function () { it('should throw an error the session', async function () { // given const sessionId = 123; - sessionRepository.get.withArgs(sessionId).rejects(new NotFoundError()); + sessionRepository.get.withArgs({ id: sessionId }).rejects(new NotFoundError()); // when const err = await catchErr(getSession)({ sessionId, sessionRepository, supervisorAccessRepository }); diff --git a/api/tests/unit/domain/usecases/link-user-to-session-certification-candidate_test.js b/api/tests/unit/domain/usecases/link-user-to-session-certification-candidate_test.js index 8e545eba111..7e08d3f170b 100644 --- a/api/tests/unit/domain/usecases/link-user-to-session-certification-candidate_test.js +++ b/api/tests/unit/domain/usecases/link-user-to-session-certification-candidate_test.js @@ -24,7 +24,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida const sessionRepository = { get: sinon.stub(), }; - sessionRepository.get.withArgs(42).resolves(domainBuilder.buildSession.finalized()); + sessionRepository.get.withArgs({ id: 42 }).resolves(domainBuilder.buildSession.finalized()); // when const err = await catchErr(linkUserToSessionCertificationCandidate)({ @@ -46,7 +46,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida beforeEach(function () { sessionRepository.get = sinon.stub(); - sessionRepository.get.withArgs(42).resolves(domainBuilder.buildSession.created()); + sessionRepository.get.withArgs({ id: 42 }).resolves(domainBuilder.buildSession.created()); }); context('when there is a problem with the personal info', function () { @@ -135,7 +135,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida const certificationCenter = domainBuilder.buildCertificationCenter({ sessionId, type: 'SUP' }); const certificationCenterRepository = _buildFakeCertificationCenterRepository().withGetBySessionId({ - args: sessionId, + args: { sessionId }, resolves: certificationCenter, }); @@ -173,7 +173,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida const certificationCenter = domainBuilder.buildCertificationCenter({ sessionId, type: 'SUP' }); const certificationCenterRepository = _buildFakeCertificationCenterRepository().withGetBySessionId({ - args: sessionId, + args: { sessionId }, resolves: certificationCenter, }); @@ -217,7 +217,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida const certificationCenter = domainBuilder.buildCertificationCenter({ sessionId, type: 'SUP' }); const certificationCenterRepository = _buildFakeCertificationCenterRepository().withGetBySessionId({ - args: sessionId, + args: { sessionId }, resolves: certificationCenter, }); @@ -260,7 +260,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida const certificationCenter = domainBuilder.buildCertificationCenter({ sessionId, type: 'SUP' }); const certificationCenterRepository = _buildFakeCertificationCenterRepository().withGetBySessionId({ - args: sessionId, + args: { sessionId }, resolves: certificationCenter, }); @@ -316,7 +316,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida externalId: '123456', }); const certificationCenterRepository = _buildFakeCertificationCenterRepository().withGetBySessionId({ - args: sessionId, + args: { sessionId }, resolves: certificationCenter, }); const organization = domainBuilder.buildOrganization({ @@ -390,7 +390,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida externalId: '123456', }); const certificationCenterRepository = _buildFakeCertificationCenterRepository().withGetBySessionId({ - args: sessionId, + args: { sessionId }, resolves: certificationCenter, }); const organization = domainBuilder.buildOrganization({ @@ -470,7 +470,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida externalId: '123456', }); const certificationCenterRepository = _buildFakeCertificationCenterRepository().withGetBySessionId({ - args: sessionId, + args: { sessionId }, resolves: certificationCenter, }); const organization = domainBuilder.buildOrganization({ @@ -536,7 +536,7 @@ describe('Unit | Domain | Use Cases | link-user-to-session-certification-candida externalId: '123456', }); const certificationCenterRepository = _buildFakeCertificationCenterRepository().withGetBySessionId({ - args: sessionId, + args: { sessionId }, resolves: certificationCenter, }); const organization = domainBuilder.buildOrganization({ diff --git a/api/tests/unit/domain/usecases/manually-resolve-certification-issue-report_test.js b/api/tests/unit/domain/usecases/manually-resolve-certification-issue-report_test.js index e905370a225..16e137f0654 100644 --- a/api/tests/unit/domain/usecases/manually-resolve-certification-issue-report_test.js +++ b/api/tests/unit/domain/usecases/manually-resolve-certification-issue-report_test.js @@ -28,7 +28,9 @@ describe('Unit | UseCase | manually-resolve-certification-issue-report', functio // then expect(certificationIssueReportRepository.get).to.have.been.called; - expect(certificationIssueReportRepository.save).to.have.been.calledWithExactly(expectedCertificationIssueReport); + expect(certificationIssueReportRepository.save).to.have.been.calledWithExactly({ + certificationIssueReport: expectedCertificationIssueReport, + }); expect(expectedCertificationIssueReport.resolveManually).to.have.been.calledWithExactly(resolution); }); }); @@ -57,9 +59,9 @@ describe('Unit | UseCase | manually-resolve-certification-issue-report', functio }); // then - expect(certificationIssueReportRepository.save).to.have.been.calledWithExactly( - expectedCertificationIssueReport, - ); + expect(certificationIssueReportRepository.save).to.have.been.calledWithExactly({ + certificationIssueReport: expectedCertificationIssueReport, + }); }); }); diff --git a/api/tests/unit/domain/usecases/retrieve-last-or-create-certification-course_test.js b/api/tests/unit/domain/usecases/retrieve-last-or-create-certification-course_test.js index cb4a9f8763f..66e4c99906b 100644 --- a/api/tests/unit/domain/usecases/retrieve-last-or-create-certification-course_test.js +++ b/api/tests/unit/domain/usecases/retrieve-last-or-create-certification-course_test.js @@ -9,9 +9,9 @@ import { UnexpectedUserAccountError, UserNotAuthorizedToCertifyError, } from '../../../../lib/domain/errors.js'; -import { CertificationCourse } from '../../../../lib/domain/models/CertificationCourse.js'; import { ComplementaryCertificationCourse } from '../../../../lib/domain/models/ComplementaryCertificationCourse.js'; import { retrieveLastOrCreateCertificationCourse } from '../../../../lib/domain/usecases/retrieve-last-or-create-certification-course.js'; +import { CertificationCourse } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { Assessment } from '../../../../src/shared/domain/models/Assessment.js'; import { catchErr, domainBuilder, expect, sinon } from '../../../test-helper.js'; @@ -78,7 +78,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi it('should throw a not found error', async function () { // given const foundSession = domainBuilder.buildSession({ accessCode: 'differentAccessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); // when const error = await catchErr(retrieveLastOrCreateCertificationCourse)({ @@ -102,7 +102,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi it('should throw a SessionNotAccessible error', async function () { // given const foundSession = domainBuilder.buildSession.finalized({ id: 1, accessCode: 'accessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); // when const error = await catchErr(retrieveLastOrCreateCertificationCourse)({ @@ -127,7 +127,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi it('should throw a CandidateNotAuthorizedToJoinSessionError', async function () { // given const foundSession = domainBuilder.buildSession.created({ id: 1, accessCode: 'accessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); const candidateNotAuthorizedToStart = domainBuilder.buildCertificationCandidate({ userId: 2, @@ -158,7 +158,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi // given const domainTransaction = Symbol('someDomainTransaction'); const foundSession = domainBuilder.buildSession.created({ id: 1, accessCode: 'accessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); const candidateNotAuthorizedToStart = domainBuilder.buildCertificationCandidate({ userId: 2, @@ -196,7 +196,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi // given const domainTransaction = Symbol('someDomainTransaction'); const foundSession = domainBuilder.buildSession.created({ id: 1, accessCode: 'accessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); const foundCertificationCandidateId = 2; domainBuilder.buildCertificationCourse({ userId: foundCertificationCandidateId, sessionId: 1 }); @@ -231,7 +231,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi // given const domainTransaction = Symbol('someDomainTransaction'); const foundSession = domainBuilder.buildSession.created({ id: 1, accessCode: 'accessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); const foundCertificationCandidate = domainBuilder.buildCertificationCandidate({ userId: 2, @@ -278,7 +278,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi const domainTransaction = Symbol('someDomainTransaction'); const foundSession = domainBuilder.buildSession.created({ id: 1, accessCode: 'accessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); certificationCandidateRepository.getBySessionIdAndUserId.withArgs({ sessionId: 1, userId: 2 }).resolves( domainBuilder.buildCertificationCandidate({ @@ -325,7 +325,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi // given const domainTransaction = Symbol('someDomainTransaction'); const foundSession = domainBuilder.buildSession.created({ id: 1, accessCode: 'accessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); certificationCandidateRepository.getBySessionIdAndUserId.withArgs({ sessionId: 1, userId: 2 }).resolves( domainBuilder.buildCertificationCandidate({ @@ -385,7 +385,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi const domainTransaction = Symbol('someDomainTransaction'); const foundSession = domainBuilder.buildSession.created({ id: 1, accessCode: 'accessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); const foundCertificationCandidate = domainBuilder.buildCertificationCandidate({ userId: 2, @@ -475,7 +475,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi accessCode: 'accessCode', version: 3, }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); const foundCertificationCandidate = domainBuilder.buildCertificationCandidate({ userId: 2, @@ -577,7 +577,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi id: 1, accessCode: 'accessCode', }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); certificationCourseRepository.findOneCertificationCourseByUserIdAndSessionId .withArgs({ userId: 2, sessionId: 1, domainTransaction }) @@ -702,7 +702,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi id: 1, accessCode: 'accessCode', }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); certificationCourseRepository.findOneCertificationCourseByUserIdAndSessionId .withArgs({ userId: 2, sessionId: 1, domainTransaction }) @@ -819,7 +819,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi id: 1, accessCode: 'accessCode', }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); certificationCourseRepository.findOneCertificationCourseByUserIdAndSessionId .withArgs({ userId: 2, sessionId: 1, domainTransaction }) @@ -924,7 +924,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi id: 1, accessCode: 'accessCode', }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); certificationCourseRepository.findOneCertificationCourseByUserIdAndSessionId .withArgs({ userId: 2, sessionId: 1, domainTransaction }) @@ -1045,7 +1045,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi id: 1, accessCode: 'accessCode', }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); certificationCourseRepository.findOneCertificationCourseByUserIdAndSessionId .withArgs({ userId: 2, sessionId: 1, domainTransaction }) @@ -1142,7 +1142,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi const domainTransaction = Symbol('someDomainTransaction'); const foundSession = domainBuilder.buildSession.created({ id: 1, accessCode: 'accessCode' }); - sessionRepository.get.withArgs(1).resolves(foundSession); + sessionRepository.get.withArgs({ id: 1 }).resolves(foundSession); certificationCourseRepository.findOneCertificationCourseByUserIdAndSessionId .withArgs({ userId: 2, sessionId: 1, domainTransaction }) diff --git a/api/tests/unit/domain/usecases/uncancel-certification-course_test.js b/api/tests/unit/domain/usecases/uncancel-certification-course_test.js index 86b5313c202..da0eef5dc75 100644 --- a/api/tests/unit/domain/usecases/uncancel-certification-course_test.js +++ b/api/tests/unit/domain/usecases/uncancel-certification-course_test.js @@ -10,7 +10,7 @@ describe('Unit | UseCase | uncancel-certification-course', function () { update: sinon.stub(), get: sinon.stub(), }; - certificationCourseRepository.get.withArgs(123).resolves(certificationCourse); + certificationCourseRepository.get.withArgs({ id: 123 }).resolves(certificationCourse); certificationCourseRepository.update.resolves(); // when @@ -21,6 +21,6 @@ describe('Unit | UseCase | uncancel-certification-course', function () { // then expect(certificationCourse.uncancel).to.have.been.calledOnce; - expect(certificationCourseRepository.update).to.have.been.calledWithExactly(certificationCourse); + expect(certificationCourseRepository.update).to.have.been.calledWithExactly({ certificationCourse }); }); }); diff --git a/api/tests/unit/domain/usecases/unpublish-session_test.js b/api/tests/unit/domain/usecases/unpublish-session_test.js index 6eb6b31b9ab..582b85252fa 100644 --- a/api/tests/unit/domain/usecases/unpublish-session_test.js +++ b/api/tests/unit/domain/usecases/unpublish-session_test.js @@ -29,7 +29,7 @@ describe('Unit | UseCase | unpublish-session', function () { id: sessionId, publishedAt: new Date('2020-01-01'), }); - sessionRepository.getWithCertificationCandidates.withArgs(sessionId).resolves(expectedSession); + sessionRepository.getWithCertificationCandidates.withArgs({ id: sessionId }).resolves(expectedSession); const finalizedSession = new FinalizedSession({ sessionId, publishSession: new Date('2020-01-01') }); finalizedSessionRepository.get.withArgs({ sessionId }).resolves(finalizedSession); @@ -45,7 +45,7 @@ describe('Unit | UseCase | unpublish-session', function () { expect(certificationRepository.unpublishCertificationCoursesBySessionId).to.have.been.calledWithExactly(sessionId); expect(sessionRepository.updatePublishedAt).to.have.been.calledWithExactly({ id: sessionId, publishedAt: null }); expect(finalizedSession.publishedAt).to.be.null; - expect(finalizedSessionRepository.save).to.be.calledWith(finalizedSession); + expect(finalizedSessionRepository.save).to.be.calledWith({ finalizedSession }); expect(actualSession).to.deep.equal({ ...expectedSession, publishedAt: null, diff --git a/api/tests/unit/infrastructure/serializers/jsonapi/certification-course-serializer_test.js b/api/tests/unit/infrastructure/serializers/jsonapi/certification-course-serializer_test.js index 74a4ba70d0f..969a61ebf0c 100644 --- a/api/tests/unit/infrastructure/serializers/jsonapi/certification-course-serializer_test.js +++ b/api/tests/unit/infrastructure/serializers/jsonapi/certification-course-serializer_test.js @@ -1,5 +1,5 @@ -import { CertificationCourse } from '../../../../../lib/domain/models/CertificationCourse.js'; import * as serializer from '../../../../../lib/infrastructure/serializers/jsonapi/certification-course-serializer.js'; +import { CertificationCourse } from '../../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { CertificationIssueReport } from '../../../../../src/certification/shared/domain/models/CertificationIssueReport.js'; import { CertificationIssueReportCategory } from '../../../../../src/certification/shared/domain/models/CertificationIssueReportCategory.js'; import { Assessment } from '../../../../../src/shared/domain/models/Assessment.js'; diff --git a/api/tests/unit/infrastructure/serializers/jsonapi/certification-serializer_test.js b/api/tests/unit/infrastructure/serializers/jsonapi/certification-serializer_test.js index d2780eda18a..8ac24850d8f 100644 --- a/api/tests/unit/infrastructure/serializers/jsonapi/certification-serializer_test.js +++ b/api/tests/unit/infrastructure/serializers/jsonapi/certification-serializer_test.js @@ -1,6 +1,6 @@ import { WrongDateFormatError } from '../../../../../lib/domain/errors.js'; -import { CertificationCourse } from '../../../../../lib/domain/models/CertificationCourse.js'; import * as serializer from '../../../../../lib/infrastructure/serializers/jsonapi/certification-serializer.js'; +import { CertificationCourse } from '../../../../../src/certification/shared/domain/models/CertificationCourse.js'; import { NO_EXAMINER_COMMENT } from '../../../../../src/certification/shared/domain/models/CertificationReport.js'; import { domainBuilder, EMPTY_BLANK_AND_NULL, expect } from '../../../../test-helper.js'; diff --git a/api/tests/unit/infrastructure/serializers/jsonapi/session-for-supervising-serializer_test.js b/api/tests/unit/infrastructure/serializers/jsonapi/session-for-supervising-serializer_test.js index b118afa0045..698ebff442a 100644 --- a/api/tests/unit/infrastructure/serializers/jsonapi/session-for-supervising-serializer_test.js +++ b/api/tests/unit/infrastructure/serializers/jsonapi/session-for-supervising-serializer_test.js @@ -1,6 +1,6 @@ import { CertificationCandidateForSupervising } from '../../../../../lib/domain/models/index.js'; import * as serializer from '../../../../../lib/infrastructure/serializers/jsonapi/session-for-supervising-serializer.js'; -import { CertificationChallengeLiveAlertStatus } from '../../../../../src/certification/session/domain/models/CertificationChallengeLiveAlert.js'; +import { CertificationChallengeLiveAlertStatus } from '../../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js'; import { CertificationCandidateForSupervisingV3 } from '../../../../../src/certification/supervision/domain/models/CertificationCandidateForSupervisingV3.js'; import { Assessment } from '../../../../../src/shared/domain/models/Assessment.js'; import { domainBuilder, expect } from '../../../../test-helper.js';