From ef2054931a8a975a0464c40c3daffdaa8dae0a4c Mon Sep 17 00:00:00 2001 From: ThomasDos Date: Tue, 12 Nov 2024 16:31:55 +0100 Subject: [PATCH] test(api): add integration tests for checkIsDFFReadyToBeSentToCertificationAuthorityById --- ...BeSentToCertificationAuthorityById.test.ts | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 packages/reva-api/modules/feasibility/dematerialized-feasibility-file/features/checkIsDFFReadyToBeSentToCertificationAuthorityById.test.ts diff --git a/packages/reva-api/modules/feasibility/dematerialized-feasibility-file/features/checkIsDFFReadyToBeSentToCertificationAuthorityById.test.ts b/packages/reva-api/modules/feasibility/dematerialized-feasibility-file/features/checkIsDFFReadyToBeSentToCertificationAuthorityById.test.ts new file mode 100644 index 000000000..1dbcf85f2 --- /dev/null +++ b/packages/reva-api/modules/feasibility/dematerialized-feasibility-file/features/checkIsDFFReadyToBeSentToCertificationAuthorityById.test.ts @@ -0,0 +1,178 @@ +import { checkIsDFFReadyToBeSentToCertificationAuthorityById } from "./checkIsDFFReadyToBeSentToCertificationAuthorityById"; + +import { + CompetenceBlocsPartCompletionEnum, + DFFDecision, + DFFEligibilityRequirement, +} from "@prisma/client"; + +const ATTACHMENTS_PART_COMPLETE = true; +const ATTACHMENTS_PART_INCOMPLETE = false; +const CERTIFICATION_PART_COMPLETE = true; +const CERTIFICATION_PART_INCOMPLETE = false; +const PREREQUISITES_PART_COMPLETE = true; +const PREREQUISITES_PART_INCOMPLETE = false; +const SWORN_STATEMENT_FILE_ID = "some-file-id"; +const CANDIDATE_CONFIRMATION_DATE = new Date(); + +const COMPETENCE_BLOCS_TO_COMPLETE: CompetenceBlocsPartCompletionEnum = + "TO_COMPLETE"; +const COMPETENCE_BLOCS_IN_PROGRESS: CompetenceBlocsPartCompletionEnum = + "IN_PROGRESS"; +const COMPETENCE_BLOCS_COMPLETED: CompetenceBlocsPartCompletionEnum = + "COMPLETED"; + +const AAP_DECISION_FAVORABLE: DFFDecision = "FAVORABLE"; +const AAP_DECISION_NULL = null; + +const ELIGIBILITY_FULL: DFFEligibilityRequirement = + "FULL_ELIGIBILITY_REQUIREMENT"; +const ELIGIBILITY_PARTIAL: DFFEligibilityRequirement = + "PARTIAL_ELIGIBILITY_REQUIREMENT"; +const ELIGIBILITY_NULL = null; + +describe("checkIsDFFReadyToBeSentToCertificationAuthorityById - Validates if a dematerialized feasibility file is ready to be sent to certification authority", () => { + describe("Basic field validation", () => { + test.each([ + [ + ATTACHMENTS_PART_INCOMPLETE, + CERTIFICATION_PART_COMPLETE, + PREREQUISITES_PART_COMPLETE, + ELIGIBILITY_PARTIAL, + SWORN_STATEMENT_FILE_ID, + CANDIDATE_CONFIRMATION_DATE, + false, + ], + [ + ATTACHMENTS_PART_COMPLETE, + CERTIFICATION_PART_INCOMPLETE, + PREREQUISITES_PART_COMPLETE, + ELIGIBILITY_PARTIAL, + SWORN_STATEMENT_FILE_ID, + CANDIDATE_CONFIRMATION_DATE, + false, + ], + [ + ATTACHMENTS_PART_COMPLETE, + CERTIFICATION_PART_COMPLETE, + PREREQUISITES_PART_INCOMPLETE, + ELIGIBILITY_PARTIAL, + SWORN_STATEMENT_FILE_ID, + CANDIDATE_CONFIRMATION_DATE, + false, + ], + [ + ATTACHMENTS_PART_COMPLETE, + CERTIFICATION_PART_COMPLETE, + PREREQUISITES_PART_COMPLETE, + ELIGIBILITY_NULL, + SWORN_STATEMENT_FILE_ID, + CANDIDATE_CONFIRMATION_DATE, + false, + ], + [ + ATTACHMENTS_PART_COMPLETE, + CERTIFICATION_PART_COMPLETE, + PREREQUISITES_PART_COMPLETE, + ELIGIBILITY_PARTIAL, + null, + CANDIDATE_CONFIRMATION_DATE, + false, + ], + [ + ATTACHMENTS_PART_COMPLETE, + CERTIFICATION_PART_COMPLETE, + PREREQUISITES_PART_COMPLETE, + ELIGIBILITY_PARTIAL, + SWORN_STATEMENT_FILE_ID, + null, + false, + ], + [ + ATTACHMENTS_PART_COMPLETE, + CERTIFICATION_PART_COMPLETE, + PREREQUISITES_PART_COMPLETE, + ELIGIBILITY_PARTIAL, + SWORN_STATEMENT_FILE_ID, + CANDIDATE_CONFIRMATION_DATE, + true, + ], + ])( + "should validate basic fields (attachments: %s, certification: %s, prerequisites: %s, eligibility: %s, sworn statement: %s, confirmation: %s) -> expected: %s", + async ( + attachments, + certification, + prerequisites, + eligibility, + swornStatement, + confirmation, + expected, + ) => { + const result = + await checkIsDFFReadyToBeSentToCertificationAuthorityById({ + attachmentsPartComplete: attachments, + certificationPartComplete: certification, + prerequisitesPartComplete: prerequisites, + competenceBlocsPartCompletion: COMPETENCE_BLOCS_TO_COMPLETE, + aapDecision: AAP_DECISION_NULL, + eligibilityRequirement: eligibility, + swornStatementFileId: swornStatement, + candidateConfirmationAt: confirmation, + }); + expect(result).toBe(expected); + }, + ); + }); + + describe("Partial eligibility scenarios", () => { + test.each([ + [COMPETENCE_BLOCS_TO_COMPLETE, AAP_DECISION_NULL, true], + [COMPETENCE_BLOCS_IN_PROGRESS, AAP_DECISION_NULL, true], + [COMPETENCE_BLOCS_COMPLETED, AAP_DECISION_NULL, true], + [COMPETENCE_BLOCS_TO_COMPLETE, AAP_DECISION_FAVORABLE, true], + [COMPETENCE_BLOCS_IN_PROGRESS, AAP_DECISION_FAVORABLE, true], + [COMPETENCE_BLOCS_COMPLETED, AAP_DECISION_FAVORABLE, true], + ])( + "should handle partial eligibility with competence blocs %s and AAP decision %s -> expected: %s", + async (competenceBlocs, aapDecision, expected) => { + const result = + await checkIsDFFReadyToBeSentToCertificationAuthorityById({ + attachmentsPartComplete: ATTACHMENTS_PART_COMPLETE, + certificationPartComplete: CERTIFICATION_PART_COMPLETE, + prerequisitesPartComplete: PREREQUISITES_PART_COMPLETE, + competenceBlocsPartCompletion: competenceBlocs, + aapDecision: aapDecision, + eligibilityRequirement: ELIGIBILITY_PARTIAL, + swornStatementFileId: SWORN_STATEMENT_FILE_ID, + candidateConfirmationAt: CANDIDATE_CONFIRMATION_DATE, + }); + expect(result).toBe(expected); + }, + ); + }); + + describe("Full eligibility scenarios", () => { + test.each([ + [COMPETENCE_BLOCS_TO_COMPLETE, AAP_DECISION_FAVORABLE, false], + [COMPETENCE_BLOCS_IN_PROGRESS, AAP_DECISION_FAVORABLE, false], + [COMPETENCE_BLOCS_COMPLETED, AAP_DECISION_NULL, false], + [COMPETENCE_BLOCS_COMPLETED, AAP_DECISION_FAVORABLE, true], + ])( + "should handle full eligibility with competence blocs %s and AAP decision %s -> expected: %s", + async (competenceBlocs, aapDecision, expected) => { + const result = + await checkIsDFFReadyToBeSentToCertificationAuthorityById({ + attachmentsPartComplete: ATTACHMENTS_PART_COMPLETE, + certificationPartComplete: CERTIFICATION_PART_COMPLETE, + prerequisitesPartComplete: PREREQUISITES_PART_COMPLETE, + competenceBlocsPartCompletion: competenceBlocs, + aapDecision: aapDecision, + eligibilityRequirement: ELIGIBILITY_FULL, + swornStatementFileId: SWORN_STATEMENT_FILE_ID, + candidateConfirmationAt: CANDIDATE_CONFIRMATION_DATE, + }); + expect(result).toBe(expected); + }, + ); + }); +});