Skip to content

Commit

Permalink
test(api): cleanup args in createFeasibilityUploadedPdfHelper and rel…
Browse files Browse the repository at this point in the history
…ated tests
  • Loading branch information
ThomasDos committed Nov 22, 2024
1 parent de07589 commit b2e839e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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;
Expand Down
93 changes: 41 additions & 52 deletions packages/reva-api/modules/feasibility/feasibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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,
Expand All @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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,
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 ?? "";

Expand Down Expand Up @@ -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 ?? "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Loading

0 comments on commit b2e839e

Please sign in to comment.