Skip to content

Commit

Permalink
chore(api): clean up create candidacy helper args
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDos committed Nov 22, 2024
1 parent e755d63 commit 725815b
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test("candidacy_takeOver should fail when candidacy manager has wrong organism",

test("candidacy_takeOver should do nothing when candidacy status is not validation", async function () {
const candidacy = await createCandidacyHelper({
status: CandidacyStatusStep.PROJET,
candidacyActiveStatus: CandidacyStatusStep.PROJET,
});
const resp = await injectGraphql({
fastify: (global as any).fastify,
Expand All @@ -93,7 +93,7 @@ test("candidacy_takeOver should do nothing when candidacy status is not validati

test("candidacy_takeOver should update candidacy statuses when active status is validation", async function () {
const candidacy = await createCandidacyHelper({
status: CandidacyStatusStep.VALIDATION,
candidacyActiveStatus: CandidacyStatusStep.VALIDATION,
});
const resp = await injectGraphql({
fastify: (global as any).fastify,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ afterEach(async () => {
});

test("candidate should be able to change it's type_accompagnement when the candidacy is still in project", async () => {
const candidacy = await createCandidacyHelper({}, CandidacyStatusStep.PROJET);
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.PROJET,
});
const candidateKeycloakId = candidacy.candidate?.keycloakId;

const resp = await injectGraphql({
Expand All @@ -38,10 +40,9 @@ test("candidate should be able to change it's type_accompagnement when the candi
});

test("candidate should NOT be able to change it's type_accompagnement when the candidacy is not in project", async () => {
const candidacy = await createCandidacyHelper(
{},
CandidacyStatusStep.VALIDATION,
);
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.VALIDATION,
});
const candidateKeycloakId = candidacy.candidate?.keycloakId;

const resp = await injectGraphql({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ afterEach(async () => {
});

test("a candidate should be able to select a new certification while a training is sent", async () => {
const candidacy = await createCandidacyHelper(
{},
CandidacyStatusStep.PARCOURS_ENVOYE,
);
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.PARCOURS_ENVOYE,
});
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId ?? "";
const certification = await createCertificationHelper();
await submitTraining({
Expand Down Expand Up @@ -137,10 +136,9 @@ test("a candidate should not be able to select a new certification after the tra
});

test("should reset the training and status when selecting a new certification", async () => {
const candidacy = await createCandidacyHelper(
{},
CandidacyStatusStep.PARCOURS_ENVOYE,
);
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.PARCOURS_ENVOYE,
});
const candidacyId = candidacy.id;
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId ?? "";
const certification = await createCertificationHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ describe("archive candidacy", () => {
}).rejects.toThrow(FunctionalCodeError.CANDIDACY_DOES_NOT_EXIST);
});
test("should fail with CANDIDACY_ALREADY_ARCHIVE", async () => {
const candidacyArchived = await createCandidacyHelper(
{},
CandidacyStatusStep.ARCHIVE,
);
const candidacyArchived = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.ARCHIVE,
});
await expect(async () => {
await archiveCandidacy({
candidacyId: candidacyArchived.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CandidacyStatusStep } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";
import { createCandidacyDropOutHelper } from "../../../test/helpers/entities/create-candidacy-drop-out-helper";

Expand Down Expand Up @@ -39,7 +40,9 @@ describe("cancel drop out candidacy", () => {
});

test("should return empty dropout reasons for the candidacy", async () => {
const candidacy = await createCandidacyHelper({}, "ARCHIVE");
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.ARCHIVE,
});
const candidacyDropOut = await prismaClient.candidacyDropOut.findUnique({
where: {
candidacyId: candidacy.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ afterEach(async () => {
});

test("a candidate should be able to select a new organism while a training is sent", async () => {
const candidacy = await createCandidacyHelper({}, CandidacyStatusStep.PROJET);
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.PROJET,
});
const candidacyId = candidacy.id;
const candidateKeycloakId = candidacy.candidate?.keycloakId ?? "";
const organismToSelect = await createOrganismHelper();
Expand Down Expand Up @@ -140,10 +142,9 @@ test("a candidate should not be able to select a new organism after the training
});

test("should reset the status to validation when selecting a new organism and status is prise_en_charge", async () => {
const candidacy = await createCandidacyHelper(
{},
CandidacyStatusStep.PRISE_EN_CHARGE,
);
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.PRISE_EN_CHARGE,
});
const candidacyId = candidacy.id;
const candidateKeycloakId = candidacy.candidate?.keycloakId ?? "";
const organism = await createOrganismHelper();
Expand All @@ -164,10 +165,9 @@ test("should reset the status to validation when selecting a new organism and st
});

test("should reset the training and update the status when selecting a new organism", async () => {
const candidacy = await createCandidacyHelper(
{},
CandidacyStatusStep.PARCOURS_ENVOYE,
);
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.PARCOURS_ENVOYE,
});
const candidacyId = candidacy.id;
const candidateKeycloakId = candidacy.candidate?.keycloakId ?? "";
const organism = await createOrganismHelper();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CandidacyStatusStep } from "@prisma/client";
import { createCandidacyHelper } from "../../../test/helpers/entities/create-candidacy-helper";
import { createReorientationReasonHelper } from "../../../test/helpers/entities/create-reorientation-reason-helper";
import { FunctionalCodeError } from "../../shared/error/functionalError";
Expand All @@ -24,12 +25,12 @@ describe("unarchive candidacy", () => {

test("should fail with CANDIDACY_IS_REORIENTATION", async () => {
const reorientationReason = await createReorientationReasonHelper();
const candidacy = await createCandidacyHelper(
{
const candidacy = await createCandidacyHelper({
candidacyArgs: {
reorientationReasonId: reorientationReason.id,
},
"ARCHIVE",
);
candidacyActiveStatus: CandidacyStatusStep.ARCHIVE,
});
await expect(async () => {
await unarchiveCandidacy({
candidacyId: candidacy.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ test("Random candidate should not be able to access the candidacy", async () =>
test("Aap associated to the candidacy should be able to access it", async () => {
const organism = await createOrganismHelper();
const candidacy = await createCandidacyHelper({
organismId: organism.id,
candidacyArgs: {
organismId: organism.id,
},
});

const resp = await getCandidacy({
Expand All @@ -104,7 +106,7 @@ test("Aap associated to the candidacy should be able to access it", async () =>

test("Random aap should not be able to access the candidacy", async () => {
const organism = await createOrganismHelper();
const candidacy = await createCandidacyHelper({});
const candidacy = await createCandidacyHelper();
const resp = await getCandidacy({
role: "manage_candidacy",
keycloakId: organism.accounts[0].keycloakId,
Expand All @@ -120,7 +122,9 @@ test("Random aap should not be able to access the candidacy", async () => {
test("Maison mere manager of the aap associated to the candidacy should be able to access it", async () => {
const organism = await createOrganismHelper();
const candidacy = await createCandidacyHelper({
organismId: organism.id,
candidacyArgs: {
organismId: organism.id,
},
});

const resp = await getCandidacy({
Expand Down
43 changes: 22 additions & 21 deletions packages/reva-api/modules/candidacy/training/training.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ afterEach(async () => {
});

test("AAP should not be able to submit a training form if its status is in 'PROJET'", async () => {
const candidacy = await createCandidacyHelper({}, CandidacyStatusStep.PROJET);
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.PROJET,
});
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId;

const resp = await injectGraphql({
Expand All @@ -41,10 +43,9 @@ test("AAP should not be able to submit a training form if its status is in 'PROJ
});

test("AAP should be able to submit a basic training form when candidacy status is 'PRISE_EN_CHARGE' and its finance module is 'unifvae'", async () => {
const candidacy = await createCandidacyHelper(
{},
CandidacyStatusStep.PRISE_EN_CHARGE,
);
const candidacy = await createCandidacyHelper({
candidacyActiveStatus: CandidacyStatusStep.PRISE_EN_CHARGE,
});
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId;

const resp = await injectGraphql({
Expand All @@ -70,12 +71,12 @@ test("AAP should be able to submit a basic training form when candidacy status i
});

test("AAP should not be able to submit a basic training form without an estimated costwhen candidacy financeModule is 'hors_plateforme'", async () => {
const candidacy = await createCandidacyHelper(
{
const candidacy = await createCandidacyHelper({
candidacyArgs: {
financeModule: "hors_plateforme",
},
CandidacyStatusStep.PRISE_EN_CHARGE,
);
candidacyActiveStatus: CandidacyStatusStep.PRISE_EN_CHARGE,
});
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId;

const resp = await injectGraphql({
Expand All @@ -101,12 +102,12 @@ test("AAP should not be able to submit a basic training form without an estimate
});

test("AAP should not be able to submit a basic training form without at least one financing method when candidacy financeModule is 'hors_plateforme'", async () => {
const candidacy = await createCandidacyHelper(
{
const candidacy = await createCandidacyHelper({
candidacyArgs: {
financeModule: "hors_plateforme",
},
CandidacyStatusStep.PRISE_EN_CHARGE,
);
candidacyActiveStatus: CandidacyStatusStep.PRISE_EN_CHARGE,
});
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId;

const resp = await injectGraphql({
Expand All @@ -132,12 +133,12 @@ test("AAP should not be able to submit a basic training form without at least on
});

test("AAP should not be able to submit a basic training form without a text when the 'other source' financing method has been checked", async () => {
const candidacy = await createCandidacyHelper(
{
const candidacy = await createCandidacyHelper({
candidacyArgs: {
financeModule: "hors_plateforme",
},
CandidacyStatusStep.PRISE_EN_CHARGE,
);
candidacyActiveStatus: CandidacyStatusStep.PRISE_EN_CHARGE,
});
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId;

const resp = await injectGraphql({
Expand Down Expand Up @@ -169,12 +170,12 @@ test("AAP should not be able to submit a basic training form without a text when
});

test("AAP should be able to submit a basic training form when candidacy status is 'PRISE_EN_CHARGE' and its finance module is 'hors_plateforme'", async () => {
const candidacy = await createCandidacyHelper(
{
const candidacy = await createCandidacyHelper({
candidacyArgs: {
financeModule: "hors_plateforme",
},
CandidacyStatusStep.PRISE_EN_CHARGE,
);
candidacyActiveStatus: CandidacyStatusStep.PRISE_EN_CHARGE,
});
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId;

const resp = await injectGraphql({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { createCandidateHelper } from "./create-candidate-helper";
import { createCertificationHelper } from "./create-certification-helper";
import { createOrganismHelper } from "./create-organism-helper";

export const createCandidacyHelper = async (
candidacyArgs?: Partial<Candidacy>,
candidacyActiveStatus?: CandidacyStatusStep,
) => {
export const createCandidacyHelper = async (args?: {
candidacyArgs?: Partial<Candidacy>;
candidacyActiveStatus?: CandidacyStatusStep;
}) => {
const { candidacyArgs, candidacyActiveStatus } = args ?? {};

const certification = await createCertificationHelper();
const department = await prismaClient.department.findFirst({
where: { code: "75" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export const createFeasibilityDematerializedHelper = async ({
candidacyArgs?: Partial<Candidacy>;
candidacyActiveStatus?: CandidacyStatusStep;
}) => {
const candidacy = await createCandidacyHelper(
const candidacy = await createCandidacyHelper({
candidacyArgs,
candidacyActiveStatus,
);
});

return prismaClient.feasibility.create({
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export const createFeasibilityUploadedPdfHelper = async ({
candidacyArgs?: Partial<Candidacy>;
candidacyActiveStatus?: CandidacyStatusStep;
}) => {
const candidacy = await createCandidacyHelper(
const candidacy = await createCandidacyHelper({
candidacyArgs,
candidacyActiveStatus,
);
});
const file = await createFileHelper();

return prismaClient.feasibility.create({
Expand Down

0 comments on commit 725815b

Please sign in to comment.