From dd2ca177a26f400e439f9ab628bb1408f3f68d52 Mon Sep 17 00:00:00 2001 From: Kevin Barnoin Date: Wed, 18 Sep 2024 19:06:30 +0200 Subject: [PATCH] fix: post v2/jobs: traduction & workplace_name (#1519) * fix: traduction & workplace_name * fix: snapshot --- server/src/services/etablissement.service.ts | 34 +++++++++++++++---- .../jobOpportunity.service.test.ts.snap | 4 +-- .../jobOpportunity/jobOpportunity.service.ts | 7 ++-- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/server/src/services/etablissement.service.ts b/server/src/services/etablissement.service.ts index 61a7b169fe..7b42cbbc2f 100644 --- a/server/src/services/etablissement.service.ts +++ b/server/src/services/etablissement.service.ts @@ -462,28 +462,48 @@ export const validateCreationEntrepriseFromCfa = async ({ siret, cfa_delegated_s } } -export const getEntrepriseDataFromSiret = async ({ siret, type }: { siret: string; type: "CFA" | "ENTREPRISE" }): Promise => { +export const getEntrepriseDataFromSiret = async ({ + siret, + type, + isApiApprentissage = false, +}: { + siret: string + type: "CFA" | "ENTREPRISE" + isApiApprentissage?: boolean +}): Promise => { const result = await getEtablissementFromGouvSafe(siret) if (!result) { return errorFactory("Le numéro siret est invalide.") } if (result === BusinessErrorCodes.NON_DIFFUSIBLE) { - return errorFactory( - `Les informations de votre entreprise sont non diffusibles. Contacter le support pour en savoir plus`, - BusinessErrorCodes.NON_DIFFUSIBLE - ) + if (isApiApprentissage) { + return errorFactory("Non-distributable company.", BusinessErrorCodes.NON_DIFFUSIBLE) + } else { + return errorFactory( + `Les informations de votre entreprise sont non diffusibles. Contacter le support pour en savoir plus`, + BusinessErrorCodes.NON_DIFFUSIBLE + ) + } } const { etat_administratif, activite_principale } = result.data if (etat_administratif === "F") { - return errorFactory("Cette entreprise est considérée comme fermée.", BusinessErrorCodes.CLOSED) + if (isApiApprentissage) { + return errorFactory("The company is considered closed.", BusinessErrorCodes.CLOSED) + } else { + return errorFactory("Cette entreprise est considérée comme fermée.", BusinessErrorCodes.CLOSED) + } } // Check if a CFA already has the company as partenaire if (type === ENTREPRISE) { // Allow cfa to add themselves as a company if (activite_principale.code.startsWith("85")) { - return errorFactory("Le numéro siret n'est pas référencé comme une entreprise.", BusinessErrorCodes.IS_CFA) + if (isApiApprentissage) { + return errorFactory("The SIRET number is not referenced as a company.", BusinessErrorCodes.IS_CFA) + } else { + return errorFactory("Le numéro siret n'est pas référencé comme une entreprise.", BusinessErrorCodes.IS_CFA) + } } } const entrepriseData = formatEntrepriseData(result.data) diff --git a/server/src/services/jobs/jobOpportunity/__snapshots__/jobOpportunity.service.test.ts.snap b/server/src/services/jobs/jobOpportunity/__snapshots__/jobOpportunity.service.test.ts.snap index 8ec10cb2c8..45b48784f6 100644 --- a/server/src/services/jobs/jobOpportunity/__snapshots__/jobOpportunity.service.test.ts.snap +++ b/server/src/services/jobs/jobOpportunity/__snapshots__/jobOpportunity.service.test.ts.snap @@ -48,7 +48,7 @@ exports[`createJobOffer > should create a job offer with the minimal data 1`] = "workplace_legal_name": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE", "workplace_naf_code": "84.11Z", "workplace_naf_label": "Administration publique générale", - "workplace_name": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE", + "workplace_name": null, "workplace_opco": "AKTO / Opco entreprises et salariés des services à forte intensité de main d'oeuvre", "workplace_siret": "13002526500013", "workplace_size": "100 à 199 salariés", @@ -287,7 +287,7 @@ exports[`updateJobOffer > should update a job offer with the minimal data 1`] = "workplace_legal_name": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE", "workplace_naf_code": "84.11Z", "workplace_naf_label": "Administration publique générale", - "workplace_name": "DIRECTION INTERMINISTERIELLE DU NUMERIQUE", + "workplace_name": null, "workplace_opco": "AKTO / Opco entreprises et salariés des services à forte intensité de main d'oeuvre", "workplace_siret": "13002526500013", "workplace_size": "100 à 199 salariés", diff --git a/server/src/services/jobs/jobOpportunity/jobOpportunity.service.ts b/server/src/services/jobs/jobOpportunity/jobOpportunity.service.ts index 2bb40b0760..a9a91ed566 100644 --- a/server/src/services/jobs/jobOpportunity/jobOpportunity.service.ts +++ b/server/src/services/jobs/jobOpportunity/jobOpportunity.service.ts @@ -556,7 +556,6 @@ type WorkplaceSiretData = Pick< IJobsPartnersOfferApi, | "workplace_geopoint" | "workplace_address" - | "workplace_name" | "workplace_legal_name" | "workplace_brand" | "workplace_naf_label" @@ -567,7 +566,10 @@ type WorkplaceSiretData = Pick< > async function resolveWorkplaceDataFromSiret(workplace_siret: string, zodError: ZodError): Promise { - const [entrepriseData, opcoData] = await Promise.all([getEntrepriseDataFromSiret({ siret: workplace_siret, type: "ENTREPRISE" }), getOpcoData(workplace_siret)]) + const [entrepriseData, opcoData] = await Promise.all([ + getEntrepriseDataFromSiret({ siret: workplace_siret, type: "ENTREPRISE", isApiApprentissage: true }), + getOpcoData(workplace_siret), + ]) if ("error" in entrepriseData) { zodError.addIssue({ code: "custom", path: ["workplace_siret"], message: entrepriseData.message }) @@ -577,7 +579,6 @@ async function resolveWorkplaceDataFromSiret(workplace_siret: string, zodError: return { workplace_geopoint: entrepriseData.geopoint, workplace_address: { label: entrepriseData.address! }, - workplace_name: entrepriseData.establishment_enseigne ?? entrepriseData.establishment_raison_sociale ?? null, workplace_brand: entrepriseData.establishment_enseigne ?? null, workplace_legal_name: entrepriseData.establishment_raison_sociale ?? null, workplace_naf_label: entrepriseData.naf_label ?? null,