diff --git a/server/src/jobs/bcn/importBCNFamilleMetier.js b/server/src/jobs/bcn/importBCNFamilleMetier.js index c8a13014..1dcb16cf 100644 --- a/server/src/jobs/bcn/importBCNFamilleMetier.js +++ b/server/src/jobs/bcn/importBCNFamilleMetier.js @@ -1,4 +1,4 @@ -import { flattenArray, oleoduc, transformData, writeData } from "oleoduc"; +import { filterData, flattenArray, oleoduc, transformData, writeData } from "oleoduc"; import { omitNil } from "#src/common/utils/objectUtils.js"; import { getLoggerWithContext } from "#src/common/logger.js"; import BCNRepository from "#src/common/repositories/bcn.js"; @@ -22,12 +22,20 @@ export async function importBCNFamilleMetier(options = {}) { const bcnMef = await BCNMefRepository.first({ mef: data["MEF"], }); + if (!bcnMef) { + return null; + } + const bcn = await BCNRepository.first({ code_certification: bcnMef.mef_stat_11, }); + if (!bcn) { + return null; + } return { data, bcn }; }), + filterData((d) => d), transformData(async (data) => { const formationWithContinuum = await BCNRepository.cfdsParentAndChildren(data.bcn.code_certification); return formationWithContinuum.map((f) => { diff --git a/server/src/jobs/stats/importAnneesNonTerminales.js b/server/src/jobs/stats/importAnneesNonTerminales.js index 5cf37b56..d45b1810 100644 --- a/server/src/jobs/stats/importAnneesNonTerminales.js +++ b/server/src/jobs/stats/importAnneesNonTerminales.js @@ -1,5 +1,6 @@ import { Readable } from "stream"; import { flattenArray, oleoduc, transformData, writeData } from "oleoduc"; +import streamToArray from "stream-to-array"; import { upsert } from "#src/common/db/mongodb.js"; import { getLoggerWithContext } from "#src/common/logger.js"; import { omitNil } from "#src/common/utils/objectUtils.js"; @@ -10,6 +11,7 @@ import { certificationsStats, regionalesStats, formationsStats } from "#src/comm import CertificationStatsRepository from "#src/common/repositories/certificationStats.js"; import RegionaleStatsRepository from "#src/common/repositories/regionaleStats.js"; import FormationStatsRepository from "#src/common/repositories/formationStats.js"; +import BCNMefRepository from "#src/common/repositories/bcnMef.js"; const logger = getLoggerWithContext("import"); @@ -37,6 +39,28 @@ const statCollections = { }, }; +async function getCertificationForYear(year, { code_certification, code_formation_diplome }) { + const previousMef = code_certification.substr(0, 3) + year + code_certification.substr(3 + 1); + const certification = await getCertificationInfo(previousMef); + + if (certification) { + return certification; + } + + const certificationsFromMef = await streamToArray( + await BCNMefRepository.find({ + formation_diplome: code_formation_diplome, + annee_dispositif: `${year}`, + }) + ); + + if (certificationsFromMef.length === 1) { + return await getCertificationInfo(certificationsFromMef[0].mef_stat_11); + } + + return null; +} + export async function importAnneesNonTerminales(options = {}) { const jobStats = { created: 0, updated: 0, failed: 0 }; const statsType = options.stats || ["certifications", "formations", "regionales"]; @@ -61,19 +85,25 @@ export async function importAnneesNonTerminales(options = {}) { millesime: millesime, "donnee_source.type": { $exists: true }, }), - transformData((stats) => { + transformData(async (stats) => { const previousYearStats = []; for (let year = stats.code_certification[3] - 1; year > 0; year--) { - const previousMef = stats.code_certification.substr(0, 3) + year + stats.code_certification.substr(3 + 1); - previousYearStats.push({ - stats, - code_certification: previousMef, - }); + const previousCertification = await getCertificationForYear( + year, + pick(stats, ["code_formation_diplome", "code_certification"]) + ); + if (previousCertification) { + previousYearStats.push({ + stats, + certification: previousCertification, + code_certification: previousCertification.code_certification, + }); + } } return previousYearStats; }), flattenArray(), - writeData(async ({ code_certification, stats }) => { + writeData(async ({ code_certification, certification, stats }) => { const query = { millesime: stats.millesime, code_certification: code_certification, @@ -84,7 +114,6 @@ export async function importAnneesNonTerminales(options = {}) { }; try { - const certification = await getCertificationInfo(code_certification); if (!certification) { logger.error(`Certification ${code_certification} pour ${stats.code_formation_diplome} inconnue.`); jobStats.failed++; diff --git a/server/tests/http/certificationsRoutes-test.js b/server/tests/http/certificationsRoutes-test.js index eff88d85..53b22fa0 100644 --- a/server/tests/http/certificationsRoutes-test.js +++ b/server/tests/http/certificationsRoutes-test.js @@ -588,6 +588,42 @@ describe("certificationsRoutes", () => { }); }); + it("Vérifie qu'on peut obtenir une année non terminale", async () => { + const { httpClient } = await startServer(); + await insertCertificationsStats( + { + code_certification: "12345678910", + code_formation_diplome: "12345678", + filiere: "pro", + certificationsTerminales: [{ code_certification: "32220000000" }], + }, + false + ); + + const response = await httpClient.get(`/api/inserjeunes/certifications/12345678910`); + + assert.strictEqual(response.status, 200); + assert.deepStrictEqual(response.data, { + millesime: "2020", + code_certification: "12345678910", + code_certification_type: "mef11", + code_formation_diplome: "12345678", + libelle: "LIBELLE", + filiere: "pro", + diplome: { code: "4", libelle: "BAC" }, + certificationsTerminales: [{ code_certification: "32220000000" }], + donnee_source: { + code_certification: "12345678910", + type: "self", + }, + formation_fermee: false, + _meta: { + titre: "Certification 12345678910", + details: "Données InserJeunes pour la certification 12345678910 (BAC filière pro) pour le millésime 2020", + }, + }); + }); + it("Ne retourne pas de stats par défaut si il n'y a pas de données pour le millésime le plus récent", async () => { const { httpClient } = await startServer(); await insertCertificationsStats({ diff --git a/server/tests/http/formationsRoutes-test.js b/server/tests/http/formationsRoutes-test.js index 01f1068d..163508d4 100644 --- a/server/tests/http/formationsRoutes-test.js +++ b/server/tests/http/formationsRoutes-test.js @@ -955,6 +955,54 @@ describe("formationsRoutes", () => { }); }); + it("Vérifie qu'on peut obtenir une année non terminale", async () => { + const { httpClient } = await startServer(); + await insertFormationsStats( + { + uai: "0751234J", + code_certification: "12345678910", + code_formation_diplome: "12345678", + filiere: "pro", + certificationsTerminales: [{ code_certification: "32220000000" }], + }, + false + ); + + const response = await httpClient.get(`/api/inserjeunes/formations/0751234J-12345678910`); + + assert.strictEqual(response.status, 200); + assert.deepStrictEqual(response.data, { + millesime: "2018_2019", + code_certification: "12345678910", + code_certification_type: "mef11", + code_formation_diplome: "12345678", + libelle: "LIBELLE", + libelle_etablissement: "Lycée", + filiere: "pro", + diplome: { code: "4", libelle: "BAC" }, + certificationsTerminales: [{ code_certification: "32220000000" }], + donnee_source: { + code_certification: "12345678910", + type: "self", + }, + academie: { + code: "01", + nom: "Paris", + }, + region: { + code: "11", + nom: "Île-de-France", + }, + uai: "0751234J", + formation_fermee: false, + _meta: { + titre: "Certification 12345678910, établissement 0751234J", + details: + "Données InserJeunes pour la certification 12345678910 (BAC filière pro) dispensée par l'établissement 0751234J, pour le millésime 2018_2019", + }, + }); + }); + it("Ne retourne pas de stats par défaut si il n'y a pas de données pour le millésime le plus récent", async () => { const { httpClient } = await startServer(); await insertCFD({ code_certification: "12345678" }); diff --git a/server/tests/http/regionalesRoutes-test.js b/server/tests/http/regionalesRoutes-test.js index 61a91745..4170d3d2 100644 --- a/server/tests/http/regionalesRoutes-test.js +++ b/server/tests/http/regionalesRoutes-test.js @@ -748,6 +748,48 @@ describe("regionalesRoutes", () => { }); }); + it("Vérifie qu'on peut obtenir une année non terminale", async () => { + const { httpClient } = await startServer(); + await insertRegionalesStats( + { + region: { code: "11", nom: "Île-de-France" }, + code_certification: "12345678910", + code_formation_diplome: "12345678", + filiere: "pro", + certificationsTerminales: [{ code_certification: "32220000000" }], + }, + false + ); + + const response = await httpClient.get(`/api/inserjeunes/regionales/11/certifications/12345678910`); + + assert.strictEqual(response.status, 200); + assert.deepStrictEqual(response.data, { + millesime: "2018_2019", + code_certification: "12345678910", + code_certification_type: "mef11", + code_formation_diplome: "12345678", + libelle: "LIBELLE", + filiere: "pro", + diplome: { code: "4", libelle: "BAC" }, + certificationsTerminales: [{ code_certification: "32220000000" }], + donnee_source: { + code_certification: "12345678910", + type: "self", + }, + region: { + code: "11", + nom: "Île-de-France", + }, + formation_fermee: false, + _meta: { + titre: "Certification 12345678910", + details: + "Données InserJeunes pour la certification 12345678910 (BAC filière pro) pour le millésime 2018_2019 et la région Île-de-France", + }, + }); + }); + it("Ne retourne pas de stats par défaut si il n'y a pas de données pour le millésime le plus récent", async () => { const { httpClient } = await startServer(); await insertCFD({ code_certification: "12345678" }); diff --git a/server/tests/jobs/bcn/importBCNFamilleMetier-test.js b/server/tests/jobs/bcn/importBCNFamilleMetier-test.js new file mode 100644 index 00000000..8c9f2567 --- /dev/null +++ b/server/tests/jobs/bcn/importBCNFamilleMetier-test.js @@ -0,0 +1,112 @@ +import assert from "assert"; +import MockDate from "mockdate"; +import { omit } from "lodash-es"; +import { insertBCNMEF, insertMEF } from "#tests/utils/fakeData.js"; +import { importBCNFamilleMetier } from "#src/jobs/bcn/importBCNFamilleMetier.js"; +import BCNRepository from "#src/common/repositories/bcn.js"; + +describe("importBCNFamilleMetier", () => { + before(() => { + MockDate.set("2023-01-01"); + }); + + after(() => { + MockDate.reset(); + }); + + describe("Vérifie que l'on ajoute les familles de métiers", () => { + it("Pour une seconde commune", async () => { + await Promise.all([ + insertBCNMEF({ + mef_stat_11: "23810031211", + formation_diplome: "40031211", + mef: "2473121131", + }), + insertMEF({ + code_certification: "23810031211", + code_formation_diplome: "40031211", + libelle_long: "2NDPRO MET. RELATION CLIENT 2NDE COMMUNE", + }), + ]); + + const result = await importBCNFamilleMetier(); + + assert.deepEqual(result, { + failed: 0, + total: 1, + updated: 1, + }); + + const found = await BCNRepository.first({}); + assert.deepStrictEqual(omit(found, ["_id"]), { + type: "mef", + code_certification: "23810031211", + code_formation_diplome: "40031211", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + date_ouverture: new Date(), + diplome: { code: "4", libelle: "BAC" }, + libelle: "BAC PRO", + libelle_long: "2NDPRO MET. RELATION CLIENT 2NDE COMMUNE", + ancien_diplome: [], + nouveau_diplome: [], + familleMetier: { + code: "003", + isAnneeCommune: true, + libelle: "Relation client", + }, + _meta: { + created_on: new Date("2023-01-01T00:00:00.000Z"), + updated_on: new Date("2023-01-01T00:00:00.000Z"), + date_import: new Date("2023-01-01T00:00:00.000Z"), + }, + }); + }); + + it("Pour une année d'option", async () => { + await Promise.all([ + insertBCNMEF({ + mef_stat_11: "23830031212", + formation_diplome: "40031211", + mef: "2473121131", + }), + insertMEF({ + code_certification: "23830031212", + code_formation_diplome: "40031211", + libelle_long: "TERMINALE", + }), + ]); + + const result = await importBCNFamilleMetier(); + + assert.deepEqual(result, { + failed: 0, + total: 1, + updated: 1, + }); + + const found = await BCNRepository.first({}); + assert.deepStrictEqual(omit(found, ["_id"]), { + type: "mef", + code_certification: "23830031212", + code_formation_diplome: "40031211", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + date_ouverture: new Date(), + diplome: { code: "4", libelle: "BAC" }, + libelle: "BAC PRO", + libelle_long: "TERMINALE", + ancien_diplome: [], + nouveau_diplome: [], + familleMetier: { + code: "003", + isAnneeCommune: true, + libelle: "Relation client", + }, + _meta: { + created_on: new Date("2023-01-01T00:00:00.000Z"), + updated_on: new Date("2023-01-01T00:00:00.000Z"), + date_import: new Date("2023-01-01T00:00:00.000Z"), + }, + }); + }); + }); +}); diff --git a/server/tests/jobs/stats/importAnneesNonTerminales-test.js b/server/tests/jobs/stats/importAnneesNonTerminales-test.js new file mode 100644 index 00000000..fdaeeb55 --- /dev/null +++ b/server/tests/jobs/stats/importAnneesNonTerminales-test.js @@ -0,0 +1,338 @@ +import chai, { assert } from "chai"; +import chaiAsPromised from "chai-as-promised"; +import MockDate from "mockdate"; +import { omit } from "lodash-es"; +import { + insertBCNMEF, + insertMEF, + insertRegionalesStats, + insertCertificationsStats, + insertFormationsStats, +} from "#tests/utils/fakeData.js"; +import CertificationStatsRepository from "#src/common/repositories/certificationStats.js"; +import RegionaleStatsRepository from "#src/common/repositories/regionaleStats.js"; +import FormationStatsRepository from "#src/common/repositories/formationStats.js"; +import { importAnneesNonTerminales } from "#src/jobs/stats/importAnneesNonTerminales.js"; + +chai.use(chaiAsPromised); + +describe("importAnneesNonTerminales", () => { + before(() => { + MockDate.set("2023-01-01"); + }); + + after(() => { + MockDate.reset(); + }); + + const DEFAULT_STATS = { + nb_annee_term: 50, + nb_en_emploi_12_mois: 25, + nb_en_emploi_18_mois: 25, + nb_en_emploi_24_mois: 25, + nb_en_emploi_6_mois: 45, + nb_poursuite_etudes: 5, + nb_sortant: 45, + taux_autres_12_mois: 40, + taux_autres_18_mois: 40, + taux_autres_24_mois: 40, + taux_autres_6_mois: 0, + taux_en_emploi_12_mois: 50, + taux_en_emploi_18_mois: 50, + taux_en_emploi_24_mois: 50, + taux_en_emploi_6_mois: 90, + taux_en_formation: 10, + taux_rupture_contrats: 10, + }; + + describe("Au niveau certifications", () => { + it("Vérifie que l'on ajoute les années non terminales pour une certification", async () => { + await Promise.all([ + await insertMEF({ + code_certification: "32210000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + await insertMEF({ + code_certification: "32220000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + await insertMEF({ + code_certification: "32230000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + insertCertificationsStats({ + code_certification: "32230000000", + code_formation_diplome: "32000000", + filiere: "pro", + ...DEFAULT_STATS, + }), + ]); + + const result = await importAnneesNonTerminales({ stats: "certifications" }); + assert.deepEqual(result, { + created: 2, + failed: 0, + updated: 0, + }); + + const certificationPremiere = await CertificationStatsRepository.first({ code_certification: "32220000000" }); + assert.deepEqual(omit(certificationPremiere, "_id"), { + code_certification: "32220000000", + millesime: "2020", + code_certification_type: "mef11", + code_formation_diplome: "32000000", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + filiere: "pro", + libelle: "BAC PRO BATIMENT", + certificationsTerminales: [{ code_certification: "32230000000" }], + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + + const certificationSeconde = await CertificationStatsRepository.first({ code_certification: "32210000000" }); + assert.deepEqual(omit(certificationSeconde, "_id"), { + code_certification: "32210000000", + millesime: "2020", + code_certification_type: "mef11", + code_formation_diplome: "32000000", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + filiere: "pro", + libelle: "BAC PRO BATIMENT", + certificationsTerminales: [{ code_certification: "32230000000" }], + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + }); + + it("Vérifie que l'on ajoute les années non terminales ayant un mef disctontinu pour une certification", async () => { + await Promise.all([ + await insertBCNMEF({ + mef_stat_11: "32219999999", + formation_diplome: "32000000", + annee_dispositif: "1", + }), + await insertMEF({ + code_certification: "32219999999", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + await insertMEF({ + code_certification: "32220000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + insertCertificationsStats({ + code_certification: "32220000000", + code_formation_diplome: "32000000", + filiere: "pro", + ...DEFAULT_STATS, + }), + ]); + + const result = await importAnneesNonTerminales({ stats: "certifications" }); + assert.deepEqual(result, { + created: 1, + failed: 0, + updated: 0, + }); + + const certificationSeconde = await CertificationStatsRepository.first({ code_certification: "32219999999" }); + assert.deepEqual(omit(certificationSeconde, "_id"), { + code_certification: "32219999999", + millesime: "2020", + code_certification_type: "mef11", + code_formation_diplome: "32000000", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + filiere: "pro", + libelle: "BAC PRO BATIMENT", + certificationsTerminales: [{ code_certification: "32220000000" }], + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + }); + }); + + describe("Au niveau régionales", () => { + it("Vérifie que l'on ajoute les années non terminales pour une certification", async () => { + await Promise.all([ + await insertMEF({ + code_certification: "32210000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + await insertMEF({ + code_certification: "32220000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + await insertMEF({ + code_certification: "32230000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + insertRegionalesStats({ + code_certification: "32230000000", + code_formation_diplome: "32000000", + filiere: "pro", + ...DEFAULT_STATS, + }), + ]); + + const result = await importAnneesNonTerminales({ stats: "regionales" }); + assert.deepEqual(result, { + created: 2, + failed: 0, + updated: 0, + }); + + const certificationPremiere = await RegionaleStatsRepository.first({ code_certification: "32220000000" }); + assert.deepEqual(omit(certificationPremiere, "_id"), { + code_certification: "32220000000", + millesime: "2018_2019", + code_certification_type: "mef11", + code_formation_diplome: "32000000", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + filiere: "pro", + libelle: "BAC PRO BATIMENT", + certificationsTerminales: [{ code_certification: "32230000000" }], + region: { + code: "11", + nom: "Île-de-France", + }, + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + + const certificationSeconde = await RegionaleStatsRepository.first({ code_certification: "32210000000" }); + assert.deepEqual(omit(certificationSeconde, "_id"), { + code_certification: "32210000000", + millesime: "2018_2019", + code_certification_type: "mef11", + code_formation_diplome: "32000000", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + filiere: "pro", + libelle: "BAC PRO BATIMENT", + certificationsTerminales: [{ code_certification: "32230000000" }], + region: { + code: "11", + nom: "Île-de-France", + }, + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + }); + }); + + describe("Au niveau formations", () => { + it("Vérifie que l'on ajoute les années non terminales pour une certification", async () => { + await Promise.all([ + await insertMEF({ + code_certification: "32210000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + await insertMEF({ + code_certification: "32220000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + await insertMEF({ + code_certification: "32230000000", + code_formation_diplome: "32000000", + diplome: { code: "4", libelle: "BAC" }, + }), + insertFormationsStats({ + uai: "0754247J", + code_certification: "32230000000", + code_formation_diplome: "32000000", + filiere: "pro", + ...DEFAULT_STATS, + }), + ]); + + const result = await importAnneesNonTerminales({ stats: "formations" }); + assert.deepEqual(result, { + created: 2, + failed: 0, + updated: 0, + }); + + const certificationPremiere = await FormationStatsRepository.first({ code_certification: "32220000000" }); + assert.deepEqual(omit(certificationPremiere, "_id"), { + uai: "0754247J", + code_certification: "32220000000", + millesime: "2018_2019", + code_certification_type: "mef11", + code_formation_diplome: "32000000", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + filiere: "pro", + libelle: "BAC PRO BATIMENT", + certificationsTerminales: [{ code_certification: "32230000000" }], + academie: { + code: "01", + nom: "Paris", + }, + region: { + code: "11", + nom: "Île-de-France", + }, + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + + const certificationSeconde = await FormationStatsRepository.first({ code_certification: "32210000000" }); + assert.deepEqual(omit(certificationSeconde, "_id"), { + uai: "0754247J", + code_certification: "32210000000", + millesime: "2018_2019", + code_certification_type: "mef11", + code_formation_diplome: "32000000", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + filiere: "pro", + libelle: "BAC PRO BATIMENT", + certificationsTerminales: [{ code_certification: "32230000000" }], + academie: { + code: "01", + nom: "Paris", + }, + region: { + code: "11", + nom: "Île-de-France", + }, + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + }); + }); +}); diff --git a/server/tests/jobs/stats/importSecondeCommune-test.js b/server/tests/jobs/stats/importSecondeCommune-test.js new file mode 100644 index 00000000..f53829ba --- /dev/null +++ b/server/tests/jobs/stats/importSecondeCommune-test.js @@ -0,0 +1,278 @@ +import chai, { assert } from "chai"; +import chaiAsPromised from "chai-as-promised"; +import MockDate from "mockdate"; +import { omit } from "lodash-es"; +import { + insertMEF, + insertRegionalesStats, + insertCertificationsStats, + insertFormationsStats, +} from "#tests/utils/fakeData.js"; +import CertificationStatsRepository from "#src/common/repositories/certificationStats.js"; +import RegionaleStatsRepository from "#src/common/repositories/regionaleStats.js"; +import FormationStatsRepository from "#src/common/repositories/formationStats.js"; +import { importSecondeCommune } from "#src/jobs/stats/importSecondeCommune.js"; + +chai.use(chaiAsPromised); + +describe("importSecondeCommune", () => { + before(() => { + MockDate.set("2023-01-01"); + }); + + after(() => { + MockDate.reset(); + }); + + const DEFAULT_STATS = { + nb_annee_term: 50, + nb_en_emploi_12_mois: 25, + nb_en_emploi_18_mois: 25, + nb_en_emploi_24_mois: 25, + nb_en_emploi_6_mois: 45, + nb_poursuite_etudes: 5, + nb_sortant: 45, + taux_autres_12_mois: 40, + taux_autres_18_mois: 40, + taux_autres_24_mois: 40, + taux_autres_6_mois: 0, + taux_en_emploi_12_mois: 50, + taux_en_emploi_18_mois: 50, + taux_en_emploi_24_mois: 50, + taux_en_emploi_6_mois: 90, + taux_en_formation: 10, + taux_rupture_contrats: 10, + }; + + describe("Au niveau certifications", () => { + it("Vérifie que l'on ajoute la seconde commune pour les certifications dans une famille de métier", async () => { + await Promise.all([ + insertMEF({ + code_certification: "23810031211", + code_formation_diplome: "40031211", + libelle_long: "2NDPRO MET. RELATION CLIENT 2NDE COMMUNE", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: true }, + }), + insertMEF({ + code_certification: "23830031212", + code_formation_diplome: "40031212", + libelle_long: "TLEPRO METIERS DE L'ACCUEIL", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + }), + insertMEF({ + code_certification: "23830031213", + code_formation_diplome: "40031213", + libelle_long: "TLEPRO MET.COM.VEN.OP.A ANI.GES.ESP.COM. ", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + }), + insertCertificationsStats({ + code_certification: "23830031212", + code_formation_diplome: "40031212", + filiere: "pro", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + ...DEFAULT_STATS, + }), + insertCertificationsStats({ + code_certification: "23830031213", + code_formation_diplome: "40031213", + filiere: "pro", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + ...DEFAULT_STATS, + }), + ]); + + const result = await importSecondeCommune({ stats: "certifications" }); + assert.deepEqual(result, { + created: 1, + failed: 0, + updated: 0, + }); + + const certification = await CertificationStatsRepository.first({ code_certification: "23810031211" }); + assert.deepEqual(omit(certification, ["_id", "certificationsTerminales"]), { + code_certification: "23810031211", + millesime: "2020", + code_certification_type: "mef11", + code_formation_diplome: "40031211", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: true }, + filiere: "pro", + libelle: "2NDPRO MET. RELATION CLIENT 2NDE COMMUNE", + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + assert.sameDeepMembers(certification.certificationsTerminales, [ + { + code_certification: "23830031212", + }, + { + code_certification: "23830031213", + }, + ]); + }); + }); + + describe("Au niveau régionales", () => { + it("Vérifie que l'on ajoute la seconde commune pour les certifications dans une famille de métier", async () => { + await Promise.all([ + insertMEF({ + code_certification: "23810031211", + code_formation_diplome: "40031211", + libelle_long: "2NDPRO MET. RELATION CLIENT 2NDE COMMUNE", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: true }, + }), + insertMEF({ + code_certification: "23830031212", + code_formation_diplome: "40031212", + libelle_long: "TLEPRO METIERS DE L'ACCUEIL", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + }), + insertMEF({ + code_certification: "23830031213", + code_formation_diplome: "40031213", + libelle_long: "TLEPRO MET.COM.VEN.OP.A ANI.GES.ESP.COM. ", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + }), + insertRegionalesStats({ + code_certification: "23830031212", + code_formation_diplome: "40031212", + filiere: "pro", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + ...DEFAULT_STATS, + }), + insertRegionalesStats({ + code_certification: "23830031213", + code_formation_diplome: "40031213", + filiere: "pro", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + ...DEFAULT_STATS, + }), + ]); + + const result = await importSecondeCommune({ stats: "regionales" }); + assert.deepEqual(result, { + created: 1, + failed: 0, + updated: 0, + }); + + const certification = await RegionaleStatsRepository.first({ code_certification: "23810031211" }); + assert.deepEqual(omit(certification, "_id"), { + code_certification: "23810031211", + millesime: "2018_2019", + code_certification_type: "mef11", + code_formation_diplome: "40031211", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: true }, + filiere: "pro", + libelle: "2NDPRO MET. RELATION CLIENT 2NDE COMMUNE", + certificationsTerminales: [ + { + code_certification: "23830031212", + }, + { + code_certification: "23830031213", + }, + ], + region: { + code: "11", + code_region_academique: "10", + nom: "Île-de-France", + }, + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + }); + }); + + describe("Au niveau formations", () => { + it("Vérifie que l'on ajoute la seconde commune pour les certifications dans une famille de métier", async () => { + await Promise.all([ + insertMEF({ + code_certification: "23810031211", + code_formation_diplome: "40031211", + libelle_long: "2NDPRO MET. RELATION CLIENT 2NDE COMMUNE", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: true }, + }), + insertMEF({ + code_certification: "23830031212", + code_formation_diplome: "40031212", + libelle_long: "TLEPRO METIERS DE L'ACCUEIL", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + }), + insertMEF({ + code_certification: "23830031213", + code_formation_diplome: "40031213", + libelle_long: "TLEPRO MET.COM.VEN.OP.A ANI.GES.ESP.COM. ", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + }), + insertFormationsStats({ + uai: "01234567", + code_certification: "23830031212", + code_formation_diplome: "40031212", + filiere: "pro", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + ...DEFAULT_STATS, + }), + insertFormationsStats({ + uai: "01234567", + code_certification: "23830031213", + code_formation_diplome: "40031213", + filiere: "pro", + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: false }, + ...DEFAULT_STATS, + }), + ]); + + const result = await importSecondeCommune({ stats: "formations" }); + assert.deepEqual(result, { + created: 1, + failed: 0, + updated: 0, + }); + + const certification = await FormationStatsRepository.first({ code_certification: "23810031211" }); + assert.deepEqual(omit(certification, "_id"), { + uai: "01234567", + code_certification: "23810031211", + millesime: "2018_2019", + code_certification_type: "mef11", + code_formation_diplome: "40031211", + date_fermeture: new Date("2022-08-30T22:00:00.000Z"), + diplome: { code: "4", libelle: "BAC" }, + familleMetier: { code: "003", libelle: "RELATION CLIENT", isAnneeCommune: true }, + filiere: "pro", + libelle: "2NDPRO MET. RELATION CLIENT 2NDE COMMUNE", + certificationsTerminales: [ + { + code_certification: "23830031212", + }, + { + code_certification: "23830031213", + }, + ], + academie: { + code: "01", + nom: "Paris", + }, + region: { + code: "11", + nom: "Île-de-France", + }, + _meta: { + created_on: new Date(), + date_import: new Date(), + updated_on: new Date(), + }, + }); + }); + }); +});