Skip to content

Commit

Permalink
feat(api):improve feasibility filtering logic and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreavizou committed Dec 12, 2024
1 parent c4e6389 commit 6b7060f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ beforeAll(async () => {
createFeasibilityUploadedPdfHelper({
decision: "COMPLETE",
}),
// The status of below candidacies is incompatible with the decision
// about the feasibility file. They should be ignored by the API (not counted, not returned)
createFeasibilityUploadedPdfHelper(
{
decision: "PENDING",
},
"PROJET",
),
createFeasibilityUploadedPdfHelper(
{
decision: "PENDING",
},
"PARCOURS_ENVOYE",
),
createFeasibilityUploadedPdfHelper(
{
decision: "PENDING",
},
"PARCOURS_CONFIRME",
),
createFeasibilityUploadedPdfHelper(
{
decision: "PENDING",
},
"DOSSIER_DE_VALIDATION_ENVOYE",
),
]);
await createCandidacyHelper({
candidacyActiveStatus: "ARCHIVE",
Expand Down
2 changes: 2 additions & 0 deletions packages/reva-api/modules/feasibility/feasibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ test("should count all (1) available feasibility for certificator user even if o
const candidacy = await createCandidacyHelper({
candidacyArgs: {
certificationId: certification.id,
status: "DOSSIER_FAISABILITE_ENVOYE",
},
});
await createFeasibilityUploadedPdfHelper({
Expand Down Expand Up @@ -178,6 +179,7 @@ test("should return all (1) available feasibility for certificateur user", async
candidacyArgs: {
certificationId: certification.id,
},
candidacyActiveStatus: "DOSSIER_FAISABILITE_ENVOYE",
});
const feasibility = await createFeasibilityUploadedPdfHelper({
decision: "PENDING",
Expand Down
22 changes: 16 additions & 6 deletions packages/reva-api/modules/feasibility/utils/feasibility.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ export type FeasibilityStatusFilter =
export const excludeArchivedAndDroppedOutCandidacy: Prisma.FeasibilityWhereInput =
{
candidacy: {
candidacyStatuses: { none: { isActive: true, status: "ARCHIVE" } },
candidacyDropOut: { is: null },
status: {
in: [
"DOSSIER_FAISABILITE_ENVOYE",
"DOSSIER_FAISABILITE_COMPLET",
"DOSSIER_FAISABILITE_INCOMPLET",
"DOSSIER_FAISABILITE_RECEVABLE",
"DOSSIER_FAISABILITE_NON_RECEVABLE",
],
},
},
};

Expand All @@ -21,11 +29,13 @@ export const excludeRejectedArchivedDraftAndDroppedOutCandidacy: Prisma.Feasibil
decision: { in: ["REJECTED", "DRAFT"] },
},
candidacy: {
candidacyStatuses: {
none: {
isActive: true,
status: "ARCHIVE",
},
status: {
in: [
"DOSSIER_FAISABILITE_ENVOYE",
"DOSSIER_FAISABILITE_COMPLET",
"DOSSIER_FAISABILITE_INCOMPLET",
"DOSSIER_FAISABILITE_RECEVABLE",
],
},
candidacyDropOut: { is: null },
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Feasibility } from "@prisma/client";
import { CandidacyStatusStep, 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?: Partial<Feasibility>,
candidacyActiveStatus?: CandidacyStatusStep,
) => {
const candidacy = await createCandidacyHelper();
const candidacy = await createCandidacyHelper({
candidacyActiveStatus:
candidacyActiveStatus ?? "DOSSIER_FAISABILITE_ENVOYE",
});
const file = await createFileHelper();

return prismaClient.feasibility.create({
Expand Down

0 comments on commit 6b7060f

Please sign in to comment.