Skip to content

Commit

Permalink
test(api): move organism fixtures to their own file and fill missing …
Browse files Browse the repository at this point in the history
…mocked values
  • Loading branch information
ThomasDos committed Nov 13, 2024
1 parent f7ed50b commit b5dba6a
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 116 deletions.
18 changes: 10 additions & 8 deletions packages/reva-api/modules/candidacy/candidacy.take-over.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import {
} from "@prisma/client";

import { prismaClient } from "../../prisma/client";
import { CANDIDATE_MAN, CANDIDATE_WOMAN } from "../../test/fixtures/candidate";

import {
expertBrancheOrganism,
expertFiliereOrganism,
} from "../../test/fixtures/people-organisms";
CANDIDATE_MAN,
CANDIDATE_WOMAN,
EXPERT_BRANCHE_ORGANISM,
EXPERT_FILIERE_ORGANISM,
} from "../../test/fixtures";
import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper";
import { injectGraphql } from "../../test/helpers/graphql-helper";

Expand All @@ -34,21 +36,21 @@ beforeAll(async () => {
where: { code: "75" },
});
wrongOrganism = await prismaClient.organism.create({
data: expertFiliereOrganism,
data: EXPERT_FILIERE_ORGANISM,
});
wrongCandidacyManager = await prismaClient.account.create({
data: {
email: expertFiliereOrganism.contactAdministrativeEmail,
email: EXPERT_FILIERE_ORGANISM.contactAdministrativeEmail,
keycloakId: wrongCandidacyManagerKcId,
organismId: wrongOrganism.id,
},
});
rightOrganism = await prismaClient.organism.create({
data: expertBrancheOrganism,
data: EXPERT_BRANCHE_ORGANISM,
});
rightCandidacyManager = await prismaClient.account.create({
data: {
email: expertBrancheOrganism.contactAdministrativeEmail,
email: EXPERT_BRANCHE_ORGANISM.contactAdministrativeEmail,
keycloakId: rightCandidacyManagerKcId,
organismId: rightOrganism.id,
},
Expand Down
7 changes: 4 additions & 3 deletions packages/reva-api/modules/candidacy/candidacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import { Candidacy, Candidate, Organism } from "@prisma/client";

import { prismaClient } from "../../prisma/client";
import { CANDIDATE_MAN } from "../../test/fixtures/candidate";
import { organismIperia } from "../../test/fixtures/people-organisms";
import { CANDIDATE_MAN, ORGANISM_EXPERIMENTATION } from "../../test/fixtures";
import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper";
import { injectGraphql } from "../../test/helpers/graphql-helper";

Expand All @@ -16,7 +15,9 @@ beforeAll(async () => {
where: { code: "75" },
});

organism = await prismaClient.organism.create({ data: organismIperia });
organism = await prismaClient.organism.create({
data: ORGANISM_EXPERIMENTATION,
});
candidate = await prismaClient.candidate.create({
data: { ...CANDIDATE_MAN, departmentId: ileDeFrance?.id || "" },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { Candidacy } from "@prisma/client";

import { prismaClient } from "../../prisma/client";
import { CANDIDATE_MAN } from "../../test/fixtures/candidate";
import { CANDIDATE_MAN } from "../../test/fixtures";
import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper";
import {
createCandidacyUnifvae,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
import { injectGraphql } from "../../../../test/helpers/graphql-helper";

import { Candidacy, CandidacyStatusStep } from "@prisma/client";
import { CANDIDATE_MAN } from "../../../../test/fixtures";
import { certificationId2FromSeed } from "../../../../test/fixtures/candidacy";
import { CANDIDATE_MAN } from "../../../../test/fixtures/candidate";
import { basicTrainingForm } from "../../../../test/fixtures/training";
import { clearDatabase } from "../../../../test/jestClearDatabaseBeforeEachTestFile";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
ReorientationReason,
} from "@prisma/client";
import { prismaClient } from "../../../prisma/client";
import { CANDIDATE_MAN } from "../../../test/fixtures/candidate";
import { organismIperia } from "../../../test/fixtures/people-organisms";

import {
CANDIDATE_MAN,
ORGANISM_EXPERIMENTATION,
} from "../../../test/fixtures";
import { FunctionalCodeError } from "../../shared/error/functionalError";
import { archiveCandidacy } from "./archiveCandidacy";
import { getCandidacyStatusesByCandidacyId } from "./getCandidacyStatusesByCandidacyId";
Expand Down Expand Up @@ -66,7 +69,9 @@ beforeAll(async () => {
parisDepartment = (await prismaClient.department.findFirst({
where: { code: "75" },
})) as Department;
organism = await prismaClient.organism.create({ data: organismIperia });
organism = await prismaClient.organism.create({
data: ORGANISM_EXPERIMENTATION,
});

candidate = await prismaClient.candidate.create({
data: { ...CANDIDATE_MAN, departmentId: parisDepartment?.id || "" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Candidacy } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";

import { CANDIDATE_MAN } from "../../../test/fixtures/candidate";
import { CANDIDATE_MAN } from "../../../test/fixtures";
import { FunctionalCodeError } from "../../shared/error/functionalError";
import { cancelDropOutCandidacy } from "./cancelDropOutCandidacy";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Candidacy } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";

import { CANDIDATE_MAN } from "../../../test/fixtures/candidate";
import { CANDIDATE_MAN } from "../../../test/fixtures";
import { FunctionalCodeError } from "../../shared/error/functionalError";
import { dropOutCandidacy } from "./dropOutCandidacy";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
*/

import { prismaClient } from "../../../prisma/client";
import {
expertBrancheOrganism,
gestionnaireMaisonMereAAP1,
} from "../../../test/fixtures/people-organisms";
import { gestionnaireMaisonMereAAP1 } from "../../../test/fixtures/people-organisms";
import { authorizationHeaderForUser } from "../../../test/helpers/authorization-helper";
import {
createCandidacyUnifvae,
Expand All @@ -17,8 +14,8 @@ import {
import { injectGraphql } from "../../../test/helpers/graphql-helper";

import { CandidacyStatusStep } from "@prisma/client";
import { CANDIDATE_MAN, EXPERT_BRANCHE_ORGANISM } from "../../../test/fixtures";
import { candidacyUnifvae } from "../../../test/fixtures/candidacy";
import { CANDIDATE_MAN } from "../../../test/fixtures/candidate";
import { basicTrainingForm } from "../../../test/fixtures/training";
import { clearDatabase } from "../../../test/jestClearDatabaseBeforeEachTestFile";

Expand All @@ -34,7 +31,7 @@ const selectNewOrganism = async () =>
endpoint: "candidacy_selectOrganism",
arguments: {
candidacyId: candidacyUnifvae.id,
organismId: expertBrancheOrganism.id,
organismId: EXPERT_BRANCHE_ORGANISM.id,
},
returnFields: "{id,organismId}",
},
Expand Down Expand Up @@ -110,7 +107,7 @@ test("a candidate should be able to select a new organism while a training is se
expect(resp.statusCode).toEqual(200);
expect(resp.json().data.candidacy_selectOrganism).toMatchObject({
id: candidacyUnifvae.id,
organismId: expertBrancheOrganism.id,
organismId: EXPERT_BRANCHE_ORGANISM.id,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
} from "@prisma/client";
import { sub } from "date-fns";
import { prismaClient } from "../../../prisma/client";
import { CANDIDATE_MAN } from "../../../test/fixtures/candidate";
import { organismIperia } from "../../../test/fixtures/people-organisms";
import {
CANDIDATE_MAN,
ORGANISM_EXPERIMENTATION,
} from "../../../test/fixtures";
import { FunctionalCodeError } from "../../shared/error/functionalError";
import { getCandidacyStatusesByCandidacyId } from "./getCandidacyStatusesByCandidacyId";
import { unarchiveCandidacy } from "./unarchiveCandidacy";
Expand Down Expand Up @@ -71,7 +73,9 @@ beforeAll(async () => {
parisDepartment = (await prismaClient.department.findFirst({
where: { code: "75" },
})) as Department;
organism = await prismaClient.organism.create({ data: organismIperia });
organism = await prismaClient.organism.create({
data: ORGANISM_EXPERIMENTATION,
});

candidate = await prismaClient.candidate.create({
data: { ...CANDIDATE_MAN, departmentId: parisDepartment?.id || "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ import { prismaClient } from "../../../prisma/client";
import {
CANDIDATE_MAN,
CANDIDATE_WOMAN,
} from "../../../test/fixtures/candidate";
EXPERT_BRANCHE_ET_FILIERE_ORGANISM,
ORGANISM_EXPERIMENTATION,
} from "../../../test/fixtures";
import { certificationAuthorityStructureFixtures } from "../../../test/fixtures/certification";
import {
expertBrancheEtFiliereOrganism,
organismIperia,
} from "../../../test/fixtures/people-organisms";
import { authorizationHeaderForUser } from "../../../test/helpers/authorization-helper";
import { injectGraphql } from "../../../test/helpers/graphql-helper";

Expand Down Expand Up @@ -89,7 +87,7 @@ beforeAll(async () => {
});

organism = await prismaClient.organism.create({
data: { ...organismIperia, maisonMereAAPId: maisonMereAAp.id },
data: { ...ORGANISM_EXPERIMENTATION, maisonMereAAPId: maisonMereAAp.id },
});

aapAccount = await prismaClient.account.create({
Expand All @@ -101,7 +99,7 @@ beforeAll(async () => {
});

randomOrganism = await prismaClient.organism.create({
data: expertBrancheEtFiliereOrganism,
data: EXPERT_BRANCHE_ET_FILIERE_ORGANISM,
});

randomAapAccount = await prismaClient.account.create({
Expand Down
7 changes: 4 additions & 3 deletions packages/reva-api/modules/feasibility/feasibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import {
import { FastifyInstance } from "fastify";

import { prismaClient } from "../../prisma/client";
import { CANDIDATE_MAN } from "../../test/fixtures/candidate";
import { CANDIDATE_MAN, ORGANISM_EXPERIMENTATION } from "../../test/fixtures";
import { certificationAuthorityStructureFixtures } from "../../test/fixtures/certification";
import { organismIperia } from "../../test/fixtures/people-organisms";
import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper";
import { injectGraphql } from "../../test/helpers/graphql-helper";

Expand All @@ -39,7 +38,9 @@ beforeAll(async () => {
where: { code: "75" },
})) as Department;

organism = await prismaClient.organism.create({ data: organismIperia });
organism = await prismaClient.organism.create({
data: ORGANISM_EXPERIMENTATION,
});

candidate = await prismaClient.candidate.create({
data: { ...CANDIDATE_MAN, departmentId: parisDepartment?.id || "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import { CandidacyStatusStep } from "@prisma/client";

import { prismaClient } from "../../../../prisma/client";

import {
CANDIDATE_MAN,
EXPERT_FILIERE_ORGANISM,
} from "../../../../test/fixtures";
import {
candidacyUnifvae,
candidacyUnireva,
dropOutSixMonthsAgo,
dropOutSixMonthsAgoMinusOneMinute,
} from "../../../../test/fixtures/candidacy";
import { CANDIDATE_MAN } from "../../../../test/fixtures/candidate";
import {
fundingRequestSample,
paymentRequestInputBase,
} from "../../../../test/fixtures/funding-request";
import {
expertFiliereOrganism,
gestionnaireMaisonMereAAP1,
} from "../../../../test/fixtures/people-organisms";
import { gestionnaireMaisonMereAAP1 } from "../../../../test/fixtures/people-organisms";
import { authorizationHeaderForUser } from "../../../../test/helpers/authorization-helper";
import {
createCandidacyUnifvae,
Expand Down Expand Up @@ -177,8 +177,7 @@ test("should create fundingRequestUnifvae with matching batch", async () => {
expect(myFundReqBatch).toMatchObject({
sent: false,
content: {
SiretAP: expertFiliereOrganism.siret,
// Certification: ,
SiretAP: EXPERT_FILIERE_ORGANISM.siret,
NomCandidat: myCandidate.lastname,
PrenomCandidat1: myCandidate.firstname,
PrenomCandidat2: myCandidate.firstname2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@prisma/client";

import { prismaClient } from "../../../../prisma/client";
import { expertFiliereOrganism } from "../../../../test/fixtures/people-organisms";
import { EXPERT_FILIERE_ORGANISM } from "../../../../test/fixtures";
import { createBatchFromFundingRequestUnifvae } from "./fundingRequestBatch";

let certif: Certification | null = null,
Expand All @@ -25,7 +25,7 @@ const candidateSample = {

beforeAll(async () => {
aap = await prismaClient.organism.create({
data: expertFiliereOrganism,
data: EXPERT_FILIERE_ORGANISM,
});
certif = await prismaClient.certification.findFirst({
where: { label: "CAP Boucher" },
Expand Down
20 changes: 11 additions & 9 deletions packages/reva-api/modules/referential/referential.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ import { Organism } from "@prisma/client";

import { prismaClient } from "../../prisma/client";
import {
expertBrancheEtFiliereOrganism,
expertBrancheOrganism,
expertFiliereOrganism,
EXPERT_BRANCHE_ET_FILIERE_ORGANISM,
EXPERT_BRANCHE_ORGANISM,
EXPERT_FILIERE_ORGANISM,
} from "../../test/fixtures";
import {
gestionnaireMaisonMereAAP1,
maisonMereAAPExpertFiliere,
gestionnaireMaisonMereAAP2,
maisonMereAAPExpertBranche,
maisonMereAAPExpertFiliere,
} from "../../test/fixtures/people-organisms";
import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper";
import { injectGraphql } from "../../test/helpers/graphql-helper";
import {
createGestionnaireMaisonMereAapAccount1,
createGestionnaireMaisonMereAapAccount2,
createMaisonMereAAPExpertFiliere,
createMaisonMereAAPExpertBranche,
createMaisonMereAAPExpertFiliere,
} from "../../test/helpers/create-db-entity";
import { injectGraphql } from "../../test/helpers/graphql-helper";

async function attachOrganismToAllDegrees(organism: Organism | null) {
const degrees = await prismaClient.degree.findMany();
Expand Down Expand Up @@ -84,7 +86,7 @@ beforeAll(async () => {
await createMaisonMereAAPExpertBranche();

expertFiliere = await prismaClient.organism.create({
data: expertFiliereOrganism,
data: EXPERT_FILIERE_ORGANISM,
});

await prismaClient.maisonMereAAP.update({
Expand All @@ -97,7 +99,7 @@ beforeAll(async () => {
});

expertBranche = await prismaClient.organism.create({
data: expertBrancheOrganism,
data: EXPERT_BRANCHE_ORGANISM,
});

await prismaClient.maisonMereAAP.update({
Expand All @@ -110,7 +112,7 @@ beforeAll(async () => {
});

await prismaClient.organism.create({
data: expertBrancheEtFiliereOrganism,
data: EXPERT_BRANCHE_ET_FILIERE_ORGANISM,
});

// Branche fixtures (also known as Convention Collective)
Expand Down
6 changes: 3 additions & 3 deletions packages/reva-api/test/fixtures/candidacy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { CandidacyStatusStep, FinanceModule } from "@prisma/client";
import { randomUUID } from "crypto";
import { sub } from "date-fns";
import { expertFiliereOrganism } from "./people-organisms";
import { CANDIDATE_MAN } from "./candidate";
import { CANDIDATE_MAN } from "./candidates.fixture";
import { EXPERT_FILIERE_ORGANISM } from "./organisms.fixture";

const certificationId1FromSeed = "51eef7ae-80c0-481b-946f-9d6e1b9fc70c";

export const certificationId2FromSeed = "2f1c2d5f-8b24-471b-8824-b7f5cb4f7bb8";

export const candidacyUnifvae = {
id: randomUUID(),
organismId: expertFiliereOrganism.id,
organismId: EXPERT_FILIERE_ORGANISM.id,
financeModule: FinanceModule.unifvae,
candidateId: CANDIDATE_MAN.id,
isCertificationPartial: false,
Expand Down
2 changes: 2 additions & 0 deletions packages/reva-api/test/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./candidates.fixture";
export * from "./organisms.fixture";
Loading

0 comments on commit b5dba6a

Please sign in to comment.