Skip to content

Commit

Permalink
✨ api: add session version in private certificate
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume LAGORCE <[email protected]>
  • Loading branch information
P-Jeremy and HEYGUL committed Nov 7, 2024
1 parent 378cd7a commit d5b2e1b
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PrivateCertificate {
* @param {Object} props.resultCompetenceTree
* @param {string} props.verificationCode
* @param {Date} props.maxReachableLevelOnCertificationDate
* @param {number} props.version
*/
constructor({
id,
Expand All @@ -51,6 +52,7 @@ class PrivateCertificate {
resultCompetenceTree = null,
verificationCode,
maxReachableLevelOnCertificationDate,
version,
} = {}) {
this.id = id;
this.firstName = firstName;
Expand All @@ -69,6 +71,7 @@ class PrivateCertificate {
this.resultCompetenceTree = resultCompetenceTree;
this.verificationCode = verificationCode;
this.maxReachableLevelOnCertificationDate = maxReachableLevelOnCertificationDate;
this.version = version;
}

static buildFrom({
Expand All @@ -91,6 +94,7 @@ class PrivateCertificate {
maxReachableLevelOnCertificationDate,
assessmentResultStatus,
isCancelled,
version,
}) {
const status = _computeStatus(assessmentResultStatus, isCancelled);
const juryComment = new JuryComment({
Expand All @@ -116,6 +120,7 @@ class PrivateCertificate {
verificationCode,
maxReachableLevelOnCertificationDate,
status,
version,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ function _selectPrivateCertificates() {
json_build_object('score', "competence-marks".score, 'level', "competence-marks".level, 'competence_code', "competence-marks"."competence_code")
ORDER BY "competence-marks"."competence_code" asc
)`),
version: 'sessions.version',
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const attributes = [
'certifiedBadgeImages',
'verificationCode',
'maxReachableLevelOnCertificationDate',
'version',
];

const serialize = function (certificate, { translate }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ describe('Certification | Results | Acceptance | Application | Certification', f
],
'verification-code': certificationCourse.verificationCode,
'max-reachable-level-on-certification-date': certificationCourse.maxReachableLevelOnCertificationDate,
version: SESSIONS_VERSIONS.V2,
},
id: `${certificationCourse.id}`,
relationships: {
Expand Down Expand Up @@ -399,6 +400,7 @@ describe('Certification | Results | Acceptance | Application | Certification', f
'certified-badge-images': [],
'verification-code': certificationCourse.verificationCode,
'max-reachable-level-on-certification-date': certificationCourse.maxReachableLevelOnCertificationDate,
version: SESSIONS_VERSIONS.V2,
},
relationships: {
'result-competence-tree': {
Expand Down Expand Up @@ -488,6 +490,7 @@ describe('Certification | Results | Acceptance | Application | Certification', f
'certified-badge-images': [],
'verification-code': certificationCourse.verificationCode,
'max-reachable-level-on-certification-date': certificationCourse.maxReachableLevelOnCertificationDate,
version: SESSIONS_VERSIONS.V3,
},
relationships: {
'result-competence-tree': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,12 +1258,14 @@ describe('Integration | Infrastructure | Repository | Certification', function (
deliveredAt: new Date('2021-05-05'),
certificationCenter: 'Centre des poules bien dodues',
pixScore: 51,
version: SESSIONS_VERSIONS.V3,
};
const certificationCenterId = databaseBuilder.factory.buildCertificationCenter().id;
const sessionId = databaseBuilder.factory.buildSession({
publishedAt: privateCertificateData.deliveredAt,
certificationCenter: privateCertificateData.certificationCenter,
certificationCenterId,
version: SESSIONS_VERSIONS.V3,
}).id;
const certificationCourseId = databaseBuilder.factory.buildCertificationCourse({
firstName: privateCertificateData.firstName,
Expand Down Expand Up @@ -1415,6 +1417,7 @@ describe('Integration | Infrastructure | Repository | Certification', function (
certificationCenter: 'Centre des poules bien dodues',
pixScore: 51,
commentForCandidate: 'Il aime beaucoup les mangues, et ça se voit !',
version: SESSIONS_VERSIONS.V3,
};

const { certificationCourseId } = await _buildValidPrivateCertificate(privateCertificateData);
Expand Down Expand Up @@ -1471,6 +1474,7 @@ describe('Integration | Infrastructure | Repository | Certification', function (
certificationCenter: 'Centre des poules bien dodues',
pixScore: 51,
commentForCandidate: 'Il aime beaucoup les mangues, et ça se voit !',
version: SESSIONS_VERSIONS.V3,
};

const { certificationCourseId } = await _buildValidPrivateCertificateWithSeveralResults(privateCertificateData);
Expand Down Expand Up @@ -1729,6 +1733,7 @@ describe('Integration | Infrastructure | Repository | Certification', function (
certificationCenter: 'Centre des poules bien dodues',
pixScore: 51,
commentForCandidate: 'Il aime beaucoup les mangues, et ça se voit !',
version: SESSIONS_VERSIONS.V3,
};

const { certificationCourseId } = await _buildValidPrivateCertificate(privateCertificateData);
Expand Down Expand Up @@ -2064,6 +2069,7 @@ describe('Integration | Infrastructure | Repository | Certification', function (
message: 'temporary message badge 2',
},
],
version: SESSIONS_VERSIONS.V3,
};

const { certificationCourseId } = await _buildValidPrivateCertificateWithAcquiredAndNotAcquiredBadges({
Expand Down Expand Up @@ -2728,6 +2734,7 @@ async function _buildValidPrivateCertificate(privateCertificateData, buildCompet
publishedAt: privateCertificateData.deliveredAt,
certificationCenter: privateCertificateData.certificationCenter,
certificationCenterId,
version: SESSIONS_VERSIONS.V3,
}).id;
const certificationCourseId = databaseBuilder.factory.buildCertificationCourse({
firstName: privateCertificateData.firstName,
Expand Down Expand Up @@ -2768,6 +2775,7 @@ async function _buildValidPrivateCertificateWithSeveralResults(privateCertificat
publishedAt: privateCertificateData.deliveredAt,
certificationCenter: privateCertificateData.certificationCenter,
certificationCenterId,
version: SESSIONS_VERSIONS.V3,
}).id;
const certificationCourseId = databaseBuilder.factory.buildCertificationCourse({
firstName: privateCertificateData.firstName,
Expand Down Expand Up @@ -2913,6 +2921,7 @@ async function _buildValidPrivateCertificateWithAcquiredAndNotAcquiredBadges({
publishedAt: privateCertificateData.deliveredAt,
certificationCenter: privateCertificateData.certificationCenter,
certificationCenterId,
version: SESSIONS_VERSIONS.V3,
}).id;
const certificationCourseId = databaseBuilder.factory.buildCertificationCourse({
firstName: privateCertificateData.firstName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('Certification | Results | Unit | Application | certifications-controll
certifiedBadgeImages: [],
verificationCode: 'P-SUPERCODE',
maxReachableLevelOnCertificationDate: 6,
version: SESSIONS_VERSIONS.V3,
});
sinon.stub(usecases, 'getPrivateCertificate');
usecases.getPrivateCertificate.withArgs({ userId, certificationCourseId, locale }).resolves(privateCertificate);
Expand Down Expand Up @@ -123,6 +124,7 @@ describe('Certification | Results | Unit | Application | certifications-controll
'certified-badge-images': [],
'verification-code': 'P-SUPERCODE',
'max-reachable-level-on-certification-date': 6,
version: SESSIONS_VERSIONS.V3,
},
relationships: {
'result-competence-tree': {
Expand Down Expand Up @@ -154,6 +156,7 @@ describe('Certification | Results | Unit | Application | certifications-controll
certifiedBadgeImages: [],
verificationCode: 'P-SUPERCODE',
maxReachableLevelOnCertificationDate: 6,
version: SESSIONS_VERSIONS.V3,
});
sinon.stub(usecases, 'findUserPrivateCertificates');
usecases.findUserPrivateCertificates.withArgs({ userId }).resolves([privateCertificate1]);
Expand Down Expand Up @@ -182,6 +185,7 @@ describe('Certification | Results | Unit | Application | certifications-controll
'certified-badge-images': [],
'verification-code': 'P-SUPERCODE',
'max-reachable-level-on-certification-date': 6,
version: SESSIONS_VERSIONS.V3,
},
relationships: {
'result-competence-tree': {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import { PrivateCertificate } from '../../../../../../src/certification/results/domain/models/PrivateCertificate.js';
import { AutoJuryCommentKeys } from '../../../../../../src/certification/shared/domain/models/JuryComment.js';
import { SESSIONS_VERSIONS } from '../../../../../../src/certification/shared/domain/models/SessionVersion.js';
import { status as assessmentResultStatuses } from '../../../../../../src/shared/domain/models/AssessmentResult.js';
import { domainBuilder, expect } from '../../../../../test-helper.js';

describe('Unit | Domain | Models | PrivateCertificate', function () {
context('#static buildFrom', function () {
const commonData = {
id: 1,
firstName: 'Jean',
lastName: 'Bon',
birthdate: '2000-03-20',
birthplace: 'Sarajevo',
isPublished: true,
userId: 123,
date: '2019-01-01',
deliveredAt: new Date('2019-05-05'),
certificationCenter: 'Centre des fruits et légumes',
pixScore: 250,
commentForCandidate: 'Bravo !',
commentByAutoJury: null,
certifiedBadgeImages: [],
resultCompetenceTree: null,
verificationCode: 'someVerifCode',
maxReachableLevelOnCertificationDate: 5,
};
let commonData;

beforeEach(function () {
commonData = {
id: 1,
firstName: 'Jean',
lastName: 'Bon',
birthdate: '2000-03-20',
birthplace: 'Sarajevo',
isPublished: true,
userId: 123,
date: '2019-01-01',
deliveredAt: new Date('2019-05-05'),
certificationCenter: 'Centre des fruits et légumes',
pixScore: 250,
commentForCandidate: 'Bravo !',
commentByAutoJury: null,
certifiedBadgeImages: [],
resultCompetenceTree: null,
verificationCode: 'someVerifCode',
maxReachableLevelOnCertificationDate: 5,
version: SESSIONS_VERSIONS.V3,
};
});

it('builds a cancelled PrivateCertificate', async function () {
// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ResultCompetence } from '../../../../../../src/certification/results/do
import { ResultCompetenceTree } from '../../../../../../src/certification/results/domain/models/ResultCompetenceTree.js';
import * as serializer from '../../../../../../src/certification/results/infrastructure/serializers/private-certificate-serializer.js';
import { AutoJuryCommentKeys } from '../../../../../../src/certification/shared/domain/models/JuryComment.js';
import { SESSIONS_VERSIONS } from '../../../../../../src/certification/shared/domain/models/SessionVersion.js';
import { domainBuilder, expect } from '../../../../../test-helper.js';
import { getI18n } from '../../../../../tooling/i18n/i18n.js';

Expand All @@ -26,6 +27,7 @@ describe('Certification | Results | Unit | Infrastructure | Serializers | privat
certifiedBadgeImages: ['/img/1', '/img/2'],
verificationCode: 'P-SUPERCODE',
maxReachableLevelOnCertificationDate: 6,
version: SESSIONS_VERSIONS.V3,
};
});

Expand Down Expand Up @@ -85,6 +87,7 @@ describe('Certification | Results | Unit | Infrastructure | Serializers | privat
'certified-badge-images': ['/img/1', '/img/2'],
'verification-code': 'P-SUPERCODE',
'max-reachable-level-on-certification-date': 6,
version: SESSIONS_VERSIONS.V3,
},
relationships: {
'result-competence-tree': {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PrivateCertificate } from '../../../../src/certification/results/domain/models/PrivateCertificate.js';
import { JuryComment, JuryCommentContexts } from '../../../../src/certification/shared/domain/models/JuryComment.js';
import { SESSIONS_VERSIONS } from '../../../../src/certification/shared/domain/models/SessionVersion.js';

const buildPrivateCertificate = function ({
id = 1,
Expand All @@ -20,6 +21,7 @@ const buildPrivateCertificate = function ({
resultCompetenceTree = null,
verificationCode = 'P-BBBCCCDD',
maxReachableLevelOnCertificationDate = 5,
version = SESSIONS_VERSIONS.V3,
} = {}) {
const juryComment = new JuryComment({
commentByAutoJury,
Expand All @@ -44,6 +46,7 @@ const buildPrivateCertificate = function ({
certifiedBadgeImages,
verificationCode,
maxReachableLevelOnCertificationDate,
version,
});
};

Expand All @@ -65,6 +68,7 @@ buildPrivateCertificate.cancelled = function ({
resultCompetenceTree,
verificationCode,
maxReachableLevelOnCertificationDate,
version,
}) {
return buildPrivateCertificate({
id,
Expand All @@ -85,6 +89,7 @@ buildPrivateCertificate.cancelled = function ({
verificationCode,
maxReachableLevelOnCertificationDate,
status: PrivateCertificate.status.CANCELLED,
version,
});
};

Expand All @@ -106,6 +111,7 @@ buildPrivateCertificate.validated = function ({
resultCompetenceTree,
verificationCode,
maxReachableLevelOnCertificationDate,
version,
}) {
return buildPrivateCertificate({
id,
Expand All @@ -126,6 +132,7 @@ buildPrivateCertificate.validated = function ({
verificationCode,
maxReachableLevelOnCertificationDate,
status: PrivateCertificate.status.VALIDATED,
version,
});
};

Expand All @@ -147,6 +154,7 @@ buildPrivateCertificate.rejected = function ({
resultCompetenceTree,
verificationCode,
maxReachableLevelOnCertificationDate,
version,
}) {
return buildPrivateCertificate({
id,
Expand All @@ -167,6 +175,7 @@ buildPrivateCertificate.rejected = function ({
verificationCode,
maxReachableLevelOnCertificationDate,
status: PrivateCertificate.status.REJECTED,
version,
});
};

Expand All @@ -188,6 +197,7 @@ buildPrivateCertificate.error = function ({
resultCompetenceTree,
verificationCode,
maxReachableLevelOnCertificationDate,
version,
}) {
return buildPrivateCertificate({
id,
Expand All @@ -208,6 +218,7 @@ buildPrivateCertificate.error = function ({
verificationCode,
maxReachableLevelOnCertificationDate,
status: PrivateCertificate.status.ERROR,
version,
});
};

Expand All @@ -229,6 +240,7 @@ buildPrivateCertificate.started = function ({
resultCompetenceTree,
verificationCode,
maxReachableLevelOnCertificationDate,
version,
}) {
return buildPrivateCertificate({
id,
Expand All @@ -249,6 +261,7 @@ buildPrivateCertificate.started = function ({
verificationCode,
maxReachableLevelOnCertificationDate,
status: PrivateCertificate.status.STARTED,
version,
});
};

Expand Down

0 comments on commit d5b2e1b

Please sign in to comment.