@@ -232,56 +232,112 @@ describe('Certification | Results | Unit | Application | Controller | certificat
232
232
clock . restore ( ) ;
233
233
} ) ;
234
234
235
- it ( 'should return binary attestations' , async function ( ) {
236
- // given
237
- const certifications = [
238
- domainBuilder . buildPrivateCertificateWithCompetenceTree ( ) ,
239
- domainBuilder . buildPrivateCertificateWithCompetenceTree ( ) ,
240
- ] ;
241
- const organizationId = domainBuilder . buildOrganization ( ) . id ;
242
- const division = '3b' ;
243
- const attestationsPDF = 'binary string' ;
244
- const userId = 1 ;
245
- const lang = FRENCH ;
246
- const i18n = getI18n ( ) ;
247
-
248
- const request = {
249
- i18n,
250
- auth : { credentials : { userId } } ,
251
- params : { organizationId } ,
252
- query : { division, isFrenchDomainExtension : true , lang } ,
253
- } ;
254
-
255
- sinon
256
- . stub ( usecases , 'findCertificationAttestationsForDivision' )
257
- . withArgs ( {
258
- division,
259
- organizationId,
260
- } )
261
- . resolves ( certifications ) ;
262
-
263
- const certificationAttestationPdfStub = {
264
- getCertificationAttestationsPdfBuffer : sinon . stub ( ) ,
265
- } ;
266
-
267
- const dependencies = {
268
- certificationAttestationPdf : certificationAttestationPdfStub ,
269
- } ;
270
-
271
- certificationAttestationPdfStub . getCertificationAttestationsPdfBuffer
272
- . withArgs ( { certificates : certifications , isFrenchDomainExtension : true , i18n } )
273
- . resolves ( { buffer : attestationsPDF } ) ;
274
-
275
- // when
276
- const response = await certificationAttestationController . downloadCertificationAttestationsForDivision (
277
- request ,
278
- hFake ,
279
- dependencies ,
280
- ) ;
281
-
282
- // then
283
- expect ( response . source ) . to . deep . equal ( attestationsPDF ) ;
284
- expect ( response . headers [ 'Content-Disposition' ] ) . to . contains ( 'attachment; filename=20190101_attestations_3b.pdf' ) ;
235
+ describe ( 'when attestations are for v3' , function ( ) {
236
+ it ( 'should return division attestations in PDF binary format' , async function ( ) {
237
+ // given
238
+ const userId = 1 ;
239
+ const i18n = getI18n ( ) ;
240
+
241
+ const v3CertificationAttestation = domainBuilder . certification . results . buildV3CertificationAttestation ( ) ;
242
+ const generatedPdf = Symbol ( 'Stream' ) ;
243
+
244
+ const organizationId = domainBuilder . buildOrganization ( ) . id ;
245
+ const division = '3ème b' ;
246
+
247
+ const request = {
248
+ i18n,
249
+ auth : { credentials : { userId } } ,
250
+ params : { organizationId } ,
251
+ query : { division, isFrenchDomainExtension : true , lang : FRENCH } ,
252
+ } ;
253
+
254
+ sinon
255
+ . stub ( usecases , 'findCertificationAttestationsForDivision' )
256
+ . withArgs ( {
257
+ division,
258
+ organizationId,
259
+ } )
260
+ . resolves ( [ v3CertificationAttestation , v3CertificationAttestation ] ) ;
261
+
262
+ const generatePdfStub = {
263
+ generate : sinon . stub ( ) . returns ( generatedPdf ) ,
264
+ } ;
265
+
266
+ // when
267
+ const response = await certificationAttestationController . downloadCertificationAttestationsForDivision (
268
+ request ,
269
+ hFake ,
270
+ {
271
+ v3CertificationAttestationPdf : generatePdfStub ,
272
+ } ,
273
+ ) ;
274
+
275
+ // then
276
+ expect ( generatePdfStub . generate ) . calledOnceWithExactly ( {
277
+ certificates : [ v3CertificationAttestation , v3CertificationAttestation ] ,
278
+ i18n,
279
+ } ) ;
280
+ expect ( response . source ) . to . deep . equal ( generatedPdf ) ;
281
+ expect ( response . headers [ 'Content-Disposition' ] ) . to . contains (
282
+ `attachment; filename=3eme-b-attestation-pix-${ dayjs ( v3CertificationAttestation . deliveredAt ) . format ( 'YYYYMMDD' ) } .pdf` ,
283
+ ) ;
284
+ } ) ;
285
+ } ) ;
286
+
287
+ describe ( 'when attestations are for v2' , function ( ) {
288
+ it ( 'should return binary attestations' , async function ( ) {
289
+ // given
290
+ const certifications = [
291
+ domainBuilder . buildPrivateCertificateWithCompetenceTree ( ) ,
292
+ domainBuilder . buildPrivateCertificateWithCompetenceTree ( ) ,
293
+ ] ;
294
+ const organizationId = domainBuilder . buildOrganization ( ) . id ;
295
+ const division = '3b' ;
296
+ const attestationsPDF = 'binary string' ;
297
+ const userId = 1 ;
298
+ const lang = FRENCH ;
299
+ const i18n = getI18n ( ) ;
300
+
301
+ const request = {
302
+ i18n,
303
+ auth : { credentials : { userId } } ,
304
+ params : { organizationId } ,
305
+ query : { division, isFrenchDomainExtension : true , lang } ,
306
+ } ;
307
+
308
+ sinon
309
+ . stub ( usecases , 'findCertificationAttestationsForDivision' )
310
+ . withArgs ( {
311
+ division,
312
+ organizationId,
313
+ } )
314
+ . resolves ( certifications ) ;
315
+
316
+ const certificationAttestationPdfStub = {
317
+ getCertificationAttestationsPdfBuffer : sinon . stub ( ) ,
318
+ } ;
319
+
320
+ const dependencies = {
321
+ certificationAttestationPdf : certificationAttestationPdfStub ,
322
+ } ;
323
+
324
+ certificationAttestationPdfStub . getCertificationAttestationsPdfBuffer
325
+ . withArgs ( { certificates : certifications , isFrenchDomainExtension : true , i18n } )
326
+ . resolves ( { buffer : attestationsPDF } ) ;
327
+
328
+ // when
329
+ const response = await certificationAttestationController . downloadCertificationAttestationsForDivision (
330
+ request ,
331
+ hFake ,
332
+ dependencies ,
333
+ ) ;
334
+
335
+ // then
336
+ expect ( response . source ) . to . deep . equal ( attestationsPDF ) ;
337
+ expect ( response . headers [ 'Content-Disposition' ] ) . to . contains (
338
+ 'attachment; filename=20190101_attestations_3b.pdf' ,
339
+ ) ;
340
+ } ) ;
285
341
} ) ;
286
342
} ) ;
287
343
} ) ;
0 commit comments