Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correction des tests formations catalogues #1432

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 84 additions & 8 deletions server/src/http/controllers/formationRegion.controller.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,76 @@
import { useMongo } from "@tests/utils/mongo.test.utils"
import { useServer } from "@tests/utils/server.test.utils"
import { describe, expect, it } from "vitest"
import { saveDbEntity } from "@tests/utils/user.test.utils"
import { IFormationCatalogue, zFormationCatalogueSchema } from "shared/models"
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"

// Skip from CI (ES is not populated correctly)
describe.skipIf(process.env.CI)("formationRegionV1", () => {
useMongo()
import { getDbCollection } from "@/common/utils/mongodbUtils"

useMongo()

describe("formationRegionV1", () => {
const httpClient = useServer()

beforeAll(() => {
vi.useFakeTimers()
vi.setSystemTime(new Date("2024-08-21"))

return () => {
vi.useRealTimers()
}
})

let formations: IFormationCatalogue[] = []

beforeEach(async () => {
formations = await Promise.all(
[
{
cle_ministere_educatif: "1",
code_postal: "75006",
num_departement: "75",
rome_codes: ["F1603", "F1606"],
tags: ["2024"],
},
{
cle_ministere_educatif: "2",
code_postal: "92110",
num_departement: "92",
rome_codes: ["F1603"],
tags: ["2024", "2023"],
},
{
cle_ministere_educatif: "3",
code_postal: "91000",
num_departement: "91",
rome_codes: ["F1603"],
tags: ["2024", "2023"],
},
{
cle_ministere_educatif: "4",
code_postal: "77000",
num_departement: "77",
rome_codes: ["I1308"],
tags: ["2024", "2023"],
},
{
cle_ministere_educatif: "5",
code_postal: "44980",
num_departement: "44",
rome_codes: ["N4101"],
tags: ["2024", "2023"],
},
{
cle_ministere_educatif: "6",
code_postal: "44983",
num_departement: "44",
rome_codes: ["F1603"],
tags: ["2024", "2023"],
},
].map((data) => saveDbEntity(zFormationCatalogueSchema, (item) => getDbCollection("formationcatalogues").insertOne(item), data))
)
})

it("Vérifie que la route répond", async () => {
const res = await httpClient().inject({ method: "GET", path: "/api/V1/formationsParRegion" })

Expand All @@ -15,15 +79,27 @@ describe.skipIf(process.env.CI)("formationRegionV1", () => {

it("Vérifie que la recherche avec Rome et region répond avec des résultats", async () => {
const res = await httpClient().inject({ method: "GET", path: "/api/V1/formationsParRegion?romes=F1603,I1308&region=11&caller=a" })
expect(res.statusCode).toBe(200)
expect(JSON.parse(res.body).results).not.toHaveLength(0)
expect.soft(res.statusCode).toBe(200)
expect(JSON.parse(res.body)).toEqual({
results: expect.arrayContaining([
expect.objectContaining({ cleMinistereEducatif: formations[0].cle_ministere_educatif }),
expect.objectContaining({ cleMinistereEducatif: formations[1].cle_ministere_educatif }),
expect.objectContaining({ cleMinistereEducatif: formations[2].cle_ministere_educatif }),
expect.objectContaining({ cleMinistereEducatif: formations[3].cle_ministere_educatif }),
]),
})
})

it("Vérifie que la recherche avec département répond avec des résultats", async () => {
const res = await httpClient().inject({ method: "GET", path: "/api/V1/formationsParRegion?departement=44&caller=a" })

expect(res.statusCode).toBe(200)
expect(JSON.parse(res.body).results).not.toHaveLength(0)
expect.soft(res.statusCode).toBe(200)
expect(JSON.parse(res.body)).toEqual({
results: expect.arrayContaining([
expect.objectContaining({ cleMinistereEducatif: formations[4].cle_ministere_educatif }),
expect.objectContaining({ cleMinistereEducatif: formations[5].cle_ministere_educatif }),
]),
})
})

it("Vérifie que les requêtes avec region et departement sont refusées", async () => {
Expand Down
17 changes: 9 additions & 8 deletions server/src/services/formation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ const transformFormations = (rawFormations: IFormationCatalogue[], isMinimalData
* Adaptation au modèle LBAC et conservation des seules infos utilisées des formations
*/
const transformFormation = (rawFormation: IFormationCatalogue): ILbaItemFormation => {
const geoSource = rawFormation.lieu_formation_geo_coordonnees
const [latOpt, longOpt] = (geoSource?.split(",") ?? []).map((str) => parseFloat(str))
const latOpt = rawFormation.lieu_formation_geopoint?.coordinates[0] ?? null
const longOpt = rawFormation.lieu_formation_geopoint?.coordinates[1] ?? null
moroine marked this conversation as resolved.
Show resolved Hide resolved
const sessions = setSessions(rawFormation)
const duration = getDurationFromSessions(sessions)

Expand Down Expand Up @@ -417,8 +417,9 @@ const transformFormation = (rawFormation: IFormationCatalogue): ILbaItemFormatio
* Adaptation au modèle LBAC et conservation des seules infos utilisées des formations
*/
const transformFormationV2 = (rawFormation: IFormationCatalogue): ILbaItemFormation2 => {
const geoSource = rawFormation.lieu_formation_geo_coordonnees
const [latOpt, longOpt] = (geoSource?.split(",") ?? []).map((str) => parseFloat(str))
const latOpt = rawFormation.lieu_formation_geopoint?.coordinates[0] ?? null
const longOpt = rawFormation.lieu_formation_geopoint?.coordinates[1] ?? null

const sessions = setSessions(rawFormation)
const duration = getDurationFromSessions(sessions)

Expand Down Expand Up @@ -492,8 +493,8 @@ const transformFormationV2 = (rawFormation: IFormationCatalogue): ILbaItemFormat
}

const transformFormationWithMinimalDataV2 = (rawFormation: IFormationCatalogue): ILbaItemFormation2 => {
const geoSource = rawFormation.lieu_formation_geo_coordonnees
const [latOpt, longOpt] = (geoSource?.split(",") ?? []).map((str) => parseFloat(str))
const latOpt = rawFormation.lieu_formation_geopoint?.coordinates[0] ?? null
const longOpt = rawFormation.lieu_formation_geopoint?.coordinates[1] ?? null

const resultFormation: ILbaItemFormation2 = {
type: LBA_ITEM_TYPE.FORMATION,
Expand Down Expand Up @@ -525,8 +526,8 @@ const transformFormationWithMinimalDataV2 = (rawFormation: IFormationCatalogue):
* Adaptation au modèle LBAC et conservation des seules infos utilisées des formations
*/
const transformFormationWithMinimalData = (rawFormation: IFormationCatalogue): ILbaItemFormation => {
const geoSource = rawFormation.lieu_formation_geo_coordonnees
const [latOpt, longOpt] = (geoSource?.split(",") ?? []).map((str) => parseFloat(str))
const latOpt = rawFormation.lieu_formation_geopoint?.coordinates[0] ?? null
const longOpt = rawFormation.lieu_formation_geopoint?.coordinates[1] ?? null

const resultFormation: ILbaItemFormation = {
ideaType: LBA_ITEM_TYPE_OLD.FORMATION,
Expand Down
22 changes: 21 additions & 1 deletion server/tests/utils/user.test.utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { ObjectId } from "mongodb"
import { OPCOS_LABEL, RECRUITER_STATUS, VALIDATION_UTILISATEUR } from "shared/constants/recruteur"
import { extensions } from "shared/helpers/zodHelpers/zodPrimitives"
import { IApplication, ICredential, IEmailBlacklist, IJob, ILbaCompany, IRecruiter, JOB_STATUS, ZApplication, ZCredential, ZEmailBlacklist, ZLbaCompany } from "shared/models"
import {
IApplication,
ICredential,
IEmailBlacklist,
IJob,
ILbaCompany,
IRecruiter,
JOB_STATUS,
ZApplication,
ZCredential,
ZEmailBlacklist,
ZLbaCompany,
ZPointGeometry,
} from "shared/models"
import { ICFA, zCFA } from "shared/models/cfa.model"
import { zObjectId } from "shared/models/common"
import { EntrepriseStatus, IEntreprise, IEntrepriseStatusEvent, ZEntreprise } from "shared/models/entreprise.model"
Expand Down Expand Up @@ -68,6 +81,13 @@ function getFixture() {
"77147689105960",
]),
}),
Generator({
schema: ZPointGeometry,
output: ({ transform }) => ({
type: "Point",
coordinates: [transform.utils.random.float({ min: -180, max: 180 }), transform.utils.random.float({ min: -90, max: 90 })],
}),
}),
])
}

Expand Down
7 changes: 4 additions & 3 deletions shared/models/formation.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { extensions } from "../helpers/zodHelpers/zodPrimitives"
import { z } from "../helpers/zodWithOpenApi"

import { ZPointGeometry } from "./address.model"
Expand All @@ -10,7 +11,7 @@ const geoCoordSchema = z.string()
const etablissementFormateurSchema = z
.object({
etablissement_formateur_id: z.string().nullish(),
etablissement_formateur_siret: z.string().nullish(),
etablissement_formateur_siret: extensions.siret.nullish(),
moroine marked this conversation as resolved.
Show resolved Hide resolved
etablissement_formateur_enseigne: z.string().nullish(),
etablissement_formateur_uai: z.string().nullish(),
etablissement_formateur_type: z.string().nullish(),
Expand Down Expand Up @@ -43,7 +44,7 @@ const etablissementFormateurSchema = z
const etablissementGestionnaireSchema = z
.object({
etablissement_gestionnaire_id: z.string().nullish(),
etablissement_gestionnaire_siret: z.string().nullish(),
etablissement_gestionnaire_siret: extensions.siret.nullish(),
moroine marked this conversation as resolved.
Show resolved Hide resolved
etablissement_gestionnaire_enseigne: z.string().nullish(),
etablissement_gestionnaire_uai: z.string().nullish(),
etablissement_gestionnaire_type: z.string().nullish(),
Expand Down Expand Up @@ -161,7 +162,7 @@ export const zFormationCatalogueSchema = z
lieu_formation_geopoint: ZPointGeometry.nullish(),
lieu_formation_adresse: z.string().nullish(),
lieu_formation_adresse_computed: z.string().nullish(),
lieu_formation_siret: z.string().nullish(),
lieu_formation_siret: extensions.siret.nullish(),
moroine marked this conversation as resolved.
Show resolved Hide resolved
id_rco_formation: z.string().nullish(),
id_formation: z.string().nullish(),
id_action: z.string().nullish(),
Expand Down
Loading