diff --git a/packages/reva-api/modules/candidacy/security/candidacy.security.test.ts b/packages/reva-api/modules/candidacy/security/candidacy.security.test.ts index 1e977075c..f9b513c6f 100644 --- a/packages/reva-api/modules/candidacy/security/candidacy.security.test.ts +++ b/packages/reva-api/modules/candidacy/security/candidacy.security.test.ts @@ -158,9 +158,7 @@ test("Certification authority manager of the feasibility file of the candidacy s const certificationAuthority = await createCertificationAuthorityHelper(); const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - certificationAuthorityId: certificationAuthority.id, - }, + certificationAuthorityId: certificationAuthority.id, }); const resp = await getCandidacy({ @@ -199,15 +197,16 @@ test("Certification local account of the feasibility file of the candidacy shoul certificationAuthorityLocalAccount.certificationAuthority .certificationAuthorityStructureId, }); - const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - certificationAuthorityId: - certificationAuthorityLocalAccount.certificationAuthorityId, - }, + const candidacyInput = await createCandidacyHelper({ candidacyArgs: { certificationId: certification.id, }, }); + const feasibility = await createFeasibilityUploadedPdfHelper({ + certificationAuthorityId: + certificationAuthorityLocalAccount.certificationAuthorityId, + candidacyId: candidacyInput.id, + }); const candidacy = feasibility.candidacy; const departmentId = candidacy.departmentId; diff --git a/packages/reva-api/modules/feasibility/feasibility.test.ts b/packages/reva-api/modules/feasibility/feasibility.test.ts index 2e7f3e811..a701a9765 100644 --- a/packages/reva-api/modules/feasibility/feasibility.test.ts +++ b/packages/reva-api/modules/feasibility/feasibility.test.ts @@ -6,6 +6,7 @@ import { FastifyInstance } from "fastify"; import { randomUUID } from "crypto"; import { prismaClient } from "../../prisma/client"; import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper"; +import { createCandidacyHelper } from "../../test/helpers/entities/create-candidacy-helper"; import { createCertificationHelper } from "../../test/helpers/entities/create-certification-helper"; import { createFeasibilityUploadedPdfHelper } from "../../test/helpers/entities/create-feasibility-uploaded-pdf-helper"; import { injectGraphql } from "../../test/helpers/graphql-helper"; @@ -16,15 +17,11 @@ afterEach(async () => { test("should count all (2) feasibilities for admin user", async () => { await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - }, + decision: "PENDING", }); await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - }, + decision: "PENDING", }); const resp = await injectGraphql({ @@ -50,19 +47,18 @@ test("should count all (1) available feasibility for certificator user even if o const certification = await createCertificationHelper({}); const certificationAuthority = certification.certificationAuthorityStructure?.certificationAuthorities[0]; - await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - certificationAuthorityId: certificationAuthority?.id, - }, + const candidacy = await createCandidacyHelper({ candidacyArgs: { certificationId: certification.id, }, }); await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - }, + decision: "PENDING", + certificationAuthorityId: certificationAuthority?.id, + candidacyId: candidacy.id, + }); + await createFeasibilityUploadedPdfHelper({ + decision: "PENDING", }); const resp = await injectGraphql({ @@ -86,9 +82,7 @@ test("should count all (1) available feasibility for certificator user even if o test("should count no available feasibility for certificator user since he doesn't handle the related certifications", async () => { await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - }, + decision: "PENDING", }); const resp = await injectGraphql({ @@ -114,16 +108,18 @@ test("should return a feasibilty for certificator since he is allowed to handle const certification = await createCertificationHelper({}); const certificationAuthority = certification.certificationAuthorityStructure?.certificationAuthorities[0]; - const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - certificationAuthorityId: certificationAuthority?.id, - }, + const candidacy = await createCandidacyHelper({ candidacyArgs: { certificationId: certification.id, }, }); + const feasibility = await createFeasibilityUploadedPdfHelper({ + decision: "PENDING", + certificationAuthorityId: certificationAuthority?.id, + candidacyId: candidacy.id, + }); + const resp = await injectGraphql({ fastify: (global as any).fastify, authorization: authorizationHeaderForUser({ @@ -148,9 +144,7 @@ test("should return a feasibilty for certificator since he is allowed to handle test("should return a feasibility error for certificator 3 since he doesn't handle it", async () => { const feasiblity = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - }, + decision: "PENDING", }); const resp = await injectGraphql({ @@ -174,15 +168,16 @@ test("should return all (1) available feasibility for certificateur user", async const certification = await createCertificationHelper({}); const certificationAuthority = certification.certificationAuthorityStructure?.certificationAuthorities[0]; - const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - certificationAuthorityId: certificationAuthority?.id, - }, + const candidacy = await createCandidacyHelper({ candidacyArgs: { certificationId: certification.id, }, }); + const feasibility = await createFeasibilityUploadedPdfHelper({ + decision: "PENDING", + certificationAuthorityId: certificationAuthority?.id, + candidacyId: candidacy.id, + }); const resp = await injectGraphql({ fastify: (global as any).fastify, @@ -208,9 +203,7 @@ test("should return all (1) available feasibility for certificateur user", async test("should count 1 pending feasibility for admin user", async () => { await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - }, + decision: "PENDING", }); const resp = await injectGraphql({ @@ -261,15 +254,16 @@ test("should validate a feasibility since certificator is allowed to do so", asy const certification = await createCertificationHelper({}); const certificationAuthority = certification.certificationAuthorityStructure?.certificationAuthorities[0]; - const feasiblity = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - certificationAuthorityId: certificationAuthority?.id, - }, + const candidacy = await createCandidacyHelper({ candidacyArgs: { certificationId: certification.id, }, }); + const feasiblity = await createFeasibilityUploadedPdfHelper({ + decision: "PENDING", + certificationAuthorityId: certificationAuthority?.id, + candidacyId: candidacy.id, + }); const resp = await postFeasibilityDecision({ feasibilityId: feasiblity.id, @@ -291,9 +285,7 @@ test("should validate a feasibility since certificator is allowed to do so", asy test("should not validate a feasibility since certificator 2 doesn't handle it, even if he is on the same scope as certificator 1", async () => { const feasiblity = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - }, + decision: "PENDING", }); const resp = await postFeasibilityDecision({ @@ -309,9 +301,7 @@ test("should not validate a feasibility since certificator 2 doesn't handle it, test("should not validate a feasibility since certificator 3 doesn't handle it", async () => { const feasiblity = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - }, + decision: "PENDING", }); const resp = await postFeasibilityDecision({ @@ -329,15 +319,16 @@ test("should reject a feasibility since certificator is allowed to do so", async const certification = await createCertificationHelper({}); const certificationAuthority = certification.certificationAuthorityStructure?.certificationAuthorities[0]; - const feasiblity = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - certificationAuthorityId: certificationAuthority?.id, - }, + const candidacy = await createCandidacyHelper({ candidacyArgs: { certificationId: certification.id, }, }); + const feasiblity = await createFeasibilityUploadedPdfHelper({ + decision: "PENDING", + certificationAuthorityId: certificationAuthority?.id, + candidacyId: candidacy.id, + }); const resp = await postFeasibilityDecision({ feasibilityId: feasiblity.id, @@ -364,9 +355,7 @@ test("should reject a feasibility since certificator is allowed to do so", async test("should not reject a feasibility since certificator 3 doesn't handle it", async () => { const feasiblity = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - decision: "PENDING", - }, + decision: "PENDING", }); const resp = await injectGraphql({ diff --git a/packages/reva-api/modules/finance/unifvae/features/finance.unifvae.test.ts b/packages/reva-api/modules/finance/unifvae/features/finance.unifvae.test.ts index c8a41fe32..25cca142a 100644 --- a/packages/reva-api/modules/finance/unifvae/features/finance.unifvae.test.ts +++ b/packages/reva-api/modules/finance/unifvae/features/finance.unifvae.test.ts @@ -14,6 +14,7 @@ import { PAYMENT_REQUEST, } from "../../../../test/fixtures"; import { authorizationHeaderForUser } from "../../../../test/helpers/authorization-helper"; +import { createCandidacyHelper } from "../../../../test/helpers/entities/create-candidacy-helper"; import { createCandidateHelper } from "../../../../test/helpers/entities/create-candidate-helper"; import { createCertificationHelper } from "../../../../test/helpers/entities/create-certification-helper"; import { createFeasibilityUploadedPdfHelper } from "../../../../test/helpers/entities/create-feasibility-uploaded-pdf-helper"; @@ -83,14 +84,15 @@ test("should create fundingRequestUnifvae with matching batch", async () => { phone: FUNDING_REQUEST_SAMPLE.fundingContactPhone, gender: FUNDING_REQUEST_SAMPLE.candidateGender, }); - const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - feasibilityFileSentAt: new Date(), - }, + const candidacyInput = await createCandidacyHelper({ candidacyArgs: { candidateId: candidate.id, }, }); + const feasibility = await createFeasibilityUploadedPdfHelper({ + feasibilityFileSentAt: new Date(), + candidacyId: candidacyInput.id, + }); const candidacy = feasibility.candidacy; const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId; @@ -145,14 +147,15 @@ test("should create fundingRequestUnifvae with matching batch", async () => { }); test("Should fail to create fundingRequestUnifvae when candidacy is not bound to Unifvae finance module", async () => { - const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - feasibilityFileSentAt: new Date(), - }, + const candidacyInput = await createCandidacyHelper({ candidacyArgs: { financeModule: "unireva", }, }); + const feasibility = await createFeasibilityUploadedPdfHelper({ + feasibilityFileSentAt: new Date(), + candidacyId: candidacyInput.id, + }); const candidacy = feasibility.candidacy; const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId; @@ -184,13 +187,14 @@ test("Should fail to create fundingRequestUnifvae when candidacy is not bound to test("should fail to create a fundingRequestUnifvae whith a 'hors care' candidacy certification", async () => { const certification = await createCertificationHelper({ rncpId: "000000" }); - const feasibility = await createFeasibilityUploadedPdfHelper({ + const candidacyInput = await createCandidacyHelper({ candidacyArgs: { certificationId: certification.id, }, - feasibilityArgs: { - feasibilityFileSentAt: new Date(), - }, + }); + const feasibility = await createFeasibilityUploadedPdfHelper({ + candidacyId: candidacyInput.id, + feasibilityFileSentAt: new Date(), }); const candidacy = feasibility.candidacy; @@ -224,12 +228,16 @@ test("should fail to create a fundingRequestUnifvae whith a 'hors care' candidac }); test("should fail to create paymentRequestUnifvae when candidacy was drop out less than 6 months ago then succeed after 6 months", async () => { - const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - feasibilityFileSentAt: new Date(), + const candidacyInput = await createCandidacyHelper({ + candidacyArgs: { + financeModule: "unifvae", }, candidacyActiveStatus: CandidacyStatusStep.DEMANDE_FINANCEMENT_ENVOYE, }); + const feasibility = await createFeasibilityUploadedPdfHelper({ + feasibilityFileSentAt: new Date(), + candidacyId: candidacyInput.id, + }); const candidacy = feasibility.candidacy; const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId ?? ""; @@ -269,12 +277,16 @@ test("should fail to create paymentRequestUnifvae when candidacy was drop out le }); test("should allow the creation of paymentRequestUnifvae when candidacy was drop out less than 6 months ago but the proof was received by an admin", async () => { - const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { - feasibilityFileSentAt: new Date(), + const candidacyInput = await createCandidacyHelper({ + candidacyArgs: { + financeModule: "unifvae", }, candidacyActiveStatus: CandidacyStatusStep.DEMANDE_FINANCEMENT_ENVOYE, }); + const feasibility = await createFeasibilityUploadedPdfHelper({ + feasibilityFileSentAt: new Date(), + candidacyId: candidacyInput.id, + }); const candidacy = feasibility.candidacy; const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId ?? ""; diff --git a/packages/reva-api/modules/finance/unifvae/validation/feasibility-checks.test.ts b/packages/reva-api/modules/finance/unifvae/validation/feasibility-checks.test.ts index 8d8e960d6..14ebbe8dd 100644 --- a/packages/reva-api/modules/finance/unifvae/validation/feasibility-checks.test.ts +++ b/packages/reva-api/modules/finance/unifvae/validation/feasibility-checks.test.ts @@ -22,7 +22,7 @@ describe("FundingRequesUnifvae Feasibility checks", () => { test("Should fail when feasibility decision is still pending", async () => { const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { decision: "PENDING" }, + decision: "PENDING", }); const errors = await validateFeasibilityChecks({ candidacyId: feasibility.candidacyId, @@ -37,7 +37,7 @@ describe("FundingRequesUnifvae Feasibility checks", () => { test("Should fail when feasibility rejected and funding request has disallowed items", async () => { const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { decision: "REJECTED" }, + decision: "REJECTED", }); const errors = await validateFeasibilityChecks({ candidacyId: feasibility.candidacyId, @@ -48,7 +48,7 @@ describe("FundingRequesUnifvae Feasibility checks", () => { test("Should succeed when feasibility rejected and request has only allowed items", async () => { const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { decision: "REJECTED" }, + decision: "REJECTED", }); const errors = await validateFeasibilityChecks({ candidacyId: feasibility.candidacyId, @@ -59,7 +59,7 @@ describe("FundingRequesUnifvae Feasibility checks", () => { test("Should succeed when feasibility validated", async () => { const feasibility = await createFeasibilityUploadedPdfHelper({ - feasibilityArgs: { decision: "ADMISSIBLE" }, + decision: "ADMISSIBLE", }); const errors = await validateFeasibilityChecks({ candidacyId: feasibility.candidacyId, diff --git a/packages/reva-api/test/helpers/entities/create-feasibility-uploaded-pdf-helper.ts b/packages/reva-api/test/helpers/entities/create-feasibility-uploaded-pdf-helper.ts index 09946d479..886032150 100644 --- a/packages/reva-api/test/helpers/entities/create-feasibility-uploaded-pdf-helper.ts +++ b/packages/reva-api/test/helpers/entities/create-feasibility-uploaded-pdf-helper.ts @@ -1,37 +1,20 @@ -import { - Candidacy, - CandidacyStatusStep, - Feasibility, - FeasibilityUploadedPdf, -} from "@prisma/client"; +import { Feasibility } from "@prisma/client"; import { prismaClient } from "../../../prisma/client"; import { createCandidacyHelper } from "./create-candidacy-helper"; import { createFileHelper } from "./create-file-helper"; -export const createFeasibilityUploadedPdfHelper = async ({ - feasibilityArgs, - feasibilityUploadedPdfArgs, - candidacyArgs, - candidacyActiveStatus, -}: { - feasibilityArgs?: Partial; - feasibilityUploadedPdfArgs?: Partial; - candidacyArgs?: Partial; - candidacyActiveStatus?: CandidacyStatusStep; -}) => { - const candidacy = await createCandidacyHelper({ - candidacyArgs, - candidacyActiveStatus, - }); +export const createFeasibilityUploadedPdfHelper = async ( + feasibilityArgs?: Partial, +) => { + const candidacy = await createCandidacyHelper(); const file = await createFileHelper(); return prismaClient.feasibility.create({ data: { - candidacyId: candidacyArgs?.id ?? candidacy.id, + candidacyId: feasibilityArgs?.candidacyId ?? candidacy.id, feasibilityUploadedPdf: { create: { feasibilityFileId: file.id, - ...feasibilityUploadedPdfArgs, }, }, ...feasibilityArgs,