Skip to content

Commit

Permalink
feat: provides certification version in shareable certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
HEYGUL authored and P-Jeremy committed Nov 7, 2024
1 parent f63dce1 commit 378cd7a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ShareableCertificate {
certifiedBadgeImages,
resultCompetenceTree = null,
maxReachableLevelOnCertificationDate,
version,
} = {}) {
this.id = id;
this.firstName = firstName;
Expand All @@ -29,6 +30,7 @@ class ShareableCertificate {
this.certifiedBadgeImages = certifiedBadgeImages;
this.resultCompetenceTree = resultCompetenceTree;
this.maxReachableLevelOnCertificationDate = maxReachableLevelOnCertificationDate;
this.version = version;
}

setResultCompetenceTree(resultCompetenceTree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ function _selectShareableCertificates() {
maxReachableLevelOnCertificationDate: 'certification-courses.maxReachableLevelOnCertificationDate',
pixScore: 'assessment-results.pixScore',
assessmentResultId: 'assessment-results.id',
version: 'sessions.version',
competenceMarks: knex.raw(`
json_agg(
json_build_object('score', "competence-marks".score, 'level', "competence-marks".level, 'competence_code', "competence-marks"."competence_code")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const attributes = [
'resultCompetenceTree',
'certifiedBadgeImages',
'maxReachableLevelOnCertificationDate',
'version',
];

const serialize = function (certificate) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { generateCertificateVerificationCode } from '../../../../../lib/domain/services/verify-certificate-code-service.js';
import { AutoJuryCommentKeys } from '../../../../../src/certification/shared/domain/models/JuryComment.js';
import { SESSIONS_VERSIONS } from '../../../../../src/certification/shared/domain/models/SessionVersion.js';
import { Assessment } from '../../../../../src/shared/domain/models/Assessment.js';
import {
createServer,
Expand Down Expand Up @@ -428,15 +429,15 @@ describe('Certification | Results | Acceptance | Application | Certification', f
userId = databaseBuilder.factory.buildUser().id;
session = databaseBuilder.factory.buildSession({
publishedAt: new Date('2018-12-01T01:02:03Z'),
version: 3,
version: SESSIONS_VERSIONS.V3,
});
certificationCourse = databaseBuilder.factory.buildCertificationCourse({
sessionId: session.id,
userId,
isPublished: true,
maxReachableLevelOnCertificationDate: 3,
verificationCode: await generateCertificateVerificationCode(),
version: 3,
version: SESSIONS_VERSIONS.V3,
});

assessment = databaseBuilder.factory.buildAssessment({
Expand Down Expand Up @@ -638,6 +639,7 @@ describe('Certification | Results | Acceptance | Application | Certification', f
},
],
'max-reachable-level-on-certification-date': certificationCourse.maxReachableLevelOnCertificationDate,
version: session.version,
},
id: `${certificationCourse.id}`,
relationships: {
Expand Down Expand Up @@ -770,7 +772,10 @@ describe('Certification | Results | Acceptance | Application | Certification', f

async function _buildDatabaseForV2Certification() {
const userId = databaseBuilder.factory.buildUser().id;
const session = databaseBuilder.factory.buildSession({ publishedAt: new Date('2018-12-01T01:02:03Z') });
const session = databaseBuilder.factory.buildSession({
version: SESSIONS_VERSIONS.V2,
publishedAt: new Date('2018-12-01T01:02:03Z'),
});
const badge = databaseBuilder.factory.buildBadge({ key: 'charlotte_aux_fraises' });
const cc = databaseBuilder.factory.buildComplementaryCertification({ key: 'A' });
const ccBadge = databaseBuilder.factory.buildComplementaryCertificationBadge({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as certificateRepository from '../../../../../../src/certification/results/infrastructure/repositories/certificate-repository.js';
import { AlgorithmEngineVersion } from '../../../../../../src/certification/shared/domain/models/AlgorithmEngineVersion.js';
import { AutoJuryCommentKeys } from '../../../../../../src/certification/shared/domain/models/JuryComment.js';
import { SESSIONS_VERSIONS } from '../../../../../../src/certification/shared/domain/models/SessionVersion.js';
import { NotFoundError } from '../../../../../../src/shared/domain/errors.js';
import { status } from '../../../../../../src/shared/domain/models/AssessmentResult.js';
import {
Expand Down Expand Up @@ -2347,6 +2349,7 @@ 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 { certificationCourseId, assessmentResultId } = await _buildValidShareableCertificate(
Expand Down Expand Up @@ -2459,6 +2462,7 @@ 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 { certificationCourseId, assessmentResultId } = await _buildValidShareableCertificate(
Expand Down Expand Up @@ -2595,6 +2599,7 @@ describe('Integration | Infrastructure | Repository | Certification', function (
deliveredAt: new Date('2021-05-05'),
certificationCenter: 'Centre des poules bien dodues',
pixScore: 51,
version: SESSIONS_VERSIONS.V3,
certifiedBadgeImages: [
{
imageUrl: 'https://images.pix.fr/badge1.svg',
Expand Down Expand Up @@ -2969,6 +2974,7 @@ async function _buildValidPrivateCertificateWithAcquiredAndNotAcquiredBadges({
async function _buildValidShareableCertificate(shareableCertificateData, buildCompetenceMark = true) {
const certificationCenterId = databaseBuilder.factory.buildCertificationCenter().id;
const sessionId = databaseBuilder.factory.buildSession({
version: shareableCertificateData.version,
id: shareableCertificateData.sessionId,
publishedAt: shareableCertificateData.deliveredAt,
certificationCenter: shareableCertificateData.certificationCenter,
Expand All @@ -2987,6 +2993,7 @@ async function _buildValidShareableCertificate(shareableCertificateData, buildCo
maxReachableLevelOnCertificationDate: shareableCertificateData.maxReachableLevelOnCertificationDate,
sessionId,
userId: shareableCertificateData.userId,
version: shareableCertificateData.version,
}).id;

const assessmentResultId = databaseBuilder.factory.buildAssessmentResult.last({
Expand All @@ -3010,6 +3017,7 @@ async function _buildValidShareableCertificate(shareableCertificateData, buildCo
async function _buildValidShareableCertificateWithAcquiredBadges({ shareableCertificateData, acquiredBadges }) {
const certificationCenterId = databaseBuilder.factory.buildCertificationCenter().id;
const sessionId = databaseBuilder.factory.buildSession({
version: shareableCertificateData.version,
publishedAt: shareableCertificateData.deliveredAt,
certificationCenter: shareableCertificateData.certificationCenter,
certificationCenterId,
Expand All @@ -3027,6 +3035,7 @@ async function _buildValidShareableCertificateWithAcquiredBadges({ shareableCert
maxReachableLevelOnCertificationDate: shareableCertificateData.maxReachableLevelOnCertificationDate,
sessionId,
userId: shareableCertificateData.userId,
version: AlgorithmEngineVersion.V2,
}).id;
const assessmentResultId = databaseBuilder.factory.buildAssessmentResult.last({
certificationCourseId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { certificationController } from '../../../../../src/certification/results/application/certification-controller.js';
import { usecases } from '../../../../../src/certification/results/domain/usecases/index.js';
import { SESSIONS_VERSIONS } from '../../../../../src/certification/shared/domain/models/SessionVersion.js';
import { domainBuilder, expect, hFake, sinon } from '../../../../test-helper.js';
import { getI18n } from '../../../../tooling/i18n/i18n.js';

Expand All @@ -23,6 +24,7 @@ describe('Certification | Results | Unit | Application | certifications-controll
pixScore: 456,
certifiedBadgeImages: ['/img/1'],
maxReachableLevelOnCertificationDate: 6,
version: SESSIONS_VERSIONS.V3,
});
sinon.stub(usecases, 'getShareableCertificate');
usecases.getShareableCertificate
Expand Down Expand Up @@ -52,6 +54,7 @@ describe('Certification | Results | Unit | Application | certifications-controll
'pix-score': 456,
'certified-badge-images': ['/img/1'],
'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,6 +1,7 @@
import { ResultCompetence } from '../../../../../../src/certification/results/domain/models/ResultCompetence.js';
import { ResultCompetenceTree } from '../../../../../../src/certification/results/domain/models/ResultCompetenceTree.js';
import * as serializer from '../../../../../../src/certification/results/infrastructure/serializers/shareable-certificate-serializer.js';
import { SESSIONS_VERSIONS } from '../../../../../../src/certification/shared/domain/models/SessionVersion.js';
import { domainBuilder, expect } from '../../../../../test-helper.js';

describe('Unit | Serializer | JSONAPI | shareable-certificate-serializer', function () {
Expand Down Expand Up @@ -47,6 +48,7 @@ describe('Unit | Serializer | JSONAPI | shareable-certificate-serializer', funct
certifiedBadgeImages: ['/img/1', '/img/2'],
resultCompetenceTree,
maxReachableLevelOnCertificationDate: 6,
version: SESSIONS_VERSIONS.V3,
});

// when
Expand All @@ -68,6 +70,7 @@ describe('Unit | Serializer | JSONAPI | shareable-certificate-serializer', funct
'pix-score': 456,
'certified-badge-images': ['/img/1', '/img/2'],
'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
Expand Up @@ -15,6 +15,7 @@ const buildShareableCertificate = function ({
maxReachableLevelOnCertificationDate = 5,
certifiedBadgeImages = [],
resultCompetenceTree = null,
version = 3,
} = {}) {
return new ShareableCertificate({
id,
Expand All @@ -31,6 +32,7 @@ const buildShareableCertificate = function ({
maxReachableLevelOnCertificationDate,
resultCompetenceTree,
certifiedBadgeImages,
version,
});
};

Expand Down

0 comments on commit 378cd7a

Please sign in to comment.