Skip to content

Commit

Permalink
test(api): split helpers to their own files and remove beforeAll wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDos committed Nov 21, 2024
1 parent 1675b01 commit 978357b
Show file tree
Hide file tree
Showing 23 changed files with 314 additions and 380 deletions.
8 changes: 5 additions & 3 deletions packages/reva-api/.env.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DATABASE_URL=postgresql://reva:password@localhost:5444/reva-test
# We prevent Keycloak update failures during local tests:
KEYCLOAK_APP_REALM=
DATABASE_URL=postgresql://reva:password@localhost:5444/reva-test
# We prevent Keycloak update failures during local tests:
KEYCLOAK_APP_REALM=

NODE_ENV=test
11 changes: 4 additions & 7 deletions packages/reva-api/modules/candidacy/candidacy.take-over.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ import { prismaClient } from "../../prisma/client";

import { Account } from "modules/account/account.types";
import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper";
import {
createCandidateFactory,
createOrganismFactory,
} from "../../test/helpers/create-db-entity";
import { createOrganismFactory } from "../../test/helpers/create-db-entity";
import { createCandidateHelper } from "../../test/helpers/entities/create-candidate-helper";
import { injectGraphql } from "../../test/helpers/graphql-helper";

let organismAccount: Account,
candidateMan: Candidate,
candidateWoman: Candidate,
Expand All @@ -28,8 +25,8 @@ beforeAll(async () => {
const organism = await createOrganismFactory();
organismAccount = organism.accounts[0];

candidateMan = await createCandidateFactory();
candidateWoman = await createCandidateFactory({ gender: Gender.woman });
candidateMan = await createCandidateHelper();
candidateWoman = await createCandidateHelper({ gender: Gender.woman });

candidacyProject = await prismaClient.candidacy.create({
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

import { prismaClient } from "../../../../prisma/client";
import { authorizationHeaderForUser } from "../../../../test/helpers/authorization-helper";
import {
createCandidacyFactory,
createCertificationFactory,
} from "../../../../test/helpers/create-db-entity";
import { createCandidacyFactory } from "../../../../test/helpers/create-db-entity";
import { injectGraphql } from "../../../../test/helpers/graphql-helper";

import { CandidacyStatusStep } from "@prisma/client";
import { randomUUID } from "crypto";
import { TRAINING_INPUT } from "../../../../test/fixtures";
import { createCertificationHelper } from "../../../../test/helpers/entities/create-certification-helper";
import { clearDatabase } from "../../../../test/jestClearDatabaseBeforeEachTestFile";

const submitTraining = async ({
Expand Down Expand Up @@ -98,7 +96,7 @@ test("a candidate should be able to select a new certification while a training
CandidacyStatusStep.PARCOURS_ENVOYE,
);
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId ?? "";
const certification = await createCertificationFactory();
const certification = await createCertificationHelper();
await submitTraining({
keycloakId: organismKeycloakId,
candidacyId: candidacy.id,
Expand Down Expand Up @@ -145,7 +143,7 @@ test("should reset the training and status when selecting a new certification",
);
const candidacyId = candidacy.id;
const organismKeycloakId = candidacy.organism?.accounts[0].keycloakId ?? "";
const certification = await createCertificationFactory();
const certification = await createCertificationHelper();
await submitTraining({
keycloakId: organismKeycloakId,
candidacyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { prismaClient } from "../../../prisma/client";
import { authorizationHeaderForUser } from "../../../test/helpers/authorization-helper";
import {
createCandidacyFactory,
createCandidateFactory,
createExpertBrancheOrganism,
createOrganismFactory,
} from "../../../test/helpers/create-db-entity";
import { injectGraphql } from "../../../test/helpers/graphql-helper";

import { CandidacyStatusStep } from "@prisma/client";
import { TRAINING_INPUT } from "../../../test/fixtures";
import { createCandidateHelper } from "../../../test/helpers/entities/create-candidate-helper";
import { clearDatabase } from "../../../test/jestClearDatabaseBeforeEachTestFile";

const selectNewOrganism = async ({
Expand Down Expand Up @@ -92,7 +92,7 @@ const confirmTraining = async ({
beforeEach(async () => {
await createOrganismFactory();
await createExpertBrancheOrganism();
await createCandidateFactory();
await createCandidateHelper();
const candidacy = await createCandidacyFactory();
const candidacyId = candidacy.id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { prismaClient } from "../../../prisma/client";
import { authorizationHeaderForUser } from "../../../test/helpers/authorization-helper";
import {
createCandidacyFactory,
createCandidateFactory,
createCertificationAuthorityFactory,
createCertificationAuthorityLocalAccountFactory,
createCertificationFactory,
createFeasibilityUploadedPdfFactory,
createOrganismFactory,
} from "../../../test/helpers/create-db-entity";
import { createCandidateHelper } from "../../../test/helpers/entities/create-candidate-helper";
import { createCertificationAuthorityHelper } from "../../../test/helpers/entities/create-certification-authority-helper";
import { createCertificationAuthorityLocalAccountHelper } from "../../../test/helpers/entities/create-certification-authority-local-account-helper";
import { createCertificationHelper } from "../../../test/helpers/entities/create-certification-helper";
import { injectGraphql } from "../../../test/helpers/graphql-helper";
import { clearDatabase } from "../../../test/jestClearDatabaseBeforeEachTestFile";

Expand Down Expand Up @@ -72,7 +72,7 @@ test("Candidate owning the candidacy should be able to access it", async () => {

test("Random candidate should not be able to access the candidacy", async () => {
const candidacy = await createCandidacyFactory();
const randomCandidate = await createCandidateFactory();
const randomCandidate = await createCandidateHelper();

const resp = await getCandidacy({
role: "candidate",
Expand Down Expand Up @@ -153,7 +153,7 @@ test("Random maison mere manager should not be able to access the candidacy", as
});

test("Certification authority manager of the feasibility file of the candidacy should be able to access it", async () => {
const certificationAuthority = await createCertificationAuthorityFactory();
const certificationAuthority = await createCertificationAuthorityHelper();

const feasibility = await createFeasibilityUploadedPdfFactory({
feasibilityArgs: {
Expand All @@ -174,7 +174,7 @@ test("Certification authority manager of the feasibility file of the candidacy s
});

test("Random Certification authority manager should not be able to access the candidacy", async () => {
const certificationAuthority = await createCertificationAuthorityFactory();
const certificationAuthority = await createCertificationAuthorityHelper();
const candidacy = await createCandidacyFactory();
const resp = await getCandidacy({
role: "manage_certification_authority_local_account",
Expand All @@ -190,9 +190,9 @@ test("Random Certification authority manager should not be able to access the ca

test("Certification local account of the feasibility file of the candidacy should be able to access it", async () => {
const certificationAuthorityLocalAccount =
await createCertificationAuthorityLocalAccountFactory();
await createCertificationAuthorityLocalAccountHelper();

const certification = await createCertificationFactory({
const certification = await createCertificationHelper({
certificationAuthorityStructureId:
certificationAuthorityLocalAccount.certificationAuthority
.certificationAuthorityStructureId,
Expand Down Expand Up @@ -240,7 +240,7 @@ test("Certification local account of the feasibility file of the candidacy shoul

test("Random Certification local account should not be able to access the candidacy", async () => {
const certificationAuthorityLocalAccount =
await createCertificationAuthorityLocalAccountFactory();
await createCertificationAuthorityLocalAccountHelper();
const candidacy = await createCandidacyFactory();
const resp = await getCandidacy({
role: "manage_feasibility",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Account } from "@prisma/client";
import { buildApp } from "../../infra/server/app";
import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper";
import {
createCertificationAuthorityLocalAccountFactory,
createCertificationAuthorityStructureFactory,
} from "../../test/helpers/create-db-entity";
import { createCertificationAuthorityLocalAccountHelper } from "../../test/helpers/entities/create-certification-authority-local-account-helper";
import { createCertificationAuthorityStructureHelper } from "../../test/helpers/entities/create-certification-authority-structure-helper";
import { injectGraphql } from "../../test/helpers/graphql-helper";
import keycloakPluginMock from "../../test/mocks/keycloak-plugin.mock";
import * as createAccount from "../account/features/createAccount";
Expand All @@ -16,7 +14,7 @@ beforeAll(async () => {

test("should return an exisiting certification local account list of 1 item for the certification authority", async () => {
const certificationAuthorityLocalAccount =
await createCertificationAuthorityLocalAccountFactory();
await createCertificationAuthorityLocalAccountHelper();

const resp = await injectGraphql({
fastify: (global as any).fastify,
Expand Down Expand Up @@ -47,7 +45,7 @@ test("should create a certification authority", async () => {
.mockImplementation(() => Promise.resolve({} as Account));

const certificationAuthorityStructure =
await createCertificationAuthorityStructureFactory();
await createCertificationAuthorityStructureHelper();

const resp = await injectGraphql({
fastify: (global as any).fastify,
Expand Down
16 changes: 7 additions & 9 deletions packages/reva-api/modules/feasibility/feasibility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import { FastifyInstance } from "fastify";
import { randomUUID } from "crypto";
import { prismaClient } from "../../prisma/client";
import { authorizationHeaderForUser } from "../../test/helpers/authorization-helper";
import {
createCertificationFactory,
createFeasibilityUploadedPdfFactory,
} from "../../test/helpers/create-db-entity";
import { createFeasibilityUploadedPdfFactory } from "../../test/helpers/create-db-entity";
import { createCertificationHelper } from "../../test/helpers/entities/create-certification-helper";
import { injectGraphql } from "../../test/helpers/graphql-helper";

afterEach(async () => {
Expand Down Expand Up @@ -49,7 +47,7 @@ test("should count all (2) feasibilities for admin user", async () => {
});

test("should count all (1) available feasibility for certificator user even if other exists on the same scope", async () => {
const certification = await createCertificationFactory({});
const certification = await createCertificationHelper({});
const certificationAuthority =
certification.certificationAuthorityStructure?.certificationAuthorities[0];
await createFeasibilityUploadedPdfFactory({
Expand Down Expand Up @@ -113,7 +111,7 @@ test("should count no available feasibility for certificator user since he doesn
});

test("should return a feasibilty for certificator since he is allowed to handle it", async () => {
const certification = await createCertificationFactory({});
const certification = await createCertificationHelper({});
const certificationAuthority =
certification.certificationAuthorityStructure?.certificationAuthorities[0];
const feasibility = await createFeasibilityUploadedPdfFactory({
Expand Down Expand Up @@ -173,7 +171,7 @@ test("should return a feasibility error for certificator 3 since he doesn't hand
});

test("should return all (1) available feasibility for certificateur user", async () => {
const certification = await createCertificationFactory({});
const certification = await createCertificationHelper({});
const certificationAuthority =
certification.certificationAuthorityStructure?.certificationAuthorities[0];
const feasibility = await createFeasibilityUploadedPdfFactory({
Expand Down Expand Up @@ -260,7 +258,7 @@ const postFeasibilityDecision = ({
};

test("should validate a feasibility since certificator is allowed to do so", async () => {
const certification = await createCertificationFactory({});
const certification = await createCertificationHelper({});
const certificationAuthority =
certification.certificationAuthorityStructure?.certificationAuthorities[0];
const feasiblity = await createFeasibilityUploadedPdfFactory({
Expand Down Expand Up @@ -328,7 +326,7 @@ test("should not validate a feasibility since certificator 3 doesn't handle it",
});

test("should reject a feasibility since certificator is allowed to do so", async () => {
const certification = await createCertificationFactory({});
const certification = await createCertificationHelper({});
const certificationAuthority =
certification.certificationAuthorityStructure?.certificationAuthorities[0];
const feasiblity = await createFeasibilityUploadedPdfFactory({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ test("Should generate a CSV stream with fundingRequest to be sent", async () =>
for await (const chunk of batchReadableStream) {
output += (chunk as Buffer).toString();
}
console.log(output);
expect(output).toBe(`field1;field2;field3;field4
123;abc, efg, l'alphabet;;0.5
234;"formation ""géniale"", manger debout";3;`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import {
PAYMENT_REQUEST,
} from "../../../../test/fixtures";
import { authorizationHeaderForUser } from "../../../../test/helpers/authorization-helper";
import {
createCandidateFactory,
createCertificationFactory,
createFeasibilityUploadedPdfFactory,
} from "../../../../test/helpers/create-db-entity";
import { createFeasibilityUploadedPdfFactory } from "../../../../test/helpers/create-db-entity";
import { createCandidateHelper } from "../../../../test/helpers/entities/create-candidate-helper";
import { createCertificationHelper } from "../../../../test/helpers/entities/create-certification-helper";
import { injectGraphql } from "../../../../test/helpers/graphql-helper";
import { clearDatabase } from "../../../../test/jestClearDatabaseBeforeEachTestFile";

Expand Down Expand Up @@ -76,7 +74,7 @@ const dropOutCandidacySixMonthsAgoMinusOneMinute = async ({
});

test("should create fundingRequestUnifvae with matching batch", async () => {
const candidate = await createCandidateFactory({
const candidate = await createCandidateHelper({
firstname: FUNDING_REQUEST_SAMPLE.fundingContactFirstname,
firstname2: FUNDING_REQUEST_SAMPLE.candidateSecondname,
firstname3: FUNDING_REQUEST_SAMPLE.candidateThirdname,
Expand Down Expand Up @@ -185,7 +183,7 @@ test("Should fail to create fundingRequestUnifvae when candidacy is not bound to
});

test("should fail to create a fundingRequestUnifvae whith a 'hors care' candidacy certification", async () => {
const certification = await createCertificationFactory({ rncpId: "000000" });
const certification = await createCertificationHelper({ rncpId: "000000" });
const feasibility = await createFeasibilityUploadedPdfFactory({
candidacyArgs: {
certificationId: certification.id,
Expand Down
Loading

0 comments on commit 978357b

Please sign in to comment.