Skip to content

Commit 8c41450

Browse files
committed
test(api): rework some tests in isFeasibilityManager.test
1 parent 9a28fc3 commit 8c41450

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

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

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe("isFeasibilityManager", () => {
9898
expect(resp.json().errors[0].message).toBe(ERROR_MESSAGES.UNAUTHORIZED);
9999
});
100100

101-
test("should deny access when feasibility does not exist", async () => {
101+
test("should deny access when candidacy does not exist", async () => {
102102
const resp = await getActiveFeasibilityByCandidacyId({
103103
candidacyId: faker.string.uuid(),
104104
keycloakId: faker.string.uuid(),
@@ -110,6 +110,43 @@ describe("isFeasibilityManager", () => {
110110
);
111111
});
112112

113+
test("should deny access when feasibility file does not exist", async () => {
114+
const certification = await createCertificationHelper();
115+
const certificationAuthority = await createCertificationAuthorityHelper();
116+
const candidacy = await createCandidacyHelper({
117+
candidacyArgs: {
118+
certificationId: certification.id,
119+
},
120+
});
121+
122+
await prismaClient.certificationAuthorityLocalAccount.create({
123+
data: {
124+
certificationAuthorityId: certificationAuthority.id,
125+
accountId: certificationAuthority.Account[0].id,
126+
certificationAuthorityLocalAccountOnCertification: {
127+
create: {
128+
certificationId: certification.id,
129+
},
130+
},
131+
certificationAuthorityLocalAccountOnDepartment: {
132+
create: {
133+
departmentId: candidacy.departmentId ?? faker.string.uuid(),
134+
},
135+
},
136+
},
137+
});
138+
139+
const resp = await getActiveFeasibilityByCandidacyId({
140+
candidacyId: candidacy.id,
141+
keycloakId: certificationAuthority?.Account[0].keycloakId,
142+
});
143+
144+
expect(resp.json()).toHaveProperty("errors");
145+
expect(resp.json().errors[0].message).toBe(
146+
ERROR_MESSAGES.CANDIDACY_NOT_FOUND,
147+
);
148+
});
149+
113150
test("should deny access when account is not found", async () => {
114151
const feasibility = await createFeasibilityUploadedPdfHelper();
115152

@@ -240,19 +277,6 @@ describe("isFeasibilityManager", () => {
240277
expect(resp.json().errors[0].message).toBe(ERROR_MESSAGES.UNAUTHORIZED);
241278
});
242279

243-
test("should deny access when certification authority does not match", async () => {
244-
const feasibility = await createFeasibilityUploadedPdfHelper();
245-
const differentAuthority = await createCertificationAuthorityHelper();
246-
247-
const resp = await getActiveFeasibilityByCandidacyId({
248-
candidacyId: feasibility.candidacyId,
249-
keycloakId: differentAuthority.Account[0].keycloakId,
250-
});
251-
252-
expect(resp.json()).toHaveProperty("errors");
253-
expect(resp.json().errors[0].message).toBe(ERROR_MESSAGES.UNAUTHORIZED);
254-
});
255-
256280
test("should deny access when feasibility is not active", async () => {
257281
const certificationAuthority = await createCertificationAuthorityHelper();
258282
const candidacy = await createCandidacyHelper();

0 commit comments

Comments
 (0)