Skip to content

Commit

Permalink
feat(candidate): drop out confirmation warning no shows when the drop…
Browse files Browse the repository at this point in the history
… out is more than 6 months old even if the candidate has not confirmed its drop out
  • Loading branch information
agarbe committed Jan 2, 2025
1 parent c0341d5 commit 6fbbdae
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { stubMutation, stubQuery } from "../../utils/graphql";
import candidateDropOut from "./fixtures/candidate-dropped-out.json";
import { subMonths } from "date-fns";

function interceptCandidacy({ droppedOut = false }: { droppedOut?: boolean }) {
function interceptCandidacy({
droppedOut = false,
proofReceivedByAdmin = false,
dropOutConfirmedByCandidate = false,
dropOutDate,
}: {
droppedOut?: boolean;
proofReceivedByAdmin?: boolean;
dropOutConfirmedByCandidate?: boolean;
dropOutDate?: Date;
}) {
cy.intercept("POST", "/api/graphql", (req) => {
stubMutation(req, "candidate_login", "candidate_login.json");

stubQuery(req, "candidate_getCandidateWithCandidacy", {
data: {
candidate_getCandidateWithCandidacy: {
Expand All @@ -13,8 +25,11 @@ function interceptCandidacy({ droppedOut = false }: { droppedOut?: boolean }) {
.candidacy,
candidacyDropOut: droppedOut
? {
createdAt: "2021-09-01T00:00:00Z",
dropOutConfirmedByCandidate: false,
createdAt: dropOutDate
? dropOutDate.toJSON()
: new Date().toJSON(),
proofReceivedByAdmin,
dropOutConfirmedByCandidate,
}
: null,
},
Expand All @@ -36,29 +51,83 @@ context("Candidacy dropout warning", () => {
"When the CANDIDACY_DROP_OUT_CANDIDATE_CONFIRMATION feature is activated",
() => {
context("When the candidacy has been dropped out", () => {
it("should show the warning when the drop out has not been confirmed", function () {
interceptCandidacy({ droppedOut: true });
cy.login();
cy.wait("@candidate_login");
cy.wait("@candidate_getCandidateWithCandidacy");
cy.wait("@activeFeaturesForConnectedUser");
context("And it has been less than 6 months since the drop out", () => {
it("should show the warning when the drop out has not been confirmed", function () {
interceptCandidacy({ droppedOut: true });
cy.login();
cy.wait("@candidate_login");
cy.wait("@candidate_getCandidateWithCandidacy");
cy.wait("@activeFeaturesForConnectedUser");

cy.get('[data-test="drop-out-warning"]').should("exist");
});
cy.get('[data-test="drop-out-warning"]').should("exist");
});

it("should let me click the decision button and lead me to the decision page", function () {
interceptCandidacy({ droppedOut: true });
cy.login();
cy.wait("@candidate_login");
cy.wait("@candidate_getCandidateWithCandidacy");
cy.wait("@activeFeaturesForConnectedUser");
it("should let me click the decision button and lead me to the decision page", function () {
interceptCandidacy({ droppedOut: true });
cy.login();
cy.wait("@candidate_login");
cy.wait("@candidate_getCandidateWithCandidacy");
cy.wait("@activeFeaturesForConnectedUser");

cy.get('[data-test="drop-out-warning-decision-button"]').click();
cy.url().should(
"eq",
"http://localhost:3004/candidat/candidacy-dropout-decision/",
);
});

cy.get('[data-test="drop-out-warning-decision-button"]').click();
cy.url().should(
"eq",
"http://localhost:3004/candidat/candidacy-dropout-decision/",
context("And a drop out proof has been given by the aap", () => {
it("should not show the decision button", function () {
interceptCandidacy({
droppedOut: true,
proofReceivedByAdmin: true,
});
cy.login();
cy.wait("@candidate_login");
cy.wait("@candidate_getCandidateWithCandidacy");
cy.wait("@activeFeaturesForConnectedUser");
cy.get('[data-test="drop-out-warning"]').should("exist");
cy.get('[data-test="drop-out-warning-decision-button"]').should(
"not.exist",
);
});
});
context(
"And the drop out has been confirmed by the candidate",
() => {
it("should not show the decision button", function () {
interceptCandidacy({
droppedOut: true,
dropOutConfirmedByCandidate: true,
});
cy.login();
cy.wait("@candidate_login");
cy.wait("@candidate_getCandidateWithCandidacy");
cy.wait("@activeFeaturesForConnectedUser");
cy.get('[data-test="drop-out-warning"]').should("exist");
cy.get('[data-test="drop-out-warning-decision-button"]').should(
"not.exist",
);
});
},
);
});
context("And it has been more than 6 months since the drop out", () => {
it("should not show the decision button", function () {
interceptCandidacy({
droppedOut: true,
dropOutDate: subMonths(new Date(), 6),
});
cy.login();
cy.wait("@candidate_login");
cy.wait("@candidate_getCandidateWithCandidacy");
cy.wait("@activeFeaturesForConnectedUser");
cy.get('[data-test="drop-out-warning"]').should("exist");
cy.get('[data-test="drop-out-warning-decision-button"]').should(
"not.exist",
);
});
});
});
context("When the candidacy has not been dropped out", () => {
it("should not show the warning", function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export const DropOutWarning = ({
dropOutDate,
className,
onDecisionButtonClick,
dropOutConfirmedByCandidate,
dropOutConfirmed,
}: {
dropOutDate: Date;
className?: string;
onDecisionButtonClick?: () => void;
dropOutConfirmedByCandidate?: boolean;
dropOutConfirmed?: boolean;
}) => (
<div
data-test="drop-out-warning"
Expand All @@ -31,12 +31,12 @@ export const DropOutWarning = ({
<div className="md:-ml-16 p-6 md:pl-24 border-b-4 border-fvae-hard-red shadow-[0px_6px_18px_0px_rgba(0,0,18,0.16)]">
Votre accompagnateur a déclaré l’abandon de votre parcours VAE le{" "}
{format(dropOutDate, "dd/MM/yyyy")}.{" "}
{dropOutConfirmedByCandidate
{dropOutConfirmed
? "Vous avez confirmé cette décision."
: "Vous avez 6 mois pour enregistrer votre décision : accepter l’abandon ou continuer votre parcours."}
</div>
</div>
{!dropOutConfirmedByCandidate && (
{!dropOutConfirmed && (
<Button
data-test="drop-out-warning-decision-button"
className="ml-auto -mt-3"
Expand Down
11 changes: 8 additions & 3 deletions packages/reva-candidate/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useRouter } from "next/navigation";
import { CandidacyBanner } from "./_components/CandidacyBanner";
import { useFeatureFlipping } from "@/components/feature-flipping/featureFlipping";
import { DropOutWarning } from "./_components/drop-out-warning/DropOutWarning";
import { isDropOutConfirmed } from "@/utils/dropOutHelper";

export default function Home() {
const { candidate, candidacy } = useCandidacy();
Expand Down Expand Up @@ -44,9 +45,13 @@ export default function Home() {
<DropOutWarning
className="mb-16"
dropOutDate={new Date(candidacy.candidacyDropOut.createdAt)}
dropOutConfirmedByCandidate={
candidacy.candidacyDropOut.dropOutConfirmedByCandidate
}
dropOutConfirmed={isDropOutConfirmed({
dropOutConfirmedByCandidate:
candidacy.candidacyDropOut.dropOutConfirmedByCandidate,
proofReceivedByAdmin:
candidacy.candidacyDropOut.proofReceivedByAdmin,
dropOutDate: new Date(candidacy.candidacyDropOut.createdAt),
})}
onDecisionButtonClick={() =>
router.push("/candidacy-dropout-decision")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const GET_CANDIDATE_WITH_CANDIDACY = graphql(`
candidacyDropOut {
createdAt
dropOutConfirmedByCandidate
proofReceivedByAdmin
}
candidacyStatuses {
id
Expand Down
17 changes: 17 additions & 0 deletions packages/reva-candidate/src/utils/dropOutHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { isAfter, addMonths } from "date-fns";

const isDropOutGracePeriodOver = ({ dropOutDate }: { dropOutDate: Date }) =>
isAfter(new Date(), addMonths(dropOutDate, 6));

export const isDropOutConfirmed = ({
dropOutConfirmedByCandidate,
proofReceivedByAdmin,
dropOutDate,
}: {
dropOutConfirmedByCandidate: boolean;
proofReceivedByAdmin: boolean;
dropOutDate: Date;
}) =>
dropOutConfirmedByCandidate ||
proofReceivedByAdmin ||
isDropOutGracePeriodOver({ dropOutDate });

0 comments on commit 6fbbdae

Please sign in to comment.