Skip to content

Commit 892b8e9

Browse files
[FEATURE] Ajout du kit surveillant pour la certif V3 (pix-8814)
#7336
2 parents 8f01793 + e4c6c3d commit 892b8e9

11 files changed

+111
-34
lines changed

api/lib/domain/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const PIX_CERTIF = {
4848
NOT_LINKED_CERTIFICATION_MSG:
4949
"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.",
5050
DEFAULT_SESSION_DURATION_MINUTES: 105,
51+
CURRENT_CERTIFICATION_VERSION: 2,
5152
};
5253

5354
const LOCALE = {

api/lib/domain/read-models/SessionForSupervisorKit.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class SessionForSupervisorKit {
2-
constructor({ id, date, time, address, room, examiner, accessCode, supervisorPassword }) {
2+
constructor({ id, date, time, address, room, examiner, accessCode, supervisorPassword, version }) {
33
this.id = id;
44
this.date = date;
55
this.time = time;
@@ -8,6 +8,7 @@ class SessionForSupervisorKit {
88
this.examiner = examiner;
99
this.accessCode = accessCode;
1010
this.supervisorPassword = supervisorPassword;
11+
this.version = version;
1112
}
1213
}
1314

api/lib/infrastructure/repositories/sessions/session-for-supervisor-kit-repository.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const get = async function (idSession) {
1212
'sessions.examiner',
1313
'sessions.accessCode',
1414
'sessions.supervisorPassword',
15+
'sessions.version',
1516
)
1617
.from('sessions')
1718
.where({ 'sessions.id': idSession })
Binary file not shown.

api/lib/infrastructure/utils/pdf/supervisor-kit-pdf.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PDFDocument, rgb } from 'pdf-lib';
44

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

99
const { ENGLISH_SPOKEN, FRENCH_SPOKEN } = LOCALE;
1010

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

1718
async function getSupervisorKitPdfBuffer({
1819
sessionForSupervisorKit,
@@ -23,6 +24,7 @@ async function getSupervisorKitPdfBuffer({
2324
} = {}) {
2425
let templatePath;
2526
let fileName;
27+
const fileVersion = sessionForSupervisorKit.version === CURRENT_CERTIFICATION_VERSION ? '' : '-v3';
2628

2729
switch (lang) {
2830
case ENGLISH_SPOKEN:
@@ -31,8 +33,8 @@ async function getSupervisorKitPdfBuffer({
3133
break;
3234

3335
default:
34-
templatePath = `${dirname}/files/kit-surveillant_template.pdf`;
35-
fileName = `kit-surveillant-${sessionForSupervisorKit.id}.pdf`;
36+
templatePath = `${dirname}/files/kit-surveillant_template${fileVersion}.pdf`;
37+
fileName = `kit-surveillant-${sessionForSupervisorKit.id}${fileVersion}.pdf`;
3638
break;
3739
}
3840

api/tests/integration/infrastructure/repositories/sessions/session-for-supervisor-kit-repository_test.js

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('Integration | Repository | Session-for-supervisor-kit', function () {
3939
time: '12:00:00',
4040
accessCode: 'X23SR71',
4141
supervisorPassword: 'NYX34',
42+
version: 2,
4243
});
4344

4445
// when
Binary file not shown.

api/tests/integration/infrastructure/utils/pdf/supervisor-kit-pdf_test.js

+98-30
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,83 @@ describe('Integration | Infrastructure | Utils | Pdf | Certification supervisor
1515
});
1616

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

30-
// when
31-
const { buffer: actualSupervisorKitBuffer, fileName } = await getSupervisorKitPdfBuffer({
32-
sessionForSupervisorKit,
33-
lang,
34-
creationDate: new Date('2021-01-01'),
31+
// when
32+
const { buffer: actualSupervisorKitBuffer, fileName } = await getSupervisorKitPdfBuffer({
33+
sessionForSupervisorKit,
34+
lang,
35+
creationDate: new Date('2021-01-01'),
36+
});
37+
38+
// Note: to update the reference pdf, you can run the test with the following lines.
39+
//
40+
// import { writeFile } from 'fs/promises';
41+
// await writeFile(expectedPdfPath, actualSupervisorKitBuffer);
42+
43+
// then
44+
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
45+
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}.pdf`);
3546
});
3647

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

42-
// then
43-
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
44-
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}.pdf`);
63+
// when
64+
const { buffer: actualSupervisorKitBuffer, fileName } = await getSupervisorKitPdfBuffer({
65+
sessionForSupervisorKit,
66+
lang,
67+
creationDate: new Date('2021-01-01'),
68+
});
69+
70+
// Note: to update the reference pdf, you can run the test with the following lines.
71+
//
72+
// import { writeFile } from 'fs/promises';
73+
// await writeFile(expectedPdfPath, actualSupervisorKitBuffer);
74+
75+
// then
76+
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
77+
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}.pdf`);
78+
});
79+
});
4580
});
4681

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

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

74108
// then
75109
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
76-
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}.pdf`);
110+
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}-v3.pdf`);
111+
});
112+
113+
context('when session details contains long labels', function () {
114+
it('should return full supervisor kit v3 with long labels in multiple lines', async function () {
115+
// given
116+
const lang = FRENCH_SPOKEN;
117+
const sessionForSupervisorKit = domainBuilder.buildSessionForSupervisorKit({
118+
id: 12345678,
119+
supervisorPassword: 12344,
120+
accessCode: 'WB64K2',
121+
date: '2022-09-21',
122+
examiner: 'Un nom très très très très très très très très très très long',
123+
address: 'Une adresse qui ne tient pas sur une seule ligne',
124+
room: 'Une salle particulièrement longue mais on ne sait jamais',
125+
version: 3,
126+
});
127+
const expectedPdfPath = __dirname + '/kit-surveillant-with-long-labels_expected-v3.pdf';
128+
129+
// when
130+
const { buffer: actualSupervisorKitBuffer, fileName } = await getSupervisorKitPdfBuffer({
131+
sessionForSupervisorKit,
132+
lang,
133+
creationDate: new Date('2021-01-01'),
134+
});
135+
136+
// Note: to update the reference pdf, you can run the test with the following lines.
137+
//
138+
// import { writeFile } from 'fs/promises';
139+
// await writeFile(expectedPdfPath, actualSupervisorKitBuffer);
140+
141+
// then
142+
expect(await isSameBinary(expectedPdfPath, actualSupervisorKitBuffer)).to.be.true;
143+
expect(fileName).to.equal(`kit-surveillant-${sessionForSupervisorKit.id}-v3.pdf`);
144+
});
77145
});
78146
});
79147
});

api/tests/tooling/domain-builder/factory/build-session-for-supervisor-kit.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const buildSessionForSupervisorKit = function ({
99
time = '14:30',
1010
accessCode = 'C3H6KL',
1111
supervisorPassword = '3LME8',
12+
version = 2,
1213
} = {}) {
1314
return new SessionForSupervisorKit({
1415
id,
@@ -19,6 +20,7 @@ const buildSessionForSupervisorKit = function ({
1920
time,
2021
accessCode,
2122
supervisorPassword,
23+
version,
2224
});
2325
};
2426

api/tests/unit/domain/usecases/get-supervisor-kit-session-info_test.js

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('Unit | UseCase | get-supervisor-kit-main-info', function () {
4444
time: '10:53',
4545
supervisorPassword: '12AB5',
4646
accessCode: '1B3DE6',
47+
version: 2,
4748
}),
4849
);
4950
});

0 commit comments

Comments
 (0)