Skip to content

Commit

Permalink
[FEATURE] Ajout du kit surveillant pour la certif V3 (pix-8814)
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Oct 27, 2023
2 parents 8f01793 + e4c6c3d commit 892b8e9
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 34 deletions.
1 change: 1 addition & 0 deletions api/lib/domain/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const PIX_CERTIF = {
NOT_LINKED_CERTIFICATION_MSG:
"L'accès à Pix Certif est limité aux centres de certification Pix. Contactez le référent de votre centre de certification si vous pensez avoir besoin d'y accéder.",
DEFAULT_SESSION_DURATION_MINUTES: 105,
CURRENT_CERTIFICATION_VERSION: 2,
};

const LOCALE = {
Expand Down
3 changes: 2 additions & 1 deletion api/lib/domain/read-models/SessionForSupervisorKit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SessionForSupervisorKit {
constructor({ id, date, time, address, room, examiner, accessCode, supervisorPassword }) {
constructor({ id, date, time, address, room, examiner, accessCode, supervisorPassword, version }) {
this.id = id;
this.date = date;
this.time = time;
Expand All @@ -8,6 +8,7 @@ class SessionForSupervisorKit {
this.examiner = examiner;
this.accessCode = accessCode;
this.supervisorPassword = supervisorPassword;
this.version = version;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const get = async function (idSession) {
'sessions.examiner',
'sessions.accessCode',
'sessions.supervisorPassword',
'sessions.version',
)
.from('sessions')
.where({ 'sessions.id': idSession })
Expand Down
Binary file not shown.
8 changes: 5 additions & 3 deletions api/lib/infrastructure/utils/pdf/supervisor-kit-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PDFDocument, rgb } from 'pdf-lib';

import pdfLibFontkit from '@pdf-lib/fontkit';
import * as url from 'url';
import { LOCALE } from '../../../domain/constants.js';
import { LOCALE, PIX_CERTIF } from '../../../domain/constants.js';

const { ENGLISH_SPOKEN, FRENCH_SPOKEN } = LOCALE;

Expand All @@ -13,6 +13,7 @@ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const MAX_SESSION_DETAIL_WIDTH = 155;
const SESSION_DETAIL_FONT_SIZE = 7;
const SESSION_DETAIL_LINE_HEIGHT = 8;
const { CURRENT_CERTIFICATION_VERSION } = PIX_CERTIF;

async function getSupervisorKitPdfBuffer({
sessionForSupervisorKit,
Expand All @@ -23,6 +24,7 @@ async function getSupervisorKitPdfBuffer({
} = {}) {
let templatePath;
let fileName;
const fileVersion = sessionForSupervisorKit.version === CURRENT_CERTIFICATION_VERSION ? '' : '-v3';

switch (lang) {
case ENGLISH_SPOKEN:
Expand All @@ -31,8 +33,8 @@ async function getSupervisorKitPdfBuffer({
break;

default:
templatePath = `${dirname}/files/kit-surveillant_template.pdf`;
fileName = `kit-surveillant-${sessionForSupervisorKit.id}.pdf`;
templatePath = `${dirname}/files/kit-surveillant_template${fileVersion}.pdf`;
fileName = `kit-surveillant-${sessionForSupervisorKit.id}${fileVersion}.pdf`;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('Integration | Repository | Session-for-supervisor-kit', function () {
time: '12:00:00',
accessCode: 'X23SR71',
supervisorPassword: 'NYX34',
version: 2,
});

// when
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,83 @@ describe('Integration | Infrastructure | Utils | Pdf | Certification supervisor
});

context('when lang is french', function () {
it('should return full french supervisor kit as a buffer', async function () {
// given
const lang = FRENCH_SPOKEN;
const sessionForSupervisorKit = domainBuilder.buildSessionForSupervisorKit({
id: 12345678,
supervisorPassword: 12344,
accessCode: 'WB64K2',
date: '2022-09-21',
examiner: 'Ariete Bordeauxchesnel',
});
const expectedPdfPath = __dirname + '/kit-surveillant_expected.pdf';
context('when session is V2', function () {
it('should return full french supervisor kit as a buffer', async function () {
// given
const lang = FRENCH_SPOKEN;
const sessionForSupervisorKit = domainBuilder.buildSessionForSupervisorKit({
id: 12345678,
supervisorPassword: 12344,
accessCode: 'WB64K2',
date: '2022-09-21',
examiner: 'Ariete Bordeauxchesnel',
});
const expectedPdfPath = __dirname + '/kit-surveillant_expected.pdf';

// when
const { buffer: actualSupervisorKitBuffer, fileName } = await getSupervisorKitPdfBuffer({
sessionForSupervisorKit,
lang,
creationDate: new Date('2021-01-01'),
// when
const { buffer: actualSupervisorKitBuffer, fileName } = await getSupervisorKitPdfBuffer({
sessionForSupervisorKit,
lang,
creationDate: new Date('2021-01-01'),
});

// Note: to update the reference pdf, you can run the test with the following lines.
//
// import { writeFile } from 'fs/promises';
// await writeFile(expectedPdfPath, actualSupervisorKitBuffer);

// then
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}.pdf`);
});

// Note: to update the reference pdf, you can run the test with the following lines.
//
// import { writeFile } from 'fs/promises';
// await writeFile(expectedPdfPath, actualSupervisorKitBuffer);
context('when session details contains long labels', function () {
it('should return full supervisor kit as a buffer with long labels in multiple lines', async function () {
// given
const lang = FRENCH_SPOKEN;
const sessionForSupervisorKit = domainBuilder.buildSessionForSupervisorKit({
id: 12345678,
supervisorPassword: 12344,
accessCode: 'WB64K2',
date: '2022-09-21',
examiner: 'Un nom très très très très très très très très très très long',
address: 'Une adresse qui ne tient pas sur une seule ligne',
room: 'Une salle particulièrement longue mais on ne sait jamais',
});
const expectedPdfPath = __dirname + '/kit-surveillant-with-long-labels_expected.pdf';

// then
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}.pdf`);
// when
const { buffer: actualSupervisorKitBuffer, fileName } = await getSupervisorKitPdfBuffer({
sessionForSupervisorKit,
lang,
creationDate: new Date('2021-01-01'),
});

// Note: to update the reference pdf, you can run the test with the following lines.
//
// import { writeFile } from 'fs/promises';
// await writeFile(expectedPdfPath, actualSupervisorKitBuffer);

// then
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}.pdf`);
});
});
});

context('when session details contains long labels', function () {
it('should return full supervisor kit as a buffer with long labels in multiple lines', async function () {
context('when session is V3', function () {
it('should return full french supervisor kit v3 pdf', async function () {
// given
const lang = FRENCH_SPOKEN;
const sessionForSupervisorKit = domainBuilder.buildSessionForSupervisorKit({
id: 12345678,
supervisorPassword: 12344,
accessCode: 'WB64K2',
date: '2022-09-21',
examiner: 'Un nom très très très très très très très très très très long',
address: 'Une adresse qui ne tient pas sur une seule ligne',
room: 'Une salle particulièrement longue mais on ne sait jamais',
examiner: 'Ariete Bordeauxchesnel',
version: 3,
});
const expectedPdfPath = __dirname + '/kit-surveillant-with-long-labels_expected.pdf';
const expectedPdfPath = __dirname + '/kit-surveillant_expected-v3.pdf';

// when
const { buffer: actualSupervisorKitBuffer, fileName } = await getSupervisorKitPdfBuffer({
Expand All @@ -73,7 +107,41 @@ describe('Integration | Infrastructure | Utils | Pdf | Certification supervisor

// then
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}.pdf`);
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}-v3.pdf`);
});

context('when session details contains long labels', function () {
it('should return full supervisor kit v3 with long labels in multiple lines', async function () {
// given
const lang = FRENCH_SPOKEN;
const sessionForSupervisorKit = domainBuilder.buildSessionForSupervisorKit({
id: 12345678,
supervisorPassword: 12344,
accessCode: 'WB64K2',
date: '2022-09-21',
examiner: 'Un nom très très très très très très très très très très long',
address: 'Une adresse qui ne tient pas sur une seule ligne',
room: 'Une salle particulièrement longue mais on ne sait jamais',
version: 3,
});
const expectedPdfPath = __dirname + '/kit-surveillant-with-long-labels_expected-v3.pdf';

// when
const { buffer: actualSupervisorKitBuffer, fileName } = await getSupervisorKitPdfBuffer({
sessionForSupervisorKit,
lang,
creationDate: new Date('2021-01-01'),
});

// Note: to update the reference pdf, you can run the test with the following lines.
//
// import { writeFile } from 'fs/promises';
// await writeFile(expectedPdfPath, actualSupervisorKitBuffer);

// then
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}-v3.pdf`);
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const buildSessionForSupervisorKit = function ({
time = '14:30',
accessCode = 'C3H6KL',
supervisorPassword = '3LME8',
version = 2,
} = {}) {
return new SessionForSupervisorKit({
id,
Expand All @@ -19,6 +20,7 @@ const buildSessionForSupervisorKit = function ({
time,
accessCode,
supervisorPassword,
version,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('Unit | UseCase | get-supervisor-kit-main-info', function () {
time: '10:53',
supervisorPassword: '12AB5',
accessCode: '1B3DE6',
version: 2,
}),
);
});
Expand Down

0 comments on commit 892b8e9

Please sign in to comment.