Skip to content

Commit

Permalink
feat(api,admin-react): allow funding on drop-out less than 6 month ag…
Browse files Browse the repository at this point in the history
…o when proof received by admin
  • Loading branch information
cedricss committed Sep 9, 2024
1 parent 892b97b commit 3573f44
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 45 deletions.
31 changes: 28 additions & 3 deletions packages/reva-admin-react/cypress/e2e/candidacy/funding.cy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { stubQuery } from "../../utils/graphql";
import { sub } from "date-fns";

function visitFunding({ dropOutCreationDate }: { dropOutCreationDate?: Date }) {
function visitFunding({
dropOutCreationDate,
proofReceivedByAdmin,
}: {
dropOutCreationDate?: Date;
proofReceivedByAdmin?: boolean;
}) {
cy.fixture("candidacy/candidacy-drop-out-funding.json").then(
(candidacyDroppedOut) => {
if (dropOutCreationDate) {
candidacyDroppedOut.data.getCandidacyById.candidacyDropOut.createdAt =
dropOutCreationDate;
candidacyDroppedOut.data.getCandidacyById.candidacyDropOut.proofReceivedByAdmin =
proofReceivedByAdmin;
} else {
delete candidacyDroppedOut.data.getCandidacyById.candidacyDropOut;
}
Expand Down Expand Up @@ -43,13 +51,19 @@ 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 });
visitFunding({
dropOutCreationDate: sixMonthsAgoMinusOneMinute,
proofReceivedByAdmin: false,
});
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 });
visitFunding({
dropOutCreationDate: sixMonthsAgo,
proofReceivedByAdmin: false,
});
cy.wait("@getCandidacyByIdFunding");
// Make sure the form is ready before testing non-existence of the alert
cy.get('[data-test="funding-form"]').should("exist");
Expand All @@ -63,4 +77,15 @@ context("Funding form", () => {
cy.get('[data-test="funding-form"]').should("exist");
cy.get('[data-test="funding-request-not-available"]').should("not.exist");
});

