@@ -2,8 +2,10 @@ import { readFile } from 'node:fs/promises';
2
2
import * as url from 'node:url' ;
3
3
4
4
import { generateCertificateVerificationCode } from '../../../../../src/certification/evaluation/domain/services/verify-certificate-code-service.js' ;
5
+ import { SESSIONS_VERSIONS } from '../../../../../src/certification/shared/domain/models/SessionVersion.js' ;
5
6
import { Assessment } from '../../../../../src/shared/domain/models/index.js' ;
6
7
import { AssessmentResult , Membership } from '../../../../../src/shared/domain/models/index.js' ;
8
+ import { featureToggles } from '../../../../../src/shared/infrastructure/feature-toggles/index.js' ;
7
9
import {
8
10
createServer ,
9
11
databaseBuilder ,
@@ -112,26 +114,79 @@ describe('Certification | Results | Acceptance | Application | Routes | certific
112
114
113
115
describe ( 'GET /api/attestation/{certificationCourseId}' , function ( ) {
114
116
context ( 'when user own the certification' , function ( ) {
115
- it ( 'should return 200 HTTP status code and the certification' , async function ( ) {
116
- // given
117
- const userId = databaseBuilder . factory . buildUser ( ) . id ;
118
- await _buildDatabaseForV2Certification ( { userId, certificationCourseId : 1234 } ) ;
119
- await databaseBuilder . commit ( ) ;
120
-
121
- const server = await createServer ( ) ;
122
-
123
- // when
124
- const response = await server . inject ( {
125
- method : 'GET' ,
126
- url : '/api/attestation/1234?isFrenchDomainExtension=true&lang=fr' ,
127
- headers : generateAuthenticatedUserRequestHeaders ( { userId } ) ,
117
+ context ( 'when session version is V3' , function ( ) {
118
+ context ( 'when isV3CertificationAttestationEnabled feature toggle is truthy' , function ( ) {
119
+ it ( 'should return 200 HTTP status code and the certification' , async function ( ) {
120
+ // given
121
+ await featureToggles . set ( 'isV3CertificationAttestationEnabled' , true ) ;
122
+ const userId = databaseBuilder . factory . buildUser ( ) . id ;
123
+
124
+ const session = databaseBuilder . factory . buildSession ( {
125
+ id : 123 ,
126
+ publishedAt : new Date ( '2018-12-01T01:02:03Z' ) ,
127
+ version : SESSIONS_VERSIONS . V3 ,
128
+ } ) ;
129
+ const certificationCourse = databaseBuilder . factory . buildCertificationCourse ( {
130
+ id : 1234 ,
131
+ sessionId : session . id ,
132
+ userId,
133
+ isPublished : true ,
134
+ verificationCode : await generateCertificateVerificationCode ( ) ,
135
+ } ) ;
136
+ const assessment = databaseBuilder . factory . buildAssessment ( {
137
+ userId,
138
+ certificationCourseId : certificationCourse . id ,
139
+ type : Assessment . types . CERTIFICATION ,
140
+ state : Assessment . states . COMPLETED ,
141
+ } ) ;
142
+ databaseBuilder . factory . buildAssessmentResult . last ( {
143
+ certificationCourseId : certificationCourse . id ,
144
+ assessmentId : assessment . id ,
145
+ level : 1 ,
146
+ pixScore : 23 ,
147
+ emitter : 'PIX-ALGO' ,
148
+ status : AssessmentResult . status . VALIDATED ,
149
+ } ) ;
150
+
151
+ await databaseBuilder . commit ( ) ;
152
+
153
+ const server = await createServer ( ) ;
154
+
155
+ // when
156
+ const response = await server . inject ( {
157
+ method : 'GET' ,
158
+ url : `/api/attestation/${ certificationCourse . id } ?isFrenchDomainExtension=true&lang=fr` ,
159
+ headers : generateAuthenticatedUserRequestHeaders ( { userId } ) ,
160
+ } ) ;
161
+
162
+ // then
163
+ expect ( response . statusCode ) . to . equal ( 200 ) ;
164
+ } ) ;
128
165
} ) ;
166
+ } ) ;
167
+
168
+ context ( 'when session version is V2' , function ( ) {
169
+ it ( 'should return 200 HTTP status code and the certification' , async function ( ) {
170
+ // given
171
+ const userId = databaseBuilder . factory . buildUser ( ) . id ;
172
+ await _buildDatabaseForV2Certification ( { userId, certificationCourseId : 1234 } ) ;
173
+ await databaseBuilder . commit ( ) ;
174
+
175
+ const server = await createServer ( ) ;
129
176
130
- // then
131
- expect ( response . statusCode ) . to . equal ( 200 ) ;
132
- expect ( response . headers [ 'content-type' ] ) . to . equal ( 'application/pdf' ) ;
133
- expect ( response . headers [ 'content-disposition' ] ) . to . include ( 'filename=attestation-pix' ) ;
134
- expect ( response . file ) . not . to . be . null ;
177
+ // when
178
+ const response = await server . inject ( {
179
+ method : 'GET' ,
180
+ url : '/api/attestation/1234?isFrenchDomainExtension=true&lang=fr' ,
181
+ headers : generateAuthenticatedUserRequestHeaders ( { userId } ) ,
182
+ } ) ;
183
+
184
+ // then
185
+ expect ( response . statusCode ) . to . equal ( 200 ) ;
186
+ expect ( response . headers [ 'content-type' ] ) . to . equal ( 'application/pdf' ) ;
187
+ expect ( response . headers [ 'content-disposition' ] ) . to . include ( 'filename=attestation-pix' ) ;
188
+ expect ( response . file ) . not . to . be . null ;
189
+ } ) ;
135
190
} ) ;
136
191
} ) ;
137
192
} ) ;
0 commit comments