@@ -5,6 +5,7 @@ import { faker } from "@faker-js/faker/.";
5
5
import { prismaClient } from "../../../../prisma/client" ;
6
6
import { authorizationHeaderForUser } from "../../../../test/helpers/authorization-helper" ;
7
7
import { createCandidacyHelper } from "../../../../test/helpers/entities/create-candidacy-helper" ;
8
+ import { createCertificationAuthorityHelper } from "../../../../test/helpers/entities/create-certification-authority-helper" ;
8
9
import { createCertificationHelper } from "../../../../test/helpers/entities/create-certification-helper" ;
9
10
import { createFeasibilityUploadedPdfHelper } from "../../../../test/helpers/entities/create-feasibility-uploaded-pdf-helper" ;
10
11
import { injectGraphql } from "../../../../test/helpers/graphql-helper" ;
@@ -37,11 +38,9 @@ const ERROR_MESSAGES = {
37
38
38
39
describe ( "isFeasibilityManager" , ( ) => {
39
40
describe ( "manage_feasibility role" , ( ) => {
40
- test ( "should allow access when user manages the certification authority of the feasibility" , async ( ) => {
41
+ test ( "should allow access when user manages the feasibility" , async ( ) => {
41
42
const certification = await createCertificationHelper ( ) ;
42
- const certificationAuthority =
43
- certification . certificationAuthorityStructure
44
- ?. oldCertificationAuthorities [ 0 ] ;
43
+ const certificationAuthority = await createCertificationAuthorityHelper ( ) ;
45
44
const candidacy = await createCandidacyHelper ( {
46
45
candidacyArgs : {
47
46
certificationId : certification . id ,
@@ -87,7 +86,7 @@ describe("isFeasibilityManager", () => {
87
86
expect ( resp . json ( ) ) . not . toHaveProperty ( "errors" ) ;
88
87
} ) ;
89
88
90
- test ( "should deny access when user does not manage the certification authority " , async ( ) => {
89
+ test ( "should deny access when user doesn't manage the feasibility " , async ( ) => {
91
90
const feasibility = await createFeasibilityUploadedPdfHelper ( ) ;
92
91
93
92
const resp = await getActiveFeasibilityByCandidacyId ( {
@@ -124,15 +123,8 @@ describe("isFeasibilityManager", () => {
124
123
} ) ;
125
124
126
125
test ( "should deny access when feasibility is not active" , async ( ) => {
127
- const certification = await createCertificationHelper ( ) ;
128
- const certificationAuthority =
129
- certification . certificationAuthorityStructure
130
- ?. oldCertificationAuthorities [ 0 ] ;
131
- const candidacy = await createCandidacyHelper ( {
132
- candidacyArgs : {
133
- certificationId : certification . id ,
134
- } ,
135
- } ) ;
126
+ const certificationAuthority = await createCertificationAuthorityHelper ( ) ;
127
+ const candidacy = await createCandidacyHelper ( ) ;
136
128
137
129
await createFeasibilityUploadedPdfHelper ( {
138
130
certificationAuthorityId : certificationAuthority ?. id ,
@@ -154,11 +146,9 @@ describe("isFeasibilityManager", () => {
154
146
} ) ;
155
147
156
148
describe ( "manage_feasibility role with certification and department checks" , ( ) => {
157
- test ( "should allow access when user matches certification, authority and department" , async ( ) => {
149
+ test ( "should allow access when user matches certification and department" , async ( ) => {
158
150
const certification = await createCertificationHelper ( ) ;
159
- const certificationAuthority =
160
- certification . certificationAuthorityStructure
161
- ?. oldCertificationAuthorities [ 0 ] ;
151
+ const certificationAuthority = await createCertificationAuthorityHelper ( ) ;
162
152
const candidacy = await createCandidacyHelper ( {
163
153
candidacyArgs : {
164
154
certificationId : certification . id ,
@@ -204,16 +194,13 @@ describe("isFeasibilityManager", () => {
204
194
expect ( resp . json ( ) ) . not . toHaveProperty ( "errors" ) ;
205
195
} ) ;
206
196
207
- test ( "should deny access when certification does not match" , async ( ) => {
197
+ test ( "should deny access when certification authority does not match" , async ( ) => {
208
198
const feasibility = await createFeasibilityUploadedPdfHelper ( ) ;
209
- const differentCertification = await createCertificationHelper ( ) ;
199
+ const certificationAuthority = await createCertificationAuthorityHelper ( ) ;
210
200
211
201
const resp = await getActiveFeasibilityByCandidacyId ( {
212
202
candidacyId : feasibility . candidacyId ,
213
- keycloakId :
214
- differentCertification . certificationAuthorityStructure
215
- ?. oldCertificationAuthorities [ 0 ] . Account [ 0 ] . keycloakId ??
216
- faker . string . uuid ( ) ,
203
+ keycloakId : certificationAuthority . Account [ 0 ] . keycloakId ,
217
204
} ) ;
218
205
219
206
expect ( resp . json ( ) ) . toHaveProperty ( "errors" ) ;
@@ -242,14 +229,11 @@ describe("isFeasibilityManager", () => {
242
229
candidacyId : differentDepartmentCandidacy . id ,
243
230
} ) ;
244
231
245
- const certificationAuthority = await createCertificationHelper ( ) ;
232
+ const certificationAuthority = await createCertificationAuthorityHelper ( ) ;
246
233
247
234
const resp = await getActiveFeasibilityByCandidacyId ( {
248
235
candidacyId : differentDepartmentCandidacy . id ,
249
- keycloakId :
250
- certificationAuthority . certificationAuthorityStructure
251
- ?. oldCertificationAuthorities [ 0 ] . Account [ 0 ] . keycloakId ??
252
- faker . string . uuid ( ) ,
236
+ keycloakId : certificationAuthority . Account [ 0 ] . keycloakId ,
253
237
} ) ;
254
238
255
239
expect ( resp . json ( ) ) . toHaveProperty ( "errors" ) ;
@@ -258,30 +242,20 @@ describe("isFeasibilityManager", () => {
258
242
259
243
test ( "should deny access when certification authority does not match" , async ( ) => {
260
244
const feasibility = await createFeasibilityUploadedPdfHelper ( ) ;
261
- const differentAuthority = await createCertificationHelper ( ) ;
245
+ const differentAuthority = await createCertificationAuthorityHelper ( ) ;
262
246
263
247
const resp = await getActiveFeasibilityByCandidacyId ( {
264
248
candidacyId : feasibility . candidacyId ,
265
- keycloakId :
266
- differentAuthority . certificationAuthorityStructure
267
- ?. oldCertificationAuthorities [ 0 ] . Account [ 0 ] . keycloakId ??
268
- faker . string . uuid ( ) ,
249
+ keycloakId : differentAuthority . Account [ 0 ] . keycloakId ,
269
250
} ) ;
270
251
271
252
expect ( resp . json ( ) ) . toHaveProperty ( "errors" ) ;
272
253
expect ( resp . json ( ) . errors [ 0 ] . message ) . toBe ( ERROR_MESSAGES . UNAUTHORIZED ) ;
273
254
} ) ;
274
255
275
256
test ( "should deny access when feasibility is not active" , async ( ) => {
276
- const certification = await createCertificationHelper ( ) ;
277
- const certificationAuthority =
278
- certification . certificationAuthorityStructure
279
- ?. oldCertificationAuthorities [ 0 ] ;
280
- const candidacy = await createCandidacyHelper ( {
281
- candidacyArgs : {
282
- certificationId : certification . id ,
283
- } ,
284
- } ) ;
257
+ const certificationAuthority = await createCertificationAuthorityHelper ( ) ;
258
+ const candidacy = await createCandidacyHelper ( ) ;
285
259
286
260
await createFeasibilityUploadedPdfHelper ( {
287
261
certificationAuthorityId : certificationAuthority ?. id ,
@@ -302,8 +276,7 @@ describe("isFeasibilityManager", () => {
302
276
} ) ;
303
277
304
278
test ( "should deny access when only certification authority matches" , async ( ) => {
305
- const certification = await createCertificationHelper ( ) ;
306
- const differentCertification = await createCertificationHelper ( ) ;
279
+ const certificationAuthority = await createCertificationAuthorityHelper ( ) ;
307
280
const differentDepartment = await prismaClient . department . create ( {
308
281
data : {
309
282
code : faker . string . numeric ( 3 ) ,
@@ -319,24 +292,18 @@ describe("isFeasibilityManager", () => {
319
292
320
293
const candidacy = await createCandidacyHelper ( {
321
294
candidacyArgs : {
322
- certificationId : differentCertification . id ,
323
295
departmentId : differentDepartment . id ,
324
296
} ,
325
297
} ) ;
326
298
327
299
await createFeasibilityUploadedPdfHelper ( {
328
- certificationAuthorityId :
329
- certification . certificationAuthorityStructure
330
- ?. oldCertificationAuthorities [ 0 ] . id ,
300
+ certificationAuthorityId : certificationAuthority . id ,
331
301
candidacyId : candidacy . id ,
332
302
} ) ;
333
303
334
304
const resp = await getActiveFeasibilityByCandidacyId ( {
335
305
candidacyId : candidacy . id ,
336
- keycloakId :
337
- certification . certificationAuthorityStructure
338
- ?. oldCertificationAuthorities [ 0 ] . Account [ 0 ] . keycloakId ??
339
- faker . string . uuid ( ) ,
306
+ keycloakId : certificationAuthority . Account [ 0 ] . keycloakId ,
340
307
} ) ;
341
308
342
309
expect ( resp . json ( ) ) . toHaveProperty ( "errors" ) ;
0 commit comments