Skip to content

Commit 9a28fc3

Browse files
committed
fix(api): was using wrong helper in isFeasibilityManager.test
1 parent fe0f64b commit 9a28fc3

File tree

1 file changed

+20
-53
lines changed

1 file changed

+20
-53
lines changed

packages/reva-api/modules/shared/security/middlewares/isFeasibilityManager.test.ts

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { faker } from "@faker-js/faker/.";
55
import { prismaClient } from "../../../../prisma/client";
66
import { authorizationHeaderForUser } from "../../../../test/helpers/authorization-helper";
77
import { createCandidacyHelper } from "../../../../test/helpers/entities/create-candidacy-helper";
8+
import { createCertificationAuthorityHelper } from "../../../../test/helpers/entities/create-certification-authority-helper";
89
import { createCertificationHelper } from "../../../../test/helpers/entities/create-certification-helper";
910
import { createFeasibilityUploadedPdfHelper } from "../../../../test/helpers/entities/create-feasibility-uploaded-pdf-helper";
1011
import { injectGraphql } from "../../../../test/helpers/graphql-helper";
@@ -37,11 +38,9 @@ const ERROR_MESSAGES = {
3738

3839
describe("isFeasibilityManager", () => {
3940
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 () => {
4142
const certification = await createCertificationHelper();
42-
const certificationAuthority =
43-
certification.certificationAuthorityStructure
44-
?.oldCertificationAuthorities[0];
43+
const certificationAuthority = await createCertificationAuthorityHelper();
4544
const candidacy = await createCandidacyHelper({
4645
candidacyArgs: {
4746
certificationId: certification.id,
@@ -87,7 +86,7 @@ describe("isFeasibilityManager", () => {
8786
expect(resp.json()).not.toHaveProperty("errors");
8887
});
8988

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 () => {
9190
const feasibility = await createFeasibilityUploadedPdfHelper();
9291

9392
const resp = await getActiveFeasibilityByCandidacyId({
@@ -124,15 +123,8 @@ describe("isFeasibilityManager", () => {
124123
});
125124

126125
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();
136128

137129
await createFeasibilityUploadedPdfHelper({
138130
certificationAuthorityId: certificationAuthority?.id,
@@ -154,11 +146,9 @@ describe("isFeasibilityManager", () => {
154146
});
155147

156148
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 () => {
158150
const certification = await createCertificationHelper();
159-
const certificationAuthority =
160-
certification.certificationAuthorityStructure
161-
?.oldCertificationAuthorities[0];
151+
const certificationAuthority = await createCertificationAuthorityHelper();
162152
const candidacy = await createCandidacyHelper({
163153
candidacyArgs: {
164154
certificationId: certification.id,
@@ -204,16 +194,13 @@ describe("isFeasibilityManager", () => {
204194
expect(resp.json()).not.toHaveProperty("errors");
205195
});
206196

207-
test("should deny access when certification does not match", async () => {
197+
test("should deny access when certification authority does not match", async () => {
208198
const feasibility = await createFeasibilityUploadedPdfHelper();
209-
const differentCertification = await createCertificationHelper();
199+
const certificationAuthority = await createCertificationAuthorityHelper();
210200

211201
const resp = await getActiveFeasibilityByCandidacyId({
212202
candidacyId: feasibility.candidacyId,
213-
keycloakId:
214-
differentCertification.certificationAuthorityStructure
215-
?.oldCertificationAuthorities[0].Account[0].keycloakId ??
216-
faker.string.uuid(),
203+
keycloakId: certificationAuthority.Account[0].keycloakId,
217204
});
218205

219206
expect(resp.json()).toHaveProperty("errors");
@@ -242,14 +229,11 @@ describe("isFeasibilityManager", () => {
242229
candidacyId: differentDepartmentCandidacy.id,
243230
});
244231

245-
const certificationAuthority = await createCertificationHelper();
232+
const certificationAuthority = await createCertificationAuthorityHelper();
246233

247234
const resp = await getActiveFeasibilityByCandidacyId({
248235
candidacyId: differentDepartmentCandidacy.id,
249-
keycloakId:
250-
certificationAuthority.certificationAuthorityStructure
251-
?.oldCertificationAuthorities[0].Account[0].keycloakId ??
252-
faker.string.uuid(),
236+
keycloakId: certificationAuthority.Account[0].keycloakId,
253237
});
254238

255239
expect(resp.json()).toHaveProperty("errors");
@@ -258,30 +242,20 @@ describe("isFeasibilityManager", () => {
258242

259243
test("should deny access when certification authority does not match", async () => {
260244
const feasibility = await createFeasibilityUploadedPdfHelper();
261-
const differentAuthority = await createCertificationHelper();
245+
const differentAuthority = await createCertificationAuthorityHelper();
262246

263247
const resp = await getActiveFeasibilityByCandidacyId({
264248
candidacyId: feasibility.candidacyId,
265-
keycloakId:
266-
differentAuthority.certificationAuthorityStructure
267-
?.oldCertificationAuthorities[0].Account[0].keycloakId ??
268-
faker.string.uuid(),
249+
keycloakId: differentAuthority.Account[0].keycloakId,
269250
});
270251

271252
expect(resp.json()).toHaveProperty("errors");
272253
expect(resp.json().errors[0].message).toBe(ERROR_MESSAGES.UNAUTHORIZED);
273254
});
274255

275256
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();
285259

286260
await createFeasibilityUploadedPdfHelper({
287261
certificationAuthorityId: certificationAuthority?.id,
@@ -302,8 +276,7 @@ describe("isFeasibilityManager", () => {
302276
});
303277

304278
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();
307280
const differentDepartment = await prismaClient.department.create({
308281
data: {
309282
code: faker.string.numeric(3),
@@ -319,24 +292,18 @@ describe("isFeasibilityManager", () => {
319292

320293
const candidacy = await createCandidacyHelper({
321294
candidacyArgs: {
322-
certificationId: differentCertification.id,
323295
departmentId: differentDepartment.id,
324296
},
325297
});
326298

327299
await createFeasibilityUploadedPdfHelper({
328-
certificationAuthorityId:
329-
certification.certificationAuthorityStructure
330-
?.oldCertificationAuthorities[0].id,
300+
certificationAuthorityId: certificationAuthority.id,
331301
candidacyId: candidacy.id,
332302
});
333303

334304
const resp = await getActiveFeasibilityByCandidacyId({
335305
candidacyId: candidacy.id,
336-
keycloakId:
337-
certification.certificationAuthorityStructure
338-
?.oldCertificationAuthorities[0].Account[0].keycloakId ??
339-
faker.string.uuid(),
306+
keycloakId: certificationAuthority.Account[0].keycloakId,
340307
});
341308

342309
expect(resp.json()).toHaveProperty("errors");

0 commit comments

Comments
 (0)