Skip to content

Commit

Permalink
♻️ refactor: move certif course to certification/evaluation context
Browse files Browse the repository at this point in the history
  • Loading branch information
yaf committed Nov 4, 2024
1 parent dd249ab commit 174bdc7
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 54 deletions.
2 changes: 0 additions & 2 deletions api/lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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';
Expand All @@ -27,7 +26,6 @@ const routes = [
certificationCenters,
certificationCenterInvitations,
certificationCenterMemberships,
certificationCourses,
certificationPointOfContacts,
certifications,
healthcheck,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
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 certifiedProfileRepository from '../infrastructure/repositories/certified-profile-repository.js';
import * as certificationCourseSerializer from '../infrastructure/serializers/certification-course-serializer.js';
import * as certifiedProfileSerializer from '../infrastructure/serializers/certified-profile-serializer.js';

const save = async function (request, h, dependencies = { extractLocaleFromRequest, certificationCourseSerializer }) {
const userId = request.auth.credentials.userId;
Expand All @@ -24,7 +25,7 @@ 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);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions api/src/certification/shared/domain/usecases/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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';

/**
* @typedef {certificationCompanionAlertRepository} CertificationCompanionAlertRepository
*/

const dependencies = {};

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 };
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -13,7 +13,7 @@ import {
knex,
learningContentBuilder,
mockLearningContent,
} from '../../../test-helper.js';
} from '../../../../../test-helper.js';

describe('Acceptance | API | Certification Course', function () {
let server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
knex,
learningContentBuilder,
mockLearningContent,
} from '../../../test-helper.js';
} from '../../../../../test-helper.js';

describe('Acceptance | Route | Certification Courses', function () {
let server;
Expand Down
Original file line number Diff line number Diff line change
@@ -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/evaluation/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 () {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as serializer from '../../../../../lib/infrastructure/serializers/jsonapi/certified-profile-serializer.js';
import * as serializer from '../../../../../src/certification/evaluation/infrastructure/serializers/certified-profile-serializer.js';
import { domainBuilder, expect } from '../../../../test-helper.js';

describe('Unit | Serializer | JSONAPI | certified-profile-serializer', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 () {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 { usecases as certificationSharedUsecases } from '../../../../src/certification/shared/domain/usecases/index.js';
import { domainBuilder, expect, generateValidRequestAuthorizationHeader, hFake, sinon } from '../../../test-helper.js';

describe('Unit | Controller | certification-course-controller', function () {
Expand Down Expand Up @@ -92,7 +93,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 },
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 174bdc7

Please sign in to comment.