diff --git a/server/seed/seed_data.dump b/server/seed/seed_data.dump index f1bdb5a9e..2e9f9ddf9 100644 Binary files a/server/seed/seed_data.dump and b/server/seed/seed_data.dump differ diff --git a/server/seed/seed_schema.dump b/server/seed/seed_schema.dump index 3065c5d55..0cf5d9e15 100644 Binary files a/server/seed/seed_schema.dump and b/server/seed/seed_schema.dump differ diff --git a/server/src/modules/data/usecases/getFormationIndicateurs/__tests__/getDomaineDeFormationIndicateurs.spec.ts b/server/src/modules/data/usecases/getFormationIndicateurs/__tests__/getDomaineDeFormationIndicateurs.spec.ts index acbbd0ed2..27187e4c8 100644 --- a/server/src/modules/data/usecases/getFormationIndicateurs/__tests__/getDomaineDeFormationIndicateurs.spec.ts +++ b/server/src/modules/data/usecases/getFormationIndicateurs/__tests__/getDomaineDeFormationIndicateurs.spec.ts @@ -214,24 +214,27 @@ describe("GET /api/formation/:cfd/indicators", () => { expect(result.tauxIJ.tauxPoursuite).toEqual( expect.arrayContaining([ { apprentissage: 0.2967, libelle: "2019+20", scolaire: 0.509 }, - { apprentissage: 0.4036, libelle: "2020+21", scolaire: 0.5379 }, + { apprentissage: 0.4036, libelle: "2020+21", scolaire: 0.5382 }, { apprentissage: 0.3954, libelle: "2021+22", scolaire: 0.5504 }, + { apprentissage: 0.3791, libelle: "2022+23", scolaire: 0.5581 }, ]) ); expect(result.tauxIJ.tauxInsertion).toEqual( expect.arrayContaining([ { apprentissage: 0.5937, libelle: "2019+20", scolaire: 0.3496 }, - { apprentissage: 0.6249, libelle: "2020+21", scolaire: 0.3531 }, + { apprentissage: 0.6272, libelle: "2020+21", scolaire: 0.3546 }, { apprentissage: 0.6137, libelle: "2021+22", scolaire: 0.4291 }, + { apprentissage: 0.6037, libelle: "2022+23", scolaire: 0.4156 }, ]) ); expect(result.tauxIJ.tauxDevenirFavorable).toEqual( expect.arrayContaining([ { apprentissage: 0.7143, libelle: "2019+20", scolaire: 0.6807 }, - { apprentissage: 0.7755, libelle: "2020+21", scolaire: 0.7011 }, + { apprentissage: 0.7769, libelle: "2020+21", scolaire: 0.7019 }, { apprentissage: 0.7664, libelle: "2021+22", scolaire: 0.7433 }, + { apprentissage: 0.7539, libelle: "2022+23", scolaire: 0.7417 }, ]) ); }); @@ -255,16 +258,18 @@ describe("GET /api/formation/:cfd/indicators", () => { expect(result.tauxIJ.tauxInsertion).toEqual( expect.arrayContaining([ { apprentissage: 0.6362, libelle: "2019+20", scolaire: 0.4757 }, - { apprentissage: 0.7, libelle: "2020+21", scolaire: 0.468 }, + { apprentissage: 0.7, libelle: "2020+21", scolaire: 0.4691 }, { apprentissage: 0.6719, libelle: "2021+22", scolaire: 0.4935 }, + { apprentissage: 0.6429, libelle: "2022+23", scolaire: 0.4911 }, ]) ); expect(result.tauxIJ.tauxDevenirFavorable).toEqual( expect.arrayContaining([ { apprentissage: 0.7278, libelle: "2019+20", scolaire: 0.7428 }, - { apprentissage: 0.8125, libelle: "2020+21", scolaire: 0.7594 }, + { apprentissage: 0.8125, libelle: "2020+21", scolaire: 0.7599 }, { apprentissage: 0.8047, libelle: "2021+22", scolaire: 0.7857 }, + { apprentissage: 0.792, libelle: "2022+23", scolaire: 0.7876 }, ]) ); }); @@ -283,22 +288,25 @@ describe("GET /api/formation/:cfd/indicators", () => { { apprentissage: 0.2518, libelle: "2019+20", scolaire: 0.5095 }, { apprentissage: 0.375, libelle: "2020+21", scolaire: 0.5478 }, { apprentissage: 0.4047, libelle: "2021+22", scolaire: 0.5769 }, + { apprentissage: 0.4176, libelle: "2022+23", scolaire: 0.5826 }, ]) ); expect(result.tauxIJ.tauxInsertion).toEqual( expect.arrayContaining([ { apprentissage: 0.6362, libelle: "2019+20", scolaire: 0.4757 }, - { apprentissage: 0.7, libelle: "2020+21", scolaire: 0.468 }, + { apprentissage: 0.7, libelle: "2020+21", scolaire: 0.4691 }, { apprentissage: 0.6719, libelle: "2021+22", scolaire: 0.4935 }, + { apprentissage: 0.6429, libelle: "2022+23", scolaire: 0.4911 }, ]) ); expect(result.tauxIJ.tauxDevenirFavorable).toEqual( expect.arrayContaining([ { apprentissage: 0.7278, libelle: "2019+20", scolaire: 0.7428 }, - { apprentissage: 0.8125, libelle: "2020+21", scolaire: 0.7594 }, + { apprentissage: 0.8125, libelle: "2020+21", scolaire: 0.7599 }, { apprentissage: 0.8047, libelle: "2021+22", scolaire: 0.7857 }, + { apprentissage: 0.792, libelle: "2022+23", scolaire: 0.7876 }, ]) ); }); @@ -324,16 +332,18 @@ describe("GET /api/formation/:cfd/indicators", () => { expect(result.tauxIJ.tauxInsertion).toEqual( expect.arrayContaining([ { apprentissage: 0.6362, libelle: "2019+20", scolaire: 0.4757 }, - { apprentissage: 0.7, libelle: "2020+21", scolaire: 0.468 }, + { apprentissage: 0.7, libelle: "2020+21", scolaire: 0.4691 }, { apprentissage: 0.6719, libelle: "2021+22", scolaire: 0.4935 }, + { apprentissage: 0.6429, libelle: "2022+23", scolaire: 0.4911 }, ]) ); expect(result.tauxIJ.tauxDevenirFavorable).toEqual( expect.arrayContaining([ { apprentissage: 0.7278, libelle: "2019+20", scolaire: 0.7428 }, - { apprentissage: 0.8125, libelle: "2020+21", scolaire: 0.7594 }, + { apprentissage: 0.8125, libelle: "2020+21", scolaire: 0.7599 }, { apprentissage: 0.8047, libelle: "2021+22", scolaire: 0.7857 }, + { apprentissage: 0.792, libelle: "2022+23", scolaire: 0.7876 }, ]) ); }); diff --git a/server/src/modules/data/usecases/getRegion/__tests__/getRegion.spec.ts b/server/src/modules/data/usecases/getRegion/__tests__/getRegion.spec.ts index bbc7e28f3..3130fefc1 100644 --- a/server/src/modules/data/usecases/getRegion/__tests__/getRegion.spec.ts +++ b/server/src/modules/data/usecases/getRegion/__tests__/getRegion.spec.ts @@ -1,13 +1,21 @@ import { usePg } from "@tests/utils/pg.test.utils"; -import { beforeAll, describe, expect, it } from "vitest"; +import type { IResError } from "shared/models/errors"; +import type { ROUTES } from "shared/routes/routes"; +import { beforeAll, beforeEach, describe, expect, it } from "vitest"; +import type { z } from "zod"; import type { Server } from "@/server/server.js"; import createServer from "@/server/server.js"; +type Response = z.infer< + (typeof ROUTES)["[GET]/region/:codeRegion"]["schema"]["response"]["200"] +>; + usePg(); describe("[GET]/region/:codeRegion", () => { let app: Server; + let fixture: ReturnType; beforeAll(async () => { app = await createServer(); @@ -16,22 +24,107 @@ describe("[GET]/region/:codeRegion", () => { return async () => app.close(); }, 15_000); + beforeEach(() => { + fixture = fixtureBuilder(app); + }); + it("doit retrouver les données de la région Auvergne-Rhône-Alpes (84) pour un BTS (320)", async () => { - const response = await app.inject({ - method: "GET", - url: "/api/region/84?codeNiveauDiplome[]=320", - }); - - expect(response.statusCode).toBe(200); - expect(response.json()).toEqual({ - libelleRegion: "Auvergne-Rhône-Alpes", - effectifEntree: 10165, - effectifTotal: 18403, - nbFormations: 96, - tauxRemplissage: 0.79200970621371, - tauxPoursuite: 0.476512025342837, - tauxInsertion: 0.640178358149534, - tauxDevenirFavorable: 0.811637697469885, - }); + fixture.given.region("84"); + fixture.given.codeNiveauDiplome("320"); + + await fixture.when.getRegion(); + + fixture.then.verifierLabelRegion("Auvergne-Rhône-Alpes"); + fixture.then.verifierEffectifEntree(15962); + fixture.then.verifierEffectifTotal(30068); + fixture.then.verifierNbFormations(123); + fixture.then.verifierTauxRemplissage(0.8822); + fixture.then.verifierTauxPoursuite(0.4975); + fixture.then.verifierTauxInsertion(0.6417); + fixture.then.verifierTauxDevenirFavorable(0.82); + }); + + it("doit vérifier que des valeurs n'existes par pour des diplomes dans des régions", async () => { + fixture.given.region("27"); + fixture.given.codeNiveauDiplome("561"); + + await fixture.when.getRegion(); + + fixture.then.verifierLabelRegion("Bourgogne-Franche-Comté"); + fixture.then.verifierNbFormations(4); + fixture.then.verifierEffectifTotal(46); + fixture.then.verifierEffectifEntree(46); + fixture.then.verifierTauxRemplissage(undefined); + fixture.then.verifierTauxPoursuite(undefined); + fixture.then.verifierTauxInsertion(undefined); + fixture.then.verifierTauxDevenirFavorable(undefined); }); }); + + + +const fixtureBuilder = (app: Server) => { + let codeRegion: string; + let codeNiveauDiplome: string; + let responseCode: number; + let responseBody: Response | IResError; + + const rounded = (value?: number, precision: number = 4) => { + if (!value) return undefined; + return Math.round(value * 10 ** precision) / 10 ** precision; + }; + + return { + given: { + region: (code: string) => { + codeRegion = code; + }, + codeNiveauDiplome: (code: string) => { + codeNiveauDiplome = code; + }, + }, + when: { + getRegion: async () => { + const response = await app.inject({ + method: "GET", + url: `/api/region/${codeRegion}?codeNiveauDiplome[]=${codeNiveauDiplome}`, + }); + responseCode = response.statusCode; + responseBody = response.json(); + }, + }, + then: { + verifierReponseSucces: () => { + expect(responseCode).toBe(200); + }, + verifierReponseErreur: () => { + expect(responseCode).toBe(400); + }, + verifierLabelRegion: (label: string) => { + expect((responseBody as Response).libelleRegion).toBe(label); + }, + verifierEffectifEntree: (effectif: number) => { + expect((responseBody as Response).effectifEntree).toBe(effectif); + }, + verifierEffectifTotal: (effectif: number) => { + expect((responseBody as Response).effectifTotal).toBe(effectif); + }, + verifierNbFormations: (nb: number) => { + expect((responseBody as Response).nbFormations).toBe(nb); + }, + verifierTauxRemplissage: (taux?: number) => { + expect(rounded((responseBody as Response).tauxRemplissage)).toBe(taux); + }, + verifierTauxPoursuite: (taux?: number) => { + expect(rounded((responseBody as Response).tauxPoursuite)).toBe(taux); + }, + verifierTauxInsertion: (taux?: number) => { + expect(rounded((responseBody as Response).tauxInsertion)).toBe(taux); + }, + verifierTauxDevenirFavorable: (taux?: number) => { + expect(rounded((responseBody as Response).tauxDevenirFavorable)).toBe(taux); + }, + }, + }; +}; + diff --git a/server/tests/utils/pg.test.utils.ts b/server/tests/utils/pg.test.utils.ts index 3503b9f78..ac27b394b 100644 --- a/server/tests/utils/pg.test.utils.ts +++ b/server/tests/utils/pg.test.utils.ts @@ -29,7 +29,7 @@ export const startAndConnectPg = async () => { await refreshViews(); console.log("Migrating to latest", testDb); - await migrateToLatest(true); + await migrateToLatest(true, false); console.log("Refreshing views", testDb); await refreshViews();