diff --git a/api/lib/domain/usecases/index.js b/api/lib/domain/usecases/index.js index 8783e779f13..63c53290af7 100644 --- a/api/lib/domain/usecases/index.js +++ b/api/lib/domain/usecases/index.js @@ -7,7 +7,6 @@ import * as complementaryCertificationRepository from '../../../src/certificatio import * as sessionCodeService from '../../../src/certification/enrolment/domain/services/session-code-service.js'; import { getCenterForAdmin } from '../../../src/certification/enrolment/domain/usecases/get-center-for-admin.js'; import * as centerRepository from '../../../src/certification/enrolment/infrastructure/repositories/center-repository.js'; -import * as certificationCandidateRepository from '../../../src/certification/enrolment/infrastructure/repositories/certification-candidate-repository.js'; import * as certificationCpfCityRepository from '../../../src/certification/enrolment/infrastructure/repositories/certification-cpf-city-repository.js'; import * as sessionEnrolmentRepository from '../../../src/certification/enrolment/infrastructure/repositories/session-repository.js'; import * as certificationEvaluationCandidateRepository from '../../../src/certification/evaluation/infrastructure/repositories/certification-candidate-repository.js'; @@ -23,6 +22,7 @@ import * as supervisorAccessRepository from '../../../src/certification/session- import * as certificationBadgesService from '../../../src/certification/shared/domain/services/certification-badges-service.js'; import * as scoringCertificationService from '../../../src/certification/shared/domain/services/scoring-certification-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'; diff --git a/api/lib/routes.js b/api/lib/routes.js index 73ccb3b893b..888a92bbdcd 100644 --- a/api/lib/routes.js +++ b/api/lib/routes.js @@ -4,7 +4,6 @@ import * as campaignParticipations from './application/campaign-participations/i import * as certificationCenterInvitations from './application/certification-center-invitations/index.js'; import * as certificationCenterMemberships from './application/certification-center-memberships/index.js'; import * as certificationCenters from './application/certification-centers/index.js'; -import * as certificationCourses from './application/certification-courses/index.js'; import * as certificationPointOfContacts from './application/certification-point-of-contacts/index.js'; import * as certifications from './application/certifications/index.js'; import * as frameworks from './application/frameworks/index.js'; @@ -24,7 +23,6 @@ const routes = [ certificationCenters, certificationCenterInvitations, certificationCenterMemberships, - certificationCourses, certificationPointOfContacts, certifications, healthcheck, diff --git a/api/src/certification/enrolment/domain/usecases/index.js b/api/src/certification/enrolment/domain/usecases/index.js index a1724e0d1b1..ef7a9037d99 100644 --- a/api/src/certification/enrolment/domain/usecases/index.js +++ b/api/src/certification/enrolment/domain/usecases/index.js @@ -21,7 +21,7 @@ import * as temporarySessionsStorageForMassImportService from '../services/tempo * @typedef {import('../../infrastructure/repositories/index.js').ComplementaryCertificationRepository} ComplementaryCertificationRepository * @typedef {import('../../infrastructure/repositories/index.js').ComplementaryCertificationBadgeWithOffsetVersionRepository} ComplementaryCertificationBadgeWithOffsetVersionRepository * @typedef {import('../../infrastructure/repositories/index.js').SessionRepository} SessionRepository - * @typedef {import('../../infrastructure/repositories/index.js').CertificationCandidateRepository} CertificationCandidateRepository + * @typedef {import('../../../../shared/infrastructure/repositories/index.js').CertificationCandidateRepository} CertificationCandidateRepository * @typedef {import('../../../session-management/infrastructure/repositories/index.js').CertificationCandidateForSupervisingRepository} CertificationCandidateForSupervisingRepository * @typedef {import('../../infrastructure/repositories/index.js').CertificationCpfCityRepository} CertificationCpfCityRepository * @typedef {import('../../infrastructure/repositories/index.js').CertificationCpfCountryRepository} CertificationCpfCountryRepository @@ -32,7 +32,7 @@ import * as temporarySessionsStorageForMassImportService from '../services/tempo * @typedef {import('../../infrastructure/repositories/index.js').CountryRepository} CountryRepository * @typedef {import('../../infrastructure/repositories/index.js').ScoCertificationCandidateRepository} ScoCertificationCandidateRepository * @typedef {import('../../infrastructure/repositories/index.js').OrganizationLearnerRepository} OrganizationLearnerRepository - * @typedef {import('../../infrastructure/repositories/index.js').UserRepository} UserRepository + * @typedef {import('../../../../shared/infrastructure/repositories/index.js').UserRepository} UserRepository * @typedef {import('../../../shared/domain/validators/session-validator.js')} SessionValidator * @typedef {import('../../../shared/domain/services/certification-cpf-service.js')} CertificationCpfService * @typedef {import('../../infrastructure/utils/pdf/attendance-sheet-pdf.js')} AttendanceSheetPdfUtils diff --git a/api/src/certification/enrolment/infrastructure/repositories/index.js b/api/src/certification/enrolment/infrastructure/repositories/index.js index 4bf815de303..1d12c54e3f4 100644 --- a/api/src/certification/enrolment/infrastructure/repositories/index.js +++ b/api/src/certification/enrolment/infrastructure/repositories/index.js @@ -2,11 +2,12 @@ import * as organizationLearnerRepository from '../../../../../lib/infrastructur import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js'; import * as complementaryCertificationApi from '../../../complementary-certification/application/api/complementary-certification-api.js'; import * as sessionManagementRepository from '../../../session-management/infrastructure/repositories/session-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 targetProfileHistoryRepository from '../../../shared/infrastructure/repositories/target-profile-history-repository.js'; +import * as userRepository from '../../../shared/infrastructure/repositories/user-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 complementaryCertificationBadgeWithOffsetVersionRepository from './complementary-certification-badge-with-offset-version-repository.js'; @@ -18,7 +19,6 @@ import * as pixCertificationRepository from './pix-certification-repository.js'; import * as scoCertificationCandidateRepository from './sco-certification-candidate-repository.js'; import * as sessionForAttendanceSheetRepository from './session-for-attendance-sheet-repository.js'; import * as sessionRepository from './session-repository.js'; -import * as userRepository from './user-repository.js'; /** * Using {@link https://jsdoc.app/tags-type "Closure Compiler's syntax"} to document injected dependencies diff --git a/api/lib/application/certification-courses/certification-course-controller.js b/api/src/certification/evaluation/application/certification-course-controller.js similarity index 50% rename from api/lib/application/certification-courses/certification-course-controller.js rename to api/src/certification/evaluation/application/certification-course-controller.js index 37e446b64fc..ef2c6b84091 100644 --- a/api/lib/application/certification-courses/certification-course-controller.js +++ b/api/src/certification/evaluation/application/certification-course-controller.js @@ -1,8 +1,7 @@ -import { extractLocaleFromRequest } from '../../../src/shared/infrastructure/utils/request-response-utils.js'; -import { usecases } from '../../domain/usecases/index.js'; -import * as certifiedProfileRepository from '../../infrastructure/repositories/certified-profile-repository.js'; -import * as certificationCourseSerializer from '../../infrastructure/serializers/jsonapi/certification-course-serializer.js'; -import * as certifiedProfileSerializer from '../../infrastructure/serializers/jsonapi/certified-profile-serializer.js'; +import { extractLocaleFromRequest } from '../../../shared/infrastructure/utils/request-response-utils.js'; +import { usecases as certificationSharedUsecases } from '../../shared/domain/usecases/index.js'; +import { usecases } from '../domain/usecases/index.js'; +import * as certificationCourseSerializer from '../infrastructure/serializers/certification-course-serializer.js'; const save = async function (request, h, dependencies = { extractLocaleFromRequest, certificationCourseSerializer }) { const userId = request.auth.credentials.userId; @@ -24,24 +23,13 @@ const save = async function (request, h, dependencies = { extractLocaleFromReque const get = async function (request, h, dependencies = { certificationCourseSerializer }) { const certificationCourseId = request.params.id; - const certificationCourse = await usecases.getCertificationCourse({ certificationCourseId }); + const certificationCourse = await certificationSharedUsecases.getCertificationCourse({ certificationCourseId }); return dependencies.certificationCourseSerializer.serialize(certificationCourse); }; -const getCertifiedProfile = async function ( - request, - h, - dependencies = { certifiedProfileRepository, certifiedProfileSerializer }, -) { - const certificationCourseId = request.params.id; - const certifiedProfile = await dependencies.certifiedProfileRepository.get(certificationCourseId); - return dependencies.certifiedProfileSerializer.serialize(certifiedProfile); -}; - const certificationCourseController = { save, get, - getCertifiedProfile, }; export { certificationCourseController }; diff --git a/api/lib/application/certification-courses/index.js b/api/src/certification/evaluation/application/certification-course-route.js similarity index 58% rename from api/lib/application/certification-courses/index.js rename to api/src/certification/evaluation/application/certification-course-route.js index a3f935d6665..1db53aacc95 100644 --- a/api/lib/application/certification-courses/index.js +++ b/api/src/certification/evaluation/application/certification-course-route.js @@ -1,43 +1,11 @@ import Joi from 'joi'; -import { securityPreHandlers } from '../../../src/shared/application/security-pre-handlers.js'; -import { identifiersType } from '../../../src/shared/domain/types/identifiers-type.js'; +import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; +import { identifiersType } from '../../../shared/domain/types/identifiers-type.js'; import { certificationCourseController } from './certification-course-controller.js'; const register = async function (server) { - const adminRoutes = [ - { - method: 'GET', - path: '/api/admin/certifications/{id}/certified-profile', - config: { - pre: [ - { - method: (request, h) => - securityPreHandlers.hasAtLeastOneAccessOf([ - securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, - securityPreHandlers.checkAdminMemberHasRoleCertif, - securityPreHandlers.checkAdminMemberHasRoleSupport, - securityPreHandlers.checkAdminMemberHasRoleMetier, - ])(request, h), - assign: 'hasAuthorizationToAccessAdminScope', - }, - ], - validate: { - params: Joi.object({ - id: identifiersType.certificationCourseId, - }), - }, - handler: certificationCourseController.getCertifiedProfile, - tags: ['api'], - notes: [ - 'Cette route est utilisé par Pix Admin', - 'Elle permet de récupérer le profil certifié pour une certification donnée', - ], - }, - }, - ]; server.route([ - ...adminRoutes, { method: 'POST', path: '/api/certification-courses', diff --git a/api/src/certification/evaluation/domain/usecases/index.js b/api/src/certification/evaluation/domain/usecases/index.js index 4015b9d4615..94017dd9fa0 100644 --- a/api/src/certification/evaluation/domain/usecases/index.js +++ b/api/src/certification/evaluation/domain/usecases/index.js @@ -1,7 +1,11 @@ import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; +import * as certificationChallengesService from '../../../../../lib/domain/services/certification-challenges-service.js'; +import * as verifyCertificateCodeService from '../../../../../lib/domain/services/verify-certificate-code-service.js'; import { pickChallengeService } from '../../../../evaluation/domain/services/pick-challenge-service.js'; +import * as languageService from '../../../../shared/domain/services/language-service.js'; +import * as placementProfileService from '../../../../shared/domain/services/placement-profile-service.js'; import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js'; import { importNamedExportsFromDirectory } from '../../../../shared/infrastructure/utils/import-named-exports-from-directory.js'; import * as flashAlgorithmService from '../../../flash-certification/domain/services/algorithm-methods/flash.js'; @@ -17,28 +21,39 @@ import { sessionRepositories, sharedCompetenceMarkRepository, } from '../../../session-management/infrastructure/repositories/index.js'; +import * as certificationBadgesService from '../../../shared/domain/services/certification-badges-service.js'; +import * as sharedCertificationCandidateRepository from '../../../shared/infrastructure/repositories/certification-candidate-repository.js'; +import * as certificationCenterRepository from '../../../shared/infrastructure/repositories/certification-center-repository.js'; import * as certificationCourseRepository from '../../../shared/infrastructure/repositories/certification-course-repository.js'; +import * as userRepository from '../../../shared/infrastructure/repositories/user-repository.js'; import * as certificationCandidateRepository from '../../infrastructure/repositories/certification-candidate-repository.js'; import * as certificationCompanionAlertRepository from '../../infrastructure/repositories/certification-companion-alert-repository.js'; - /** * @typedef {certificationCompanionAlertRepository} CertificationCompanionAlertRepository */ const dependencies = { ...sessionRepositories, - certificationCandidateRepository, assessmentRepository, + sharedCertificationCandidateRepository, + verifyCertificateCodeService, assessmentResultRepository, answerRepository, sharedCompetenceMarkRepository, challengeRepository, + userRepository, competenceMarkRepository, + certificationChallengesService, cpfExportRepository, certificationChallengeRepository, flashAlgorithmConfigurationRepository, flashAlgorithmService, + languageService, + certificationBadgesService, pickChallengeService, + placementProfileService, + certificationCenterRepository, + certificationCandidateRepository, certificationCompanionAlertRepository, certificationCourseRepository, }; diff --git a/api/lib/domain/usecases/retrieve-last-or-create-certification-course.js b/api/src/certification/evaluation/domain/usecases/retrieve-last-or-create-certification-course.js similarity index 89% rename from api/lib/domain/usecases/retrieve-last-or-create-certification-course.js rename to api/src/certification/evaluation/domain/usecases/retrieve-last-or-create-certification-course.js index dbe49cb680a..31024337d86 100644 --- a/api/lib/domain/usecases/retrieve-last-or-create-certification-course.js +++ b/api/src/certification/evaluation/domain/usecases/retrieve-last-or-create-certification-course.js @@ -11,21 +11,21 @@ * @typedef {import('./index.js').AssessmentRepository} AssessmentRepository * @typedef {import('../../../src/shared/domain/models/CertificationCandidate.js').CertificationCandidate} CertificationCandidate */ -import { SessionNotAccessible } from '../../../src/certification/session-management/domain/errors.js'; -import { ComplementaryCertificationCourse } from '../../../src/certification/session-management/domain/models/ComplementaryCertificationCourse.js'; -import { AlgorithmEngineVersion } from '../../../src/certification/shared/domain/models/AlgorithmEngineVersion.js'; -import { CertificationCourse } from '../../../src/certification/shared/domain/models/CertificationCourse.js'; -import { SessionVersion } from '../../../src/certification/shared/domain/models/SessionVersion.js'; -import { config } from '../../../src/shared/config.js'; -import { LanguageNotSupportedError } from '../../../src/shared/domain/errors.js'; +import { DomainTransaction } from '../../../../../lib/infrastructure/DomainTransaction.js'; +import { config } from '../../../../shared/config.js'; +import { LanguageNotSupportedError } from '../../../../shared/domain/errors.js'; import { CandidateNotAuthorizedToJoinSessionError, CandidateNotAuthorizedToResumeCertificationTestError, NotFoundError, UnexpectedUserAccountError, -} from '../../../src/shared/domain/errors.js'; -import { Assessment } from '../../../src/shared/domain/models/Assessment.js'; -import { DomainTransaction } from '../../infrastructure/DomainTransaction.js'; +} from '../../../../shared/domain/errors.js'; +import { Assessment } from '../../../../shared/domain/models/Assessment.js'; +import { SessionNotAccessible } from '../../../session-management/domain/errors.js'; +import { ComplementaryCertificationCourse } from '../../../session-management/domain/models/ComplementaryCertificationCourse.js'; +import { AlgorithmEngineVersion } from '../../../shared/domain/models/AlgorithmEngineVersion.js'; +import { CertificationCourse } from '../../../shared/domain/models/CertificationCourse.js'; +import { SessionVersion } from '../../../shared/domain/models/SessionVersion.js'; const { features } = config; @@ -33,7 +33,7 @@ const { features } = config; * @param {Object} params * @param {SessionRepository} params.sessionRepository * @param {AssessmentRepository} params.assessmentRepository - * @param {CertificationCandidateRepository} params.certificationCandidateRepository + * @param {CertificationCandidateRepository} params.sharedCertificationCandidateRepository * @param {CertificationCourseRepository} params.certificationCourseRepository * @param {UserRepository} params.userRepository * @param {PlacementProfileService} params.placementProfileService @@ -48,7 +48,7 @@ const retrieveLastOrCreateCertificationCourse = async function ({ userId, locale, assessmentRepository, - certificationCandidateRepository, + sharedCertificationCandidateRepository, certificationCourseRepository, sessionRepository, certificationCenterRepository, @@ -64,7 +64,7 @@ const retrieveLastOrCreateCertificationCourse = async function ({ _validateSessionAccess(session, accessCode); _validateSessionIsActive(session); - const certificationCandidate = await certificationCandidateRepository.getBySessionIdAndUserId({ + const certificationCandidate = await sharedCertificationCandidateRepository.getBySessionIdAndUserId({ userId, sessionId, }); @@ -81,7 +81,7 @@ const retrieveLastOrCreateCertificationCourse = async function ({ await _blockCandidateFromRestartingWithoutExplicitValidation( certificationCandidate, - certificationCandidateRepository, + sharedCertificationCandidateRepository, ); if (existingCertificationCourse) { @@ -164,10 +164,10 @@ function _validateCandidateIsAuthorizedToStart(certificationCandidate, existingC async function _blockCandidateFromRestartingWithoutExplicitValidation( certificationCandidate, - certificationCandidateRepository, + sharedCertificationCandidateRepository, ) { certificationCandidate.authorizedToStart = false; - await certificationCandidateRepository.update(certificationCandidate); + await sharedCertificationCandidateRepository.update(certificationCandidate); } /** @@ -200,7 +200,7 @@ async function _startNewCertification({ }) { let lang; if (SessionVersion.isV3(session.version)) { - const user = await userRepository.get(userId); + const user = await userRepository.get({ id: userId }); const isUserLanguageValid = _validateUserLanguage(languageService, user.lang); if (!isUserLanguageValid) { diff --git a/api/lib/infrastructure/serializers/jsonapi/certification-course-serializer.js b/api/src/certification/evaluation/infrastructure/serializers/certification-course-serializer.js similarity index 100% rename from api/lib/infrastructure/serializers/jsonapi/certification-course-serializer.js rename to api/src/certification/evaluation/infrastructure/serializers/certification-course-serializer.js diff --git a/api/src/certification/evaluation/routes.js b/api/src/certification/evaluation/routes.js index e4d51d82ad7..9fbddc468c5 100644 --- a/api/src/certification/evaluation/routes.js +++ b/api/src/certification/evaluation/routes.js @@ -1,5 +1,6 @@ import * as companionAlert from '../evaluation/application/companion-alert-route.js'; +import * as certificationCourseRoutes from './application/certification-course-route.js'; -const certificationEvaluationRoutes = [companionAlert]; +const certificationEvaluationRoutes = [companionAlert, certificationCourseRoutes]; export { certificationEvaluationRoutes }; diff --git a/api/src/certification/results/application/certification-results-controller.js b/api/src/certification/results/application/certification-results-controller.js index 74a6366c6f3..57aefea10cc 100644 --- a/api/src/certification/results/application/certification-results-controller.js +++ b/api/src/certification/results/application/certification-results-controller.js @@ -2,6 +2,8 @@ import dayjs from 'dayjs'; import { tokenService } from '../../../shared/domain/services/token-service.js'; import { usecases } from '../domain/usecases/index.js'; +import * as certifiedProfileRepository from '../infrastructure/repositories/certified-profile-repository.js'; +import * as certifiedProfileSerializer from '../infrastructure/serializers/certified-profile-serializer.js'; import { getCleaCertifiedCandidateCsv } from '../infrastructure/utils/csv/certification-results/get-clea-certified-candidate-csv.js'; import { getSessionCertificationResultsCsv } from '../infrastructure/utils/csv/certification-results/get-session-certification-results-csv.js'; @@ -69,10 +71,22 @@ const getSessionResultsToDownload = async function ( .header('Content-Disposition', `attachment; filename=${csvResult.filename}`); }; +const getCertifiedProfile = async function ( + request, + h, + dependencies = { certifiedProfileRepository, certifiedProfileSerializer }, +) { + const certificationCourseId = request.params.id; + //TODO add passthrough usecase to remove link between application and infrastructure + const certifiedProfile = await dependencies.certifiedProfileRepository.get(certificationCourseId); + return dependencies.certifiedProfileSerializer.serialize(certifiedProfile); +}; + const certificationResultsController = { getCleaCertifiedCandidateDataCsv, getSessionResultsByRecipientEmail, getSessionResultsToDownload, + getCertifiedProfile, }; export { certificationResultsController }; diff --git a/api/src/certification/results/application/certification-results-route.js b/api/src/certification/results/application/certification-results-route.js index a8e1b31615a..f8f05f104d3 100644 --- a/api/src/certification/results/application/certification-results-route.js +++ b/api/src/certification/results/application/certification-results-route.js @@ -1,11 +1,41 @@ import Joi from 'joi'; +import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; import { identifiersType } from '../../../shared/domain/types/identifiers-type.js'; import { authorization } from '../../shared/application/pre-handlers/authorization.js'; import { certificationResultsController } from './certification-results-controller.js'; const register = async function (server) { server.route([ + { + method: 'GET', + path: '/api/admin/certifications/{id}/certified-profile', + config: { + pre: [ + { + method: (request, h) => + securityPreHandlers.hasAtLeastOneAccessOf([ + securityPreHandlers.checkAdminMemberHasRoleSuperAdmin, + securityPreHandlers.checkAdminMemberHasRoleCertif, + securityPreHandlers.checkAdminMemberHasRoleSupport, + securityPreHandlers.checkAdminMemberHasRoleMetier, + ])(request, h), + assign: 'hasAuthorizationToAccessAdminScope', + }, + ], + validate: { + params: Joi.object({ + id: identifiersType.certificationCourseId, + }), + }, + handler: certificationResultsController.getCertifiedProfile, + tags: ['api'], + notes: [ + 'Cette route est utilisé par Pix Admin', + 'Elle permet de récupérer le profil certifié pour une certification donnée', + ], + }, + }, { method: 'GET', path: '/api/sessions/{sessionId}/certified-clea-candidate-data', diff --git a/api/lib/infrastructure/repositories/certified-profile-repository.js b/api/src/certification/results/infrastructure/repositories/certified-profile-repository.js similarity index 90% rename from api/lib/infrastructure/repositories/certified-profile-repository.js rename to api/src/certification/results/infrastructure/repositories/certified-profile-repository.js index a00685db3d1..88eff95a5a1 100644 --- a/api/lib/infrastructure/repositories/certified-profile-repository.js +++ b/api/src/certification/results/infrastructure/repositories/certified-profile-repository.js @@ -1,21 +1,21 @@ import _ from 'lodash'; -import { knex } from '../../../db/knex-database-connection.js'; -import { NotFoundError } from '../../../src/shared/domain/errors.js'; +import { knex } from '../../../../../db/knex-database-connection.js'; +import * as knowledgeElementRepository from '../../../../../lib/infrastructure/repositories/knowledge-element-repository.js'; +import { NotFoundError } from '../../../../../src/shared/domain/errors.js'; import { CertifiedArea, CertifiedCompetence, CertifiedProfile, CertifiedSkill, CertifiedTube, -} from '../../../src/shared/domain/read-models/CertifiedProfile.js'; +} from '../../../../../src/shared/domain/read-models/CertifiedProfile.js'; import { areaDatasource, competenceDatasource, skillDatasource, tubeDatasource, -} from '../../../src/shared/infrastructure/datasources/learning-content/index.js'; -import * as knowledgeElementRepository from './knowledge-element-repository.js'; +} from '../../../../../src/shared/infrastructure/datasources/learning-content/index.js'; const get = async function (certificationCourseId) { const certificationDatas = await knex diff --git a/api/lib/infrastructure/serializers/jsonapi/certified-profile-serializer.js b/api/src/certification/results/infrastructure/serializers/certified-profile-serializer.js similarity index 100% rename from api/lib/infrastructure/serializers/jsonapi/certified-profile-serializer.js rename to api/src/certification/results/infrastructure/serializers/certified-profile-serializer.js diff --git a/api/src/certification/session-management/application/certification-course-controller.js b/api/src/certification/session-management/application/certification-course-controller.js index 67db5b4fe48..b1d1383cb7e 100644 --- a/api/src/certification/session-management/application/certification-course-controller.js +++ b/api/src/certification/session-management/application/certification-course-controller.js @@ -1,5 +1,5 @@ import * as events from '../../../../lib/domain/events/index.js'; -import { usecases as libUsecases } from '../../../../lib/domain/usecases/index.js'; +import { usecases as certificationSharedUsecases } from '../../../../src/certification/shared/domain/usecases/index.js'; import { usecases } from '../domain/usecases/index.js'; import * as certificationSerializer from '../infrastructure/serializers/certification-serializer.js'; import * as juryCommentSerializer from '../infrastructure/serializers/jury-comment-serializer.js'; @@ -67,7 +67,7 @@ const update = async function (request, h, dependencies = { certificationSeriali userId, ); await usecases.correctCandidateIdentityInCertificationCourse({ command }); - const updatedCertificationCourse = await libUsecases.getCertificationCourse({ + const updatedCertificationCourse = await certificationSharedUsecases.getCertificationCourse({ certificationCourseId: command.certificationCourseId, }); return dependencies.certificationSerializer.serializeFromCertificationCourse(updatedCertificationCourse); diff --git a/api/lib/domain/usecases/get-certification-course.js b/api/src/certification/shared/domain/usecases/get-certification-course.js similarity index 100% rename from api/lib/domain/usecases/get-certification-course.js rename to api/src/certification/shared/domain/usecases/get-certification-course.js diff --git a/api/src/certification/shared/domain/usecases/index.js b/api/src/certification/shared/domain/usecases/index.js new file mode 100644 index 00000000000..79d3ea00ace --- /dev/null +++ b/api/src/certification/shared/domain/usecases/index.js @@ -0,0 +1,32 @@ +import { dirname, join } from 'node:path'; +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 * as certificationCourseRepository from '../../../shared/infrastructure/repositories/certification-course-repository.js'; + +/** + * @typedef {certificationCompanionAlertRepository} CertificationCompanionAlertRepository + */ + +const dependencies = { + certificationCourseRepository, +}; + +const path = dirname(fileURLToPath(import.meta.url)); + +/** + * Note : current ignoredFileNames are injected in * {@link file://./../../../shared/domain/usecases/index.js} + * This is in progress, because they should be injected in this file and not by shared sub-domain + * The only remaining file ignored should be index.js + */ +const usecasesWithoutInjectedDependencies = { + ...(await importNamedExportsFromDirectory({ + path: join(path, './'), + ignoredFileNames: ['index.js'], + })), +}; + +const usecases = injectDependencies(usecasesWithoutInjectedDependencies, dependencies); + +export { usecases }; diff --git a/api/src/certification/enrolment/infrastructure/repositories/certification-candidate-repository.js b/api/src/certification/shared/infrastructure/repositories/certification-candidate-repository.js similarity index 94% rename from api/src/certification/enrolment/infrastructure/repositories/certification-candidate-repository.js rename to api/src/certification/shared/infrastructure/repositories/certification-candidate-repository.js index 29f3aedbd11..96d88999731 100644 --- a/api/src/certification/enrolment/infrastructure/repositories/certification-candidate-repository.js +++ b/api/src/certification/shared/infrastructure/repositories/certification-candidate-repository.js @@ -1,8 +1,8 @@ import { knex } from '../../../../../db/knex-database-connection.js'; import { NotFoundError } from '../../../../shared/domain/errors.js'; import { CertificationCandidate } from '../../../../shared/domain/models/index.js'; -import { ComplementaryCertification } from '../../domain/models/ComplementaryCertification.js'; -import { Subscription } from '../../domain/models/Subscription.js'; +import { ComplementaryCertification } from '../../../enrolment/domain/models/ComplementaryCertification.js'; +import { Subscription } from '../../../enrolment/domain/models/Subscription.js'; const getBySessionIdAndUserId = async function ({ sessionId, userId }) { const candidateData = await _candidateBaseQuery().where({ sessionId, userId }).first(); diff --git a/api/src/certification/enrolment/infrastructure/repositories/user-repository.js b/api/src/certification/shared/infrastructure/repositories/user-repository.js similarity index 93% rename from api/src/certification/enrolment/infrastructure/repositories/user-repository.js rename to api/src/certification/shared/infrastructure/repositories/user-repository.js index cc6cdf41545..2c69366de2b 100644 --- a/api/src/certification/enrolment/infrastructure/repositories/user-repository.js +++ b/api/src/certification/shared/infrastructure/repositories/user-repository.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import { knex } from '../../../../../db/knex-database-connection.js'; import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.js'; -import { User } from '../../domain/models/User.js'; +import { User } from '../../../enrolment/domain/models/User.js'; export async function get({ id }) { const knexConn = DomainTransaction.getConnection(); diff --git a/api/tests/certification/enrolment/integration/infrastructure/repositories/certification-candidate-repository_test.js b/api/tests/certification/enrolment/integration/infrastructure/repositories/certification-candidate-repository_test.js index 2fb17201d02..46a1535f02b 100644 --- a/api/tests/certification/enrolment/integration/infrastructure/repositories/certification-candidate-repository_test.js +++ b/api/tests/certification/enrolment/integration/infrastructure/repositories/certification-candidate-repository_test.js @@ -1,8 +1,8 @@ import _ from 'lodash'; -import * as certificationCandidateRepository from '../../../../../../src/certification/enrolment/infrastructure/repositories/certification-candidate-repository.js'; import { ComplementaryCertification } from '../../../../../../src/certification/session-management/domain/models/ComplementaryCertification.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 { NotFoundError } from '../../../../../../src/shared/domain/errors.js'; import { catchErr, databaseBuilder, domainBuilder, expect, knex } from '../../../../../test-helper.js'; diff --git a/api/tests/certification/enrolment/integration/infrastructure/repositories/user-repository_test.js b/api/tests/certification/enrolment/integration/infrastructure/repositories/user-repository_test.js index 35d6ebbaf56..bb02bee6045 100644 --- a/api/tests/certification/enrolment/integration/infrastructure/repositories/user-repository_test.js +++ b/api/tests/certification/enrolment/integration/infrastructure/repositories/user-repository_test.js @@ -1,4 +1,4 @@ -import * as userRepository from '../../../../../../src/certification/enrolment/infrastructure/repositories/user-repository.js'; +import * as userRepository from '../../../../../../src/certification/shared/infrastructure/repositories/user-repository.js'; import { databaseBuilder, domainBuilder, expect } from '../../../../../test-helper.js'; describe('Integration | Repository | certification | enrolment | User', function () { diff --git a/api/tests/acceptance/application/certification-courses/certification-course-controller_test.js b/api/tests/certification/evaluation/acceptance/application/certification-courses/certification-course-controller_test.js similarity index 97% rename from api/tests/acceptance/application/certification-courses/certification-course-controller_test.js rename to api/tests/certification/evaluation/acceptance/application/certification-courses/certification-course-controller_test.js index ad2c6843e6d..59dfcedb1d4 100644 --- a/api/tests/acceptance/application/certification-courses/certification-course-controller_test.js +++ b/api/tests/certification/evaluation/acceptance/application/certification-courses/certification-course-controller_test.js @@ -1,10 +1,10 @@ -import { CertificationIssueReportCategory } from '../../../../src/certification/shared/domain/models/CertificationIssueReportCategory.js'; +import { CertificationIssueReportCategory } from '../../../../../../src/certification/shared/domain/models/CertificationIssueReportCategory.js'; import { SESSIONS_VERSIONS, SessionVersion, -} from '../../../../src/certification/shared/domain/models/SessionVersion.js'; -import { config } from '../../../../src/shared/config.js'; -import { KnowledgeElement } from '../../../../src/shared/domain/models/KnowledgeElement.js'; +} from '../../../../../../src/certification/shared/domain/models/SessionVersion.js'; +import { config } from '../../../../../../src/shared/config.js'; +import { KnowledgeElement } from '../../../../../../src/shared/domain/models/KnowledgeElement.js'; import { createServer, databaseBuilder, @@ -13,7 +13,7 @@ import { knex, learningContentBuilder, mockLearningContent, -} from '../../../test-helper.js'; +} from '../../../../../test-helper.js'; describe('Acceptance | API | Certification Course', function () { let server; diff --git a/api/tests/acceptance/application/certification-courses/index_test.js b/api/tests/certification/evaluation/acceptance/application/certification-courses/index_test.js similarity index 99% rename from api/tests/acceptance/application/certification-courses/index_test.js rename to api/tests/certification/evaluation/acceptance/application/certification-courses/index_test.js index d5bd18c0f41..3c840cf5622 100644 --- a/api/tests/acceptance/application/certification-courses/index_test.js +++ b/api/tests/certification/evaluation/acceptance/application/certification-courses/index_test.js @@ -6,7 +6,7 @@ import { knex, learningContentBuilder, mockLearningContent, -} from '../../../test-helper.js'; +} from '../../../../../test-helper.js'; describe('Acceptance | Route | Certification Courses', function () { let server; diff --git a/api/tests/integration/infrastructure/repositories/certified-profile-repository_test.js b/api/tests/certification/evaluation/integration/infrastructure/repositories/certified-profile-repository_test.js similarity index 95% rename from api/tests/integration/infrastructure/repositories/certified-profile-repository_test.js rename to api/tests/certification/evaluation/integration/infrastructure/repositories/certified-profile-repository_test.js index 7ceeec51089..8002452b48f 100644 --- a/api/tests/integration/infrastructure/repositories/certified-profile-repository_test.js +++ b/api/tests/certification/evaluation/integration/infrastructure/repositories/certified-profile-repository_test.js @@ -1,8 +1,8 @@ -import * as certifiedProfileRepository from '../../../../lib/infrastructure/repositories/certified-profile-repository.js'; -import { NotFoundError } from '../../../../src/shared/domain/errors.js'; -import { KnowledgeElement } from '../../../../src/shared/domain/models/KnowledgeElement.js'; -import { CertifiedProfile } from '../../../../src/shared/domain/read-models/CertifiedProfile.js'; -import { catchErr, databaseBuilder, domainBuilder, expect, mockLearningContent } from '../../../test-helper.js'; +import * as certifiedProfileRepository from '../../../../../../src/certification/results/infrastructure/repositories/certified-profile-repository.js'; +import { NotFoundError } from '../../../../../../src/shared/domain/errors.js'; +import { KnowledgeElement } from '../../../../../../src/shared/domain/models/KnowledgeElement.js'; +import { CertifiedProfile } from '../../../../../../src/shared/domain/read-models/CertifiedProfile.js'; +import { catchErr, databaseBuilder, domainBuilder, expect, mockLearningContent } from '../../../../../test-helper.js'; describe('Integration | Repository | Certified Profile', function () { describe('#get', function () { diff --git a/api/tests/unit/infrastructure/serializers/jsonapi/certification-course-serializer_test.js b/api/tests/certification/evaluation/integration/serializers/certification-course-serializer_test.js similarity index 97% rename from api/tests/unit/infrastructure/serializers/jsonapi/certification-course-serializer_test.js rename to api/tests/certification/evaluation/integration/serializers/certification-course-serializer_test.js index 2c5eb3964f5..a814e3a8695 100644 --- a/api/tests/unit/infrastructure/serializers/jsonapi/certification-course-serializer_test.js +++ b/api/tests/certification/evaluation/integration/serializers/certification-course-serializer_test.js @@ -1,4 +1,4 @@ -import * as serializer from '../../../../../lib/infrastructure/serializers/jsonapi/certification-course-serializer.js'; +import * as serializer from '../../../../../src/certification/evaluation/infrastructure/serializers/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'; diff --git a/api/tests/unit/application/certification-courses/index_test.js b/api/tests/certification/evaluation/unit/application/certification-courses-route_test.js similarity index 59% rename from api/tests/unit/application/certification-courses/index_test.js rename to api/tests/certification/evaluation/unit/application/certification-courses-route_test.js index 74244d1c26f..71f1f7f9a19 100644 --- a/api/tests/unit/application/certification-courses/index_test.js +++ b/api/tests/certification/evaluation/unit/application/certification-courses-route_test.js @@ -1,25 +1,9 @@ -import { certificationCourseController as certificationCoursesController } from '../../../../lib/application/certification-courses/certification-course-controller.js'; -import * as moduleUnderTest from '../../../../lib/application/certification-courses/index.js'; -import { securityPreHandlers } from '../../../../src/shared/application/security-pre-handlers.js'; -import { expect, HttpTestServer, sinon } from '../../../test-helper.js'; +import { certificationCourseController as certificationCoursesController } from '../../../../../src/certification/evaluation/application/certification-course-controller.js'; +import * as moduleUnderTest from '../../../../../src/certification/evaluation/application/certification-course-route.js'; +import { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js'; +import { expect, HttpTestServer, sinon } from '../../../../test-helper.js'; describe('Unit | Application | Certifications Course | Route', function () { - describe('GET /api/admin/certifications/{id}/certified-profile', function () { - it('should exist', async function () { - // given - sinon.stub(securityPreHandlers, 'hasAtLeastOneAccessOf').returns(() => true); - sinon.stub(certificationCoursesController, 'getCertifiedProfile').returns('ok'); - const httpTestServer = new HttpTestServer(); - await httpTestServer.register(moduleUnderTest); - - // when - const response = await httpTestServer.request('GET', '/api/admin/certifications/1234/certified-profile'); - - // then - expect(response.statusCode).to.equal(200); - }); - }); - describe('POST /api/certification-courses', function () { it('should return OK (200)', async function () { // given diff --git a/api/tests/unit/domain/usecases/get-certification-course_test.js b/api/tests/certification/evaluation/unit/domain/usecases/get-certification-course_test.js similarity index 72% rename from api/tests/unit/domain/usecases/get-certification-course_test.js rename to api/tests/certification/evaluation/unit/domain/usecases/get-certification-course_test.js index 622355df765..e4994cd9275 100644 --- a/api/tests/unit/domain/usecases/get-certification-course_test.js +++ b/api/tests/certification/evaluation/unit/domain/usecases/get-certification-course_test.js @@ -1,6 +1,6 @@ -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'; +import { CertificationCourse } from '../../../../../../src/certification/shared/domain/models/CertificationCourse.js'; +import { getCertificationCourse } from '../../../../../../src/certification/shared/domain/usecases/get-certification-course.js'; +import { expect, sinon } from '../../../../../test-helper.js'; describe('Unit | UseCase | get-certification-course', function () { let certificationCourse; diff --git a/api/tests/certification/results/unit/application/certification-results-controller_test.js b/api/tests/certification/results/unit/application/certification-results-controller_test.js index 1f061b191f5..8267ef524b7 100644 --- a/api/tests/certification/results/unit/application/certification-results-controller_test.js +++ b/api/tests/certification/results/unit/application/certification-results-controller_test.js @@ -130,4 +130,67 @@ describe('Certification | Results | Unit | Controller | certification results', expect(response.headers['Content-Disposition']).to.equal(`attachment; filename=${fileName}`); }); }); + + describe('#getCertifiedProfile', function () { + it('should fetch the associated certified profile serialized as JSONAPI', async function () { + const certifiedProfileSerializer = { + serialize: sinon.stub(), + }; + const certifiedProfileRepository = { + get: sinon.stub(), + }; + const skill1 = domainBuilder.buildCertifiedSkill({ + id: 'recSkill1', + name: 'skill_1', + hasBeenAskedInCertif: false, + tubeId: 'recTube1', + difficulty: 1, + }); + const skill2 = domainBuilder.buildCertifiedSkill({ + id: 'recSkill2', + name: 'skill_2', + hasBeenAskedInCertif: true, + tubeId: 'recTube1', + difficulty: 2, + }); + const tube1 = domainBuilder.buildCertifiedTube({ + id: 'recTube1', + name: 'tube_1', + competenceId: 'recCompetence1', + }); + const competence1 = domainBuilder.buildCertifiedCompetence({ + id: 'recCompetence1', + name: 'competence_1', + areaId: 'recArea1', + origin: 'Pix', + }); + const area1 = domainBuilder.buildCertifiedArea({ + id: 'recArea1', + name: 'area_1', + color: 'someColor', + }); + const certifiedProfile = domainBuilder.buildCertifiedProfile({ + id: 123, + userId: 456, + certifiedSkills: [skill1, skill2], + certifiedTubes: [tube1], + certifiedCompetences: [competence1], + certifiedAreas: [area1], + }); + certifiedProfileRepository.get.withArgs(123).resolves(certifiedProfile); + certifiedProfileSerializer.serialize.withArgs(certifiedProfile).resolves('ok'); + const request = { + params: { id: 123 }, + }; + + // when + const response = await certificationResultsController.getCertifiedProfile(request, hFake, { + certifiedProfileRepository, + certifiedProfileSerializer, + }); + + // then + expect(response).to.deep.equal('ok'); + }); + }); }); diff --git a/api/tests/certification/results/unit/application/certification-results-route_test.js b/api/tests/certification/results/unit/application/certification-results-route_test.js index f5f98c96a60..d89ae33f34e 100644 --- a/api/tests/certification/results/unit/application/certification-results-route_test.js +++ b/api/tests/certification/results/unit/application/certification-results-route_test.js @@ -1,9 +1,26 @@ import { certificationResultsController } from '../../../../../src/certification/results/application/certification-results-controller.js'; import * as moduleUnderTest from '../../../../../src/certification/results/application/certification-results-route.js'; import { authorization } from '../../../../../src/certification/shared/application/pre-handlers/authorization.js'; +import { securityPreHandlers } from '../../../../../src/shared/application/security-pre-handlers.js'; import { expect, HttpTestServer, sinon } from '../../../../test-helper.js'; describe('Certification | Results | Unit | Application | Certification Results Route', function () { + describe('GET /api/admin/certifications/{id}/certified-profile', function () { + it('should exist', async function () { + // given + sinon.stub(securityPreHandlers, 'hasAtLeastOneAccessOf').returns(() => true); + sinon.stub(certificationResultsController, 'getCertifiedProfile').returns('ok'); + const httpTestServer = new HttpTestServer(); + await httpTestServer.register(moduleUnderTest); + + // when + const response = await httpTestServer.request('GET', '/api/admin/certifications/1234/certified-profile'); + + // then + expect(response.statusCode).to.equal(200); + }); + }); + describe('GET /api/sessions/{sessionId}/certified-clea-candidate-data', function () { it('should exist', async function () { // given diff --git a/api/tests/unit/infrastructure/serializers/jsonapi/certified-profile-serializer_test.js b/api/tests/certification/results/unit/infrastructure/serializers/certified-profile-serializer_test.js similarity index 95% rename from api/tests/unit/infrastructure/serializers/jsonapi/certified-profile-serializer_test.js rename to api/tests/certification/results/unit/infrastructure/serializers/certified-profile-serializer_test.js index d46264f03b7..47fadbb22c2 100644 --- a/api/tests/unit/infrastructure/serializers/jsonapi/certified-profile-serializer_test.js +++ b/api/tests/certification/results/unit/infrastructure/serializers/certified-profile-serializer_test.js @@ -1,5 +1,5 @@ -import * as serializer from '../../../../../lib/infrastructure/serializers/jsonapi/certified-profile-serializer.js'; -import { domainBuilder, expect } from '../../../../test-helper.js'; +import * as serializer from '../../../../../../src/certification/results/infrastructure/serializers/certified-profile-serializer.js'; +import { domainBuilder, expect } from '../../../../../test-helper.js'; describe('Unit | Serializer | JSONAPI | certified-profile-serializer', function () { describe('#serialize', function () { diff --git a/api/tests/certification/session-management/unit/application/certification-course-controller_test.js b/api/tests/certification/session-management/unit/application/certification-course-controller_test.js index 8745ea83a9a..8adc8fda1f9 100644 --- a/api/tests/certification/session-management/unit/application/certification-course-controller_test.js +++ b/api/tests/certification/session-management/unit/application/certification-course-controller_test.js @@ -1,8 +1,8 @@ import { CertificationCourseRejected } from '../../../../../lib/domain/events/CertificationCourseRejected.js'; import { CertificationCourseUnrejected } from '../../../../../lib/domain/events/CertificationCourseUnrejected.js'; -import { usecases as libUsecases } from '../../../../../lib/domain/usecases/index.js'; import { certificationCourseController } from '../../../../../src/certification/session-management/application/certification-course-controller.js'; import { usecases } from '../../../../../src/certification/session-management/domain/usecases/index.js'; +import { usecases as certificationSharedUsecases } from '../../../../../src/certification/shared/domain/usecases/index.js'; import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js'; describe('Certification | Session Management | Unit | Application | Controller | Certification Course', function () { @@ -141,7 +141,7 @@ describe('Certification | Session Management | Unit | Application | Controller | // given sinon.stub(usecases, 'correctCandidateIdentityInCertificationCourse').resolves(); const updatedCertificationCourse = domainBuilder.buildCertificationCourse(); - sinon.stub(libUsecases, 'getCertificationCourse').resolves(updatedCertificationCourse); + sinon.stub(certificationSharedUsecases, 'getCertificationCourse').resolves(updatedCertificationCourse); certificationSerializer.deserializeCertificationCandidateModificationCommand.resolves({ firstName: 'Phil', lastName: 'Defer', @@ -181,7 +181,7 @@ describe('Certification | Session Management | Unit | Application | Controller | // given sinon.stub(usecases, 'correctCandidateIdentityInCertificationCourse').resolves(); const updatedCertificationCourse = domainBuilder.buildCertificationCourse(); - sinon.stub(libUsecases, 'getCertificationCourse').resolves(updatedCertificationCourse); + sinon.stub(certificationSharedUsecases, 'getCertificationCourse').resolves(updatedCertificationCourse); certificationSerializer.deserializeCertificationCandidateModificationCommand.resolves({ firstName: 'Phil', lastName: 'Defer', 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 a19e7050723..10b0c84a17c 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,12 +1,11 @@ -import { certificationCourseController } from '../../../../lib/application/certification-courses/certification-course-controller.js'; -import { usecases } from '../../../../lib/domain/usecases/index.js'; +import { certificationCourseController } from '../../../../src/certification/evaluation/application/certification-course-controller.js'; +import { usecases } from '../../../../src/certification/evaluation/domain/usecases/index.js'; import { CertificationCourse } from '../../../../src/certification/shared/domain/models/CertificationCourse.js'; -import { domainBuilder, expect, generateValidRequestAuthorizationHeader, hFake, sinon } from '../../../test-helper.js'; +import { usecases as certificationSharedUsecases } from '../../../../src/certification/shared/domain/usecases/index.js'; +import { expect, generateValidRequestAuthorizationHeader, hFake, sinon } from '../../../test-helper.js'; describe('Unit | Controller | certification-course-controller', function () { let certificationCourseSerializer; - let certifiedProfileSerializer; - let certifiedProfileRepository; let requestResponseUtils; beforeEach(function () { @@ -15,12 +14,6 @@ describe('Unit | Controller | certification-course-controller', function () { serializeFromCertificationCourse: sinon.stub(), deserializeCertificationCandidateModificationCommand: sinon.stub(), }; - certifiedProfileSerializer = { - serialize: sinon.stub(), - }; - certifiedProfileRepository = { - get: sinon.stub(), - }; requestResponseUtils = { extractLocaleFromRequest: sinon.stub() }; }); @@ -92,7 +85,10 @@ describe('Unit | Controller | certification-course-controller', function () { const certificationCourseId = 'certification_course_id'; const certificationCourse = new CertificationCourse({ id: certificationCourseId, sessionId }); const userId = 42; - sinon.stub(usecases, 'getCertificationCourse').withArgs({ certificationCourseId }).resolves(certificationCourse); + sinon + .stub(certificationSharedUsecases, 'getCertificationCourse') + .withArgs({ certificationCourseId }) + .resolves(certificationCourse); certificationCourseSerializer.serialize.withArgs(certificationCourse).resolves(certificationCourse); const request = { params: { id: certificationCourseId }, @@ -107,62 +103,4 @@ describe('Unit | Controller | certification-course-controller', function () { expect(response).to.deep.equal(certificationCourse); }); }); - - describe('#getCertifiedProfile', function () { - it('should fetch the associated certified profile serialized as JSONAPI', async function () { - // given - const skill1 = domainBuilder.buildCertifiedSkill({ - id: 'recSkill1', - name: 'skill_1', - hasBeenAskedInCertif: false, - tubeId: 'recTube1', - difficulty: 1, - }); - const skill2 = domainBuilder.buildCertifiedSkill({ - id: 'recSkill2', - name: 'skill_2', - hasBeenAskedInCertif: true, - tubeId: 'recTube1', - difficulty: 2, - }); - const tube1 = domainBuilder.buildCertifiedTube({ - id: 'recTube1', - name: 'tube_1', - competenceId: 'recCompetence1', - }); - const competence1 = domainBuilder.buildCertifiedCompetence({ - id: 'recCompetence1', - name: 'competence_1', - areaId: 'recArea1', - origin: 'Pix', - }); - const area1 = domainBuilder.buildCertifiedArea({ - id: 'recArea1', - name: 'area_1', - color: 'someColor', - }); - const certifiedProfile = domainBuilder.buildCertifiedProfile({ - id: 123, - userId: 456, - certifiedSkills: [skill1, skill2], - certifiedTubes: [tube1], - certifiedCompetences: [competence1], - certifiedAreas: [area1], - }); - certifiedProfileRepository.get.withArgs(123).resolves(certifiedProfile); - certifiedProfileSerializer.serialize.withArgs(certifiedProfile).resolves('ok'); - const request = { - params: { id: 123 }, - }; - - // when - const response = await certificationCourseController.getCertifiedProfile(request, hFake, { - certifiedProfileRepository, - certifiedProfileSerializer, - }); - - // then - expect(response).to.deep.equal('ok'); - }); - }); }); 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 06737f44dd4..bf61a2180ff 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 @@ -1,6 +1,6 @@ import _ from 'lodash'; -import { retrieveLastOrCreateCertificationCourse } from '../../../../lib/domain/usecases/retrieve-last-or-create-certification-course.js'; +import { retrieveLastOrCreateCertificationCourse } from '../../../../src/certification/evaluation/domain/usecases/retrieve-last-or-create-certification-course.js'; import { SessionNotAccessible } from '../../../../src/certification/session-management/domain/errors.js'; import { ComplementaryCertificationCourse } from '../../../../src/certification/session-management/domain/models/ComplementaryCertificationCourse.js'; import { AlgorithmEngineVersion } from '../../../../src/certification/shared/domain/models/AlgorithmEngineVersion.js'; @@ -25,7 +25,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi const sessionRepository = {}; const assessmentRepository = {}; const competenceRepository = {}; - const certificationCandidateRepository = {}; + const sharedCertificationCandidateRepository = {}; const certificationChallengeRepository = {}; const certificationChallengesService = {}; const certificationCourseRepository = {}; @@ -39,7 +39,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi const injectables = { assessmentRepository, competenceRepository, - certificationCandidateRepository, + sharedCertificationCandidateRepository, certificationChallengeRepository, certificationCourseRepository, sessionRepository, @@ -60,8 +60,8 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi assessmentRepository.save = sinon.stub(); competenceRepository.listPixCompetencesOnly = sinon.stub(); certificationBadgesService.findStillValidBadgeAcquisitions = sinon.stub(); - certificationCandidateRepository.getBySessionIdAndUserId = sinon.stub(); - certificationCandidateRepository.update = sinon.stub(); + sharedCertificationCandidateRepository.getBySessionIdAndUserId = sinon.stub(); + sharedCertificationCandidateRepository.update = sinon.stub(); certificationChallengeRepository.save = sinon.stub(); certificationChallengesService.pickCertificationChallengesForPixPlus = sinon.stub(); certificationChallengesService.pickCertificationChallenges = sinon.stub(); @@ -146,7 +146,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi authorizedToStart: false, subscriptions: [domainBuilder.buildCoreSubscription()], }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(candidateNotAuthorizedToStart); @@ -179,7 +179,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi authorizedToStart: false, subscriptions: [domainBuilder.buildCoreSubscription()], }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(candidateNotAuthorizedToStart); @@ -223,7 +223,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi subscriptions: [domainBuilder.buildCoreSubscription()], }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: foundCertificationCandidateId }) .resolves(null); @@ -256,7 +256,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi authorizedToStart: true, subscriptions: [domainBuilder.buildCoreSubscription()], }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(foundCertificationCandidate); @@ -287,7 +287,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi created: false, certificationCourse: existingCertificationCourse, }); - expect(certificationCandidateRepository.update).to.have.been.calledOnceWith( + expect(sharedCertificationCandidateRepository.update).to.have.been.calledOnceWith( domainBuilder.buildCertificationCandidate({ ...foundCertificationCandidate, authorizedToStart: false, @@ -313,7 +313,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi reconciledAt, }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(certificationCandidate); @@ -379,7 +379,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi subscriptions: [domainBuilder.buildCoreSubscription()], reconciledAt, }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(foundCertificationCandidate); @@ -474,7 +474,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi reconciledAt, }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: foundSession.id, userId: user.id }) .resolves(foundCertificationCandidate); @@ -528,7 +528,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi habilitations: [complementaryCertification], }); - userRepository.get.withArgs(user.id).resolves(user); + userRepository.get.withArgs({ id: user.id }).resolves(user); languageService.isLanguageAvailableForV3Certification.withArgs(user.lang).returns(true); certificationCenterRepository.getBySessionId.resolves(certificationCenter); @@ -614,7 +614,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi authorizedToStart: true, subscriptions: [domainBuilder.buildCoreSubscription()], }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId }) .resolves(foundCertificationCandidate); @@ -629,7 +629,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi certificationCenterRepository.getBySessionId.resolves(certificationCenter); const user = domainBuilder.buildUser({ id: userId, lang: 'nl' }); - userRepository.get.withArgs(userId).resolves(user); + userRepository.get.withArgs({ id: userId }).resolves(user); languageService.isLanguageAvailableForV3Certification.withArgs(user.lang).returns(false); @@ -668,7 +668,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi reconciledAt, accessibilityAdjustmentNeeded: true, }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId }) .resolves(foundCertificationCandidate); @@ -685,7 +685,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi certificationBadgesService.findStillValidBadgeAcquisitions.withArgs({ userId }).resolves([]); const user = domainBuilder.buildUser({ id: userId }); - userRepository.get.withArgs(userId).resolves(user); + userRepository.get.withArgs({ id: userId }).resolves(user); languageService.isLanguageAvailableForV3Certification.withArgs(user.lang).returns(true); @@ -789,7 +789,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi .withArgs(placementProfile) .resolves(_.flatMap(userCompetencesWithChallenges, 'challenges')); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(foundCertificationCandidate); @@ -911,7 +911,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi .withArgs(placementProfile) .resolves(_.flatMap(userCompetencesWithChallenges, 'challenges')); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(foundCertificationCandidate); @@ -1015,7 +1015,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi reconciledAt, }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(foundCertificationCandidate); @@ -1125,7 +1125,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi .withArgs(placementProfile) .resolves(_.flatMap(userCompetencesWithChallenges, 'challenges')); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(foundCertificationCandidate); @@ -1232,7 +1232,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi reconciledAt, }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(foundCertificationCandidate); @@ -1330,7 +1330,7 @@ describe('Unit | UseCase | retrieve-last-or-create-certification-course', functi reconciledAt, }); - certificationCandidateRepository.getBySessionIdAndUserId + sharedCertificationCandidateRepository.getBySessionIdAndUserId .withArgs({ sessionId: 1, userId: 2 }) .resolves(foundCertificationCandidate);