Skip to content

Commit

Permalink
style(api): added missing folders test scripts and prisma/seed
Browse files Browse the repository at this point in the history
  • Loading branch information
fbonniec committed Dec 3, 2024
1 parent 784031b commit be88be9
Show file tree
Hide file tree
Showing 23 changed files with 405 additions and 401 deletions.
2 changes: 1 addition & 1 deletion packages/reva-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"prisma:generate:migration": "prisma migrate dev --create-only",
"cron": "npx [email protected] infra/cron.ts",
"cron-dev": "npx [email protected] infra/cron.ts | npx pino-pretty",
"lint": "eslint --color modules infra"
"lint": "eslint --color modules infra test scripts prisma/seed"
},
"prisma": {
"seed": "npx tsx prisma/seed/seed.ts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function readCsvRows<T>({
});
}

export async function seedFormacode() {
async function seedFormacode() {
const prisma = new PrismaClient();

await prisma.$transaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export async function insertBasicSkillsIfNone(prisma: PrismaClient) {
data: [
{ label: "Usage et communication numérique" },
{
label: "Utilisation des règles de base de calcul et du raisonnement mathématique",
label:
"Utilisation des règles de base de calcul et du raisonnement mathématique",
},
{ label: "Communication en français" },
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { PrismaClient } from "@prisma/client";

export async function insertVulnerabilityIndicatorsIfNone(prisma: PrismaClient) {
const vulnerabilityIndicatorsCount = await prisma.vulnerabilityIndicator.count();
export async function insertVulnerabilityIndicatorsIfNone(
prisma: PrismaClient,
) {
const vulnerabilityIndicatorsCount =
await prisma.vulnerabilityIndicator.count();

if (vulnerabilityIndicatorsCount === 0) {
await prisma.vulnerabilityIndicator.createMany({
Expand Down
12 changes: 6 additions & 6 deletions packages/reva-api/test/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./basic-skills.fixtures";
export * from "./candidacies.fixture";
export * from "./feasibilities.fixture";
export * from "./funding-requests.fixture";
export * from "./payment-requests.fixture";
export * from "./trainings.fixture";
export * from "./basic-skills.fixtures";
export * from "./candidacies.fixture";
export * from "./feasibilities.fixture";
export * from "./funding-requests.fixture";
export * from "./payment-requests.fixture";
export * from "./trainings.fixture";
30 changes: 15 additions & 15 deletions packages/reva-api/test/fixtures/payment-requests.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export const PAYMENT_REQUEST = {
individualEffectiveHourCount: 0,
individualEffectiveCost: 0,
collectiveEffectiveHourCount: 0,
collectiveEffectiveCost: 0,
mandatoryTrainingsEffectiveHourCount: 0,
mandatoryTrainingsEffectiveCost: 0,
basicSkillsEffectiveHourCount: 0,
basicSkillsEffectiveCost: 0,
certificateSkillsEffectiveHourCount: 0,
certificateSkillsEffectiveCost: 0,
otherTrainingEffectiveHourCount: 0,
otherTrainingEffectiveCost: 0,
invoiceNumber: "Invoice-001",
};
export const PAYMENT_REQUEST = {
individualEffectiveHourCount: 0,
individualEffectiveCost: 0,
collectiveEffectiveHourCount: 0,
collectiveEffectiveCost: 0,
mandatoryTrainingsEffectiveHourCount: 0,
mandatoryTrainingsEffectiveCost: 0,
basicSkillsEffectiveHourCount: 0,
basicSkillsEffectiveCost: 0,
certificateSkillsEffectiveHourCount: 0,
certificateSkillsEffectiveCost: 0,
otherTrainingEffectiveHourCount: 0,
otherTrainingEffectiveCost: 0,
invoiceNumber: "Invoice-001",
};
32 changes: 16 additions & 16 deletions packages/reva-api/test/helpers/attach-organism-to-all-ccn-helper.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Organism } from "@prisma/client";
import { prismaClient } from "../../prisma/client";

export async function attachOrganismToAllConventionCollectiveHelper(
organism: Organism | null,
) {
const ccn = await prismaClient.conventionCollective.findMany();
for (const c of ccn) {
await prismaClient.organismOnConventionCollective.create({
data: {
organismId: organism?.id || "",
ccnId: c.id,
},
});
}
}
import { Organism } from "@prisma/client";
import { prismaClient } from "../../prisma/client";

export async function attachOrganismToAllConventionCollectiveHelper(
organism: Organism | null,
) {
const ccn = await prismaClient.conventionCollective.findMany();
for (const c of ccn) {
await prismaClient.organismOnConventionCollective.create({
data: {
organismId: organism?.id || "",
ccnId: c.id,
},
});
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Organism } from "@prisma/client";
import { prismaClient } from "../../prisma/client";

export async function attachOrganismToAllDegreesHelper(
organism: Organism | null,
) {
const degrees = await prismaClient.degree.findMany();
for (const degree of degrees) {
await prismaClient.organismOnDegree.create({
data: {
degreeId: degree?.id || "",
organismId: organism?.id || "",
},
});
}
}
import { Organism } from "@prisma/client";
import { prismaClient } from "../../prisma/client";

export async function attachOrganismToAllDegreesHelper(
organism: Organism | null,
) {
const degrees = await prismaClient.degree.findMany();
for (const degree of degrees) {
await prismaClient.organismOnDegree.create({
data: {
degreeId: degree?.id || "",
organismId: organism?.id || "",
},
});
}
}
28 changes: 14 additions & 14 deletions packages/reva-api/test/helpers/entities/create-account-helper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { faker } from "@faker-js/faker";
import { Account } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";

export const createAccountHelper = async (accountArgs?: Partial<Account>) =>
prismaClient.account.create({
data: {
email: faker.internet.email(),
firstname: faker.person.firstName(),
lastname: faker.person.lastName(),
keycloakId: faker.string.uuid(),
...accountArgs,
},
});
import { faker } from "@faker-js/faker";
import { Account } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";

export const createAccountHelper = async (accountArgs?: Partial<Account>) =>
prismaClient.account.create({
data: {
email: faker.internet.email(),
firstname: faker.person.firstName(),
lastname: faker.person.lastName(),
keycloakId: faker.string.uuid(),
...accountArgs,
},
});
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { CandidacyDropOut } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";
import { createCandidacyHelper } from "./create-candidacy-helper";
import { createDropOutReasonHelper } from "./create-drop-out-reason-helper";

export const createCandidacyDropOutHelper = async (
args?: Partial<CandidacyDropOut>,
) => {
//either take the candidacy whose id is passed in args or create a new one
const candidacy = args?.candidacyId
? await prismaClient.candidacy.findUnique({
where: { id: args.candidacyId },
})
: await createCandidacyHelper();

if (!candidacy) {
throw new Error("candidacy not found");
}
const dropOutReason = await createDropOutReasonHelper();

return prismaClient.candidacyDropOut.create({
data: {
status: candidacy?.status,
candidacyId: candidacy.id,
dropOutReasonId: dropOutReason.id,
...args,
},
include: {
candidacy: true,
dropOutReason: true,
},
});
};
import { CandidacyDropOut } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";
import { createCandidacyHelper } from "./create-candidacy-helper";
import { createDropOutReasonHelper } from "./create-drop-out-reason-helper";

export const createCandidacyDropOutHelper = async (
args?: Partial<CandidacyDropOut>,
) => {
//either take the candidacy whose id is passed in args or create a new one
const candidacy = args?.candidacyId
? await prismaClient.candidacy.findUnique({
where: { id: args.candidacyId },
})
: await createCandidacyHelper();

if (!candidacy) {
throw new Error("candidacy not found");
}
const dropOutReason = await createDropOutReasonHelper();

return prismaClient.candidacyDropOut.create({
data: {
status: candidacy?.status,
candidacyId: candidacy.id,
dropOutReasonId: dropOutReason.id,
...args,
},
include: {
candidacy: true,
dropOutReason: true,
},
});
};
70 changes: 35 additions & 35 deletions packages/reva-api/test/helpers/entities/create-candidate-helper.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { faker } from "@faker-js/faker";
import { Candidate, Gender } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";

export const createCandidateHelper = async (
candidateArgs?: Partial<Candidate>,
): Promise<Candidate> => {
const parisDepartment = await prismaClient.department.findFirst({
where: { code: "75" },
});

return prismaClient.candidate.create({
data: {
firstname: faker.person.firstName(),
lastname: faker.person.lastName(),
email: faker.internet.email(),
gender: Gender.man,
keycloakId: faker.string.uuid(),
firstname2: faker.person.middleName(),
firstname3: faker.person.middleName(),
phone: faker.phone.number(),
birthdate: faker.date.past(),
birthCity: faker.location.city(),
nationality: faker.lorem.word(),
highestDegreeLabel: faker.lorem.word(),
street: faker.location.streetAddress(),
city: faker.location.city(),
zip: faker.string.numeric(5),
addressComplement: faker.lorem.word(),
givenName: faker.person.fullName(),
departmentId: parisDepartment?.id ?? "",
...candidateArgs,
},
});
};
import { faker } from "@faker-js/faker";
import { Candidate, Gender } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";

export const createCandidateHelper = async (
candidateArgs?: Partial<Candidate>,
): Promise<Candidate> => {
const parisDepartment = await prismaClient.department.findFirst({
where: { code: "75" },
});

return prismaClient.candidate.create({
data: {
firstname: faker.person.firstName(),
lastname: faker.person.lastName(),
email: faker.internet.email(),
gender: Gender.man,
keycloakId: faker.string.uuid(),
firstname2: faker.person.middleName(),
firstname3: faker.person.middleName(),
phone: faker.phone.number(),
birthdate: faker.date.past(),
birthCity: faker.location.city(),
nationality: faker.lorem.word(),
highestDegreeLabel: faker.lorem.word(),
street: faker.location.streetAddress(),
city: faker.location.city(),
zip: faker.string.numeric(5),
addressComplement: faker.lorem.word(),
givenName: faker.person.fullName(),
departmentId: parisDepartment?.id ?? "",
...candidateArgs,
},
});
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { faker } from "@faker-js/faker/.";
import { CertificationAuthorityStructure } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";

export const createCertificationAuthorityStructureHelper = async (
args?: Partial<CertificationAuthorityStructure>,
) =>
prismaClient.certificationAuthorityStructure.create({
data: {
label: faker.lorem.sentence(),
...args,
},
});
import { faker } from "@faker-js/faker/.";
import { CertificationAuthorityStructure } from "@prisma/client";
import { prismaClient } from "../../../prisma/client";

export const createCertificationAuthorityStructureHelper = async (
args?: Partial<CertificationAuthorityStructure>,
) =>
prismaClient.certificationAuthorityStructure.create({
data: {
label: faker.lorem.sentence(),
...args,
},
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { faker } from "@faker-js/faker/.";
import { prismaClient } from "../../../prisma/client";
import { ConventionCollective } from "@prisma/client";

export const createCCNHelper = async (
ccnArgs?: Partial<ConventionCollective>,
) =>
prismaClient.conventionCollective.create({
data: {
code: faker.string.numeric(5),
label: faker.company.name(),
...ccnArgs,
},
});
import { faker } from "@faker-js/faker/.";
import { prismaClient } from "../../../prisma/client";
import { ConventionCollective } from "@prisma/client";

export const createCCNHelper = async (
ccnArgs?: Partial<ConventionCollective>,
) =>
prismaClient.conventionCollective.create({
data: {
code: faker.string.numeric(5),
label: faker.company.name(),
...ccnArgs,
},
});
Loading

0 comments on commit be88be9

Please sign in to comment.