Skip to content

Commit

Permalink
bandeauV3: add certifiability check
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrecoin authored and laura-bergoens committed Sep 12, 2024
1 parent 177d38d commit 20152eb
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class UserCertificationEligibility {
constructor({ id, isCertifiable, certificationEligibilities = [] }) {
this.id = id;
this.isCertifiable = isCertifiable;
this.certificationEligibilities = certificationEligibilities;
}
}

class CertificationEligibility {
constructor({ label, imageUrl, isOutdated, isAcquiredExpectedLevel }) {
this.label = label;
this.imageUrl = imageUrl;
this.isOutdated = isOutdated;
this.isAcquiredExpectedLevel = isAcquiredExpectedLevel;
}
}

export { CertificationEligibility, UserCertificationEligibility };
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const getUserCertificationEligibility = async function () {
return true;
import { UserCertificationEligibility } from '../read-models/UserCertificationEligibility.js';

const getUserCertificationEligibility = async function ({ userId, limitDate, placementProfileService }) {
const placementProfile = await placementProfileService.getPlacementProfile({ userId, limitDate });
return new UserCertificationEligibility({
id: userId,
isCertifiable: placementProfile.isCertifiable(),
certificationEligibilities: [],
});
};

export { getUserCertificationEligibility };
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { getUserCertificationEligibility } from '../../../../../../src/certification/enrolment/domain/usecases/get-user-certification-eligibility.js';
import { domainBuilder, expect, sinon } from '../../../../../test-helper.js';

describe('Certification | Enrolment | Unit | Usecases | get-user-certification-eligibility', function () {
const userId = 123;
const limitDate = new Date('2024-09-06');
let dependencies;
const placementProfileService = {};

beforeEach(function () {
placementProfileService.getPlacementProfile = sinon.stub();
dependencies = {
userId,
limitDate,
placementProfileService,
};
});

context('certificability', function () {
context('when user is certifiable', function () {
it('returns a user certification eligibility with is certifiable set to true', async function () {
placementProfileService.getPlacementProfile.withArgs({ userId, limitDate }).resolves(
domainBuilder.buildPlacementProfile.buildCertifiable({
profileDate: limitDate,
userId,
}),
);

const userCertificationEligibility = await getUserCertificationEligibility(dependencies);

expect(userCertificationEligibility).to.deep.equal(
domainBuilder.certification.enrolment.buildUserCertificationEligibility({
id: userId,
isCertifiable: true,
certificationEligibilities: [],
}),
);
});
});
context('when user is not certifiable', function () {
it('returns a user certification eligibility with is certifiable set to false', async function () {
placementProfileService.getPlacementProfile.withArgs({ userId, limitDate }).resolves(
domainBuilder.buildPlacementProfile({
profileDate: limitDate,
userId,
userCompetences: [domainBuilder.buildUserCompetence({ estimatedLevel: 1, pixScore: 1 })],
}),
);

const userCertificationEligibility = await getUserCertificationEligibility(dependencies);

expect(userCertificationEligibility).to.deep.equal(
domainBuilder.certification.enrolment.buildUserCertificationEligibility({
id: userId,
isCertifiable: false,
certificationEligibilities: [],
}),
);
});
});
});
});
22 changes: 12 additions & 10 deletions api/tests/tooling/domain-builder/factory/build-placement-profile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash';

import { PlacementProfile } from '../../../../src/shared/domain/models/PlacementProfile.js';
import { PlacementProfile } from '../../../../src/shared/domain/models/index.js';
import { buildUserCompetence } from './build-user-competence.js';

const buildPlacementProfile = function buildPlacementProfile({
Expand Down Expand Up @@ -34,16 +34,18 @@ buildPlacementProfile.buildForCompetences = function buildForCompetences({ profi
};

buildPlacementProfile.buildCertifiable = function buildCertifiable({ profileDate, userId }) {
const userCompetences = Array(5).map((_, index) => {
return buildUserCompetence({
id: index,
index,
name: `competence_${index}`,
pixScore: 10_000,
estimatedLevel: 7,
const userCompetences = Array(5)
.fill()
.map((_, index) => {
return buildUserCompetence({
id: index,
index,
name: `competence_${index}`,
pixScore: 10_000,
estimatedLevel: 7,
});
});
});
return new PlacementProfile(profileDate, userId, userCompetences);
return new PlacementProfile({ profileDate, userId, userCompetences });
};

export { buildPlacementProfile };
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { UserCertificationEligibility } from '../../../../../../src/certification/enrolment/domain/read-models/UserCertificationEligibility.js';
import { domainBuilder } from '../../../domain-builder.js';

const buildUserCertificationEligibility = function ({
id = 123,
isCertifiable = false,
certificationEligibilities = [domainBuilder.certification.enrolment.buildV3UserCertificationEligibility()],
} = {}) {
return new UserCertificationEligibility({
id,
isCertifiable,
certificationEligibilities,
});
};

export { buildUserCertificationEligibility };
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CertificationEligibility } from '../../../../../../src/certification/enrolment/domain/read-models/UserCertificationEligibility.js';

const buildV3UserCertificationEligibility = function ({
label = "Label d'éligibilité",
imageUrl = "url d'image",
isOutdated = false,
isAcquiredExpectedLevel = true,
} = {}) {
return new CertificationEligibility({
label,
imageUrl,
isOutdated,
isAcquiredExpectedLevel,
});
};

export { buildV3UserCertificationEligibility };
2 changes: 2 additions & 0 deletions api/tests/tooling/domain-builder/factory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ import {
buildSubscription,
} from './certification/enrolment/build-subscription.js';
import { buildUserEnrolment } from './certification/enrolment/build-user.js';
import { buildUserCertificationEligibility } from './certification/enrolment/build-user-certification-eligibility.js';
import { buildFlashAssessmentAlgorithm } from './certification/flash-certification/build-flash-assessment-algorithm.js';
import { buildAssessmentResult as buildCertificationScoringAssessmentResult } from './certification/scoring/build-assessment-result.js';
import { buildCertificationAssessmentHistory } from './certification/scoring/build-certification-assessment-history.js';
Expand Down Expand Up @@ -221,6 +222,7 @@ const certification = {
buildUser: buildUserEnrolment,
buildCertificationEligibility: buildCertificationEligibilityEnrolment,
buildComplementaryCertificationCourseWithResults: buildComplementaryCertificationCourseWithResultsEnrolment,
buildUserCertificationEligibility,
},
sessionManagement: {
buildCertificationSessionComplementaryCertification,
Expand Down

0 comments on commit 20152eb

Please sign in to comment.