it("do not display any alert when dropped-out less than 6 month ago but with proof received by admin", function () {
visitFunding({
dropOutCreationDate: sixMonthsAgoMinusOneMinute,
proofReceivedByAdmin: true,
});
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
Expand Up @@ -34,7 +34,8 @@
],
"candidacyDropOut": {
"createdAt": 1707305319452,
"droppedOutAt": 0
"droppedOutAt": 0,
"proofReceivedByAdmin": false
},
"certificateSkills": "RNCP A",
"otherTraining": "Texte B",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const getCandidacyByIdFunding = graphql(`
}
candidacyDropOut {
createdAt
proofReceivedByAdmin
}
certificateSkills
otherTraining
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ const FundingPage = () => {
</div>
{!isReadOnly &&
candidacy?.candidacyDropOut &&
!candidacy.candidacyDropOut.proofReceivedByAdmin &&
isAfter(
candidacy?.candidacyDropOut?.createdAt,
sub(new Date(), { months: 6 }),
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 @@ -76,6 +76,7 @@ type CandidacyDropOut {
createdAt: Timestamp!
dropOutReason: DropOutReason!
otherReasonContent: String
proofReceivedByAdmin: Boolean!
status: CandidacyStatusStep!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,45 @@ afterEach(async () => {
await prismaClient.candidacyDropOut.deleteMany();
});

const injectGraphqlFundingRequestCreation = async () =>
injectGraphql({
fastify: (global as any).fastify,
authorization: authorizationHeaderForUser({
role: "manage_candidacy",
keycloakId: gestionaMaisonMereAapAccount1.keycloakId,
}),
payload: {
requestType: "mutation",
endpoint: "candidacy_createFundingRequestUnifvae",
returnFields: "{ id }",
arguments: {
candidacyId: candidacyUnifvae.id,
fundingRequest: {
...fundingRequestSample,
},
},
enumFields: ["candidateGender"],
},
});

const dropOutCandidacySixMonthsAgoMinusOneMinute = async ({
proofReceivedByAdmin,
}: {
proofReceivedByAdmin: boolean;
}) =>
prismaClient.candidacy.update({
where: { id: candidacyUnifvae.id },
data: {
candidacyDropOut: {
create: {
...dropOutSixMonthsAgoMinusOneMinute,
dropOutReason: { connect: { label: "Autre" } },
proofReceivedByAdmin,
},
},
},
});

test("should create fundingRequestUnifvae with matching batch", async () => {
const resp = await injectGraphql({
fastify: (global as any).fastify,
Expand Down Expand Up @@ -200,40 +239,11 @@ test("should fetch fundingRequestUnifvae", async () => {
});

test("should fail to create fundingRequestUnifvae when candidacy was drop out less than 6 months ago then succeed after 6 months", async () => {
const createFundingRequest = async () =>
await injectGraphql({
fastify: (global as any).fastify,
authorization: authorizationHeaderForUser({
role: "manage_candidacy",
keycloakId: gestionaMaisonMereAapAccount1.keycloakId,
}),
payload: {
requestType: "mutation",
endpoint: "candidacy_createFundingRequestUnifvae",
returnFields: "{ id }",
arguments: {
candidacyId: candidacyUnifvae.id,
fundingRequest: {
...fundingRequestSample,
},
},
enumFields: ["candidateGender"],
},
});

await prismaClient.candidacy.update({
where: { id: candidacyUnifvae.id },
data: {
candidacyDropOut: {
create: {
...dropOutSixMonthsAgoMinusOneMinute,
dropOutReason: { create: { label: "dummy" } },
},
},
},
await dropOutCandidacySixMonthsAgoMinusOneMinute({
proofReceivedByAdmin: false,
});

const resp = await createFundingRequest();
const resp = await injectGraphqlFundingRequestCreation();

expect(resp.statusCode).toBe(200);
const obj = resp.json();
Expand All @@ -251,8 +261,18 @@ test("should fail to create fundingRequestUnifvae when candidacy was drop out le
},
});

const resp2 = await createFundingRequest();
const resp2 = await injectGraphqlFundingRequestCreation();

const obj2 = resp2.json();
expect(obj2).not.toHaveProperty("errors");
});

test("should allow the creation of fundingRequestUnifvae when candidacy was drop out less than 6 months ago but the proof was received by an admin", async () => {
await dropOutCandidacySixMonthsAgoMinusOneMinute({
proofReceivedByAdmin: true,
});

const resp = await injectGraphqlFundingRequestCreation();
const obj = resp.json();
expect(obj).not.toHaveProperty("errors");
});
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const unsafeResolvers = {

if (
candidacy.candidacyDropOut &&
!candidacy.candidacyDropOut.proofReceivedByAdmin &&
isAfter(
candidacy.candidacyDropOut.createdAt,
sub(new Date(), { months: 6 }),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "candidacy_drop_out" ADD COLUMN "proof_received_by_admin" BOOLEAN NOT NULL DEFAULT false;
17 changes: 9 additions & 8 deletions packages/reva-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,15 @@ model DropOutReason {
}

model CandidacyDropOut {
candidacy Candidacy @relation(fields: [candidacyId], references: [id])
candidacyId String @unique @map("candidacy_id") @db.Uuid
dropOutReason DropOutReason @relation(fields: [dropOutReasonId], references: [id])
dropOutReasonId String @map("drop_out_reason_id") @db.Uuid
status CandidacyStatusStep
otherReasonContent String? @map("other_reason_content")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
candidacy Candidacy @relation(fields: [candidacyId], references: [id])
candidacyId String @unique @map("candidacy_id") @db.Uuid
dropOutReason DropOutReason @relation(fields: [dropOutReasonId], references: [id])
dropOutReasonId String @map("drop_out_reason_id") @db.Uuid
status CandidacyStatusStep
otherReasonContent String? @map("other_reason_content")
proofReceivedByAdmin Boolean @default(false) @map("proof_received_by_admin")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
@@id([candidacyId])
@@map("candidacy_drop_out")
Expand Down

0 comments on commit 3573f44

Please sign in to comment.