Skip to content

Commit

Permalink
feat(api,admin): display error block on top of funding page when drop…
Browse files Browse the repository at this point in the history
… out was declared less than 6 months ago
  • Loading branch information
cedricss committed Aug 19, 2024
1 parent ec391bf commit 1d7a17f
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 1 deletion.
48 changes: 48 additions & 0 deletions packages/reva-admin-react/cypress/e2e/funding.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { stubQuery } from "../utils/graphql";
import { sub } from "date-fns";

function visitFunding({ dropOutCreationDate }: { dropOutCreationDate: Date }) {
cy.fixture("candidacy-drop-out-funding.json").then((candidacyDroppedOut) => {
candidacyDroppedOut.data.getCandidacyById.candidacyDropOut.createdAt =
dropOutCreationDate;

cy.intercept("POST", "/api/graphql", (req) => {
stubQuery(req, "activeFeaturesForConnectedUser", "active-features.json");
stubQuery(
req,
"getOrganismForAAPVisibilityCheck",
"visibility-check-admin.json",
);
stubQuery(req, "getAccountInfo", "account-admin.json");

stubQuery(req, "getCandidacyByIdFunding", candidacyDroppedOut);

stubQuery(
req,
"getCandidacyMenuAndCandidateInfos",
"candidacy-drop-out-menu.json",
);
});
});

cy.aap("/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/funding");
}

const sixMonthsAgo = sub(new Date(), { months: 6 });
const sixMonthsAgoMinusOneMinute = sub(new Date(), { months: 6, minutes: -1 });

context("Funding form", () => {
it("display a 'not available' alert when dropped-out less than 6 month ago", function () {
visitFunding({ dropOutCreationDate: sixMonthsAgoMinusOneMinute });
cy.wait("@getCandidacyByIdFunding");
cy.get('[data-test="funding-request-not-available"]').should("exist");
});

it("do not display any alert when dropped-out 6 month ago", function () {
visitFunding({ dropOutCreationDate: sixMonthsAgo });
cy.wait("@getCandidacyByIdFunding");
// Make sure the form is ready before testing non-existence of the alert
cy.get('[data-test="funding-form"]').should("exist");
cy.get('[data-test="funding-request-not-available"]').should("not.exist");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"data": {
"getCandidacyById": {
"financeModule": "unifvae",
"candidacyStatuses": [
{
"status": "PROJET",
"isActive": false
},
{
"status": "VALIDATION",
"isActive": false
},
{
"status": "PRISE_EN_CHARGE",
"isActive": false
},
{
"status": "PARCOURS_ENVOYE",
"isActive": false
},
{
"status": "PARCOURS_CONFIRME",
"isActive": false
},
{
"status": "DOSSIER_FAISABILITE_ENVOYE",
"isActive": false
},
{
"status": "DOSSIER_FAISABILITE_INCOMPLET",
"isActive": true
}
],
"candidacyDropOut": {
"createdAt": 1707305319452,
"droppedOutAt": 0
},
"certificateSkills": "RNCP A",
"otherTraining": "Texte B",
"basicSkills": [
{
"id": "d2eac236-723b-4bb8-ae4c-5d16d320ec72",
"label": "Usage et communication numérique"
}
],
"mandatoryTrainings": [
{
"id": "2790458c-040f-417d-b081-1d74b715ff9b",
"label": "Equipier de Première Intervention"
},
{
"id": "16ffd197-b95c-431c-890b-77bf58c51c6b",
"label": "Prévention et secours civiques de niveau 1 (PSC1)"
},
{
"id": "378724fb-ba6c-4686-92d9-c48b92534374",
"label": "Brevet national de sécurité et de sauvetage aquatique (BNSSA)"
}
],
"organism": {
"label": "Organism 1"
},
"candidate": {
"lastname": "Doe",
"firstname": "Alice",
"firstname2": null,
"firstname3": null,
"gender": null,
"email": "[email protected]",
"phone": "06000000"
},
"certification": {
"label": "CQP Technicien de la qualité"
},
"fundingRequestUnifvae": null
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"data": {
"candidacyMenu_getCandidacyMenu": {
"menuHeader": [
{
"label": "Résumé de la candidature",
"url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/summary",
"status": "ACTIVE_WITHOUT_HINT"
}
],
"mainMenu": [
{
"label": "Abandon du candidat confirmé le 7 février 2024",
"url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/drop-out",
"status": "ACTIVE_WITHOUT_HINT"
},
{
"label": "Demande de prise en charge",
"url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/funding",
"status": "ACTIVE_WITH_EDIT_HINT"
},
{
"label": "Demande de paiement",
"url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/payment/unifvae/invoice",
"status": "INACTIVE"
}
],
"menuFooter": [
{
"label": "Journal des actions",
"url": "/admin2/candidacies/46206f6b-0a59-4478-9338-45e3a8d968e4/logs",
"status": "ACTIVE_WITHOUT_HINT"
}
]
},
"getCandidacyById": {
"candidate": {
"lastname": "Doe",
"firstname": "Alice"
}
}
}
}
4 changes: 3 additions & 1 deletion packages/reva-admin-react/cypress/utils/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const hasOperationName = (req, operationName) => {
export const stubQuery = (req, operationName, fixture, statusCode = 200) => {
if (hasOperationName(req, operationName)) {
req.alias = operationName;
fixture && req.reply({ statusCode, fixture });
typeof fixture == "string" && fixture.endsWith(".json")
? req.reply({ statusCode, fixture })
: req.reply(statusCode, fixture);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const getCandidacyByIdFunding = graphql(`
isActive
}
candidacyDropOut {
createdAt
droppedOutAt
}
certificateSkills
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useCandidacyFunding } from "./_components/useCandidacyFunding.hook";
import { useFeatureflipping } from "@/components/feature-flipping/featureFlipping";
import { z } from "zod";
import Alert from "@codegouvfr/react-dsfr/Alert";
import { format, isAfter, isBefore, sub } from "date-fns";

const errorNumber = "Veuillez saisir une valeur numérique.";

Expand Down Expand Up @@ -237,8 +238,23 @@ const FundingPage = () => {
</p>
)}
</div>
{!isReadOnly &&
candidacy?.candidacyDropOut &&
isAfter(
candidacy?.candidacyDropOut?.createdAt,
sub(new Date(), { months: 6 }),
) && (
<Alert
data-test="funding-request-not-available"
className="mt-12 mb-6"
severity="error"
title="La demande de prise en charge n’est pas encore disponible"
description="Vous y aurez accès 6 mois après la mise en abandon du candidat."
/>
)}
<FormProvider {...methods}>
<form
data-test="funding-form"
className="flex flex-col"
onSubmit={handleSubmit(onSubmit)}
onReset={(e) => {
Expand Down
1 change: 1 addition & 0 deletions packages/reva-api/modules/candidacy/candidacy.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Candidacy {
}

type CandidacyDropOut {
createdAt: Timestamp!
dropOutReason: DropOutReason!
droppedOutAt: Timestamp!
otherReasonContent: String
Expand Down

0 comments on commit 1d7a17f

Please sign in to comment.