From 8d7caca5eb09d26a4f5322bb357016de6cc2bfcf Mon Sep 17 00:00:00 2001 From: Xavier Jp Date: Wed, 6 Nov 2024 10:02:38 +0100 Subject: [PATCH] fix: qualifelec empty array and logo issues (#1322) * fix: qualifelec empty array and logo issues * test: add unit tests --- .env.dev | 2 -- clients/rge/index.ts | 2 ++ .../labels-and-certificates/rge/index.tsx | 8 ++--- .../rge/map-certicat-to-logo.tsx | 19 ------------ data/administrations/qualifelec.yml | 1 + models/certifications/rge.ts | 1 + .../association-protected/index.ts | 4 +-- models/espace-agent/certificats/qualifelec.ts | 19 +++++++++--- public/images/logos/qualifelec.svg | 1 + ...-qalifelec.jpg => logo-rge-qualifelec.jpg} | Bin .../certifications/certificats-logo.test.ts | 26 ++++++++++++++++ .../certifications/certificats-logo.ts | 29 ++++++++++++++++++ 12 files changed, 78 insertions(+), 34 deletions(-) delete mode 100644 components/labels-and-certificates/rge/map-certicat-to-logo.tsx create mode 100644 public/images/logos/qualifelec.svg rename public/images/rge/{logo-rge-qalifelec.jpg => logo-rge-qualifelec.jpg} (100%) create mode 100644 utils/helpers/certifications/certificats-logo.test.ts create mode 100644 utils/helpers/certifications/certificats-logo.ts diff --git a/.env.dev b/.env.dev index 936fac282..369c31842 100644 --- a/.env.dev +++ b/.env.dev @@ -15,8 +15,6 @@ MATOMO_SITE_ID= MATOMO_API_SITE_ID= ALTERNATIVE_SEARCH_ROUTE= PROXY_API_KEY= -REDIS_URL=redis://127.0.0.1:6379 -REDIS_ENABLED=false AGENTCONNECT_CLIENT_ID= AGENTCONNECT_CLIENT_SECRET= AGENTCONNECT_URL_DISCOVER=https://fca.integ01.dev-agentconnect.fr/api/v2/.well-known/openid-configuration diff --git a/clients/rge/index.ts b/clients/rge/index.ts index 8198900b4..252edc223 100644 --- a/clients/rge/index.ts +++ b/clients/rge/index.ts @@ -4,6 +4,7 @@ import stubClientWithSnapshots from '#clients/stub-client-with-snaphots'; import { INomCertificat, IRGECertification } from '#models/certifications/rge'; import { Siren } from '#utils/helpers'; import { httpGet } from '#utils/network'; +import { getCertificatLogoPath } from '../../utils/helpers/certifications/certificats-logo'; type IRGEResponse = { results: { @@ -90,6 +91,7 @@ const mapToDomainObject = (rge: IRGEResponse) => { url_qualification = '', } = result; certifications.push({ + logoPath: getCertificatLogoPath(nom_certificat), codeQualification: code_qualification, domaines: [domaine], nomCertificat: nom_certificat, diff --git a/components/labels-and-certificates/rge/index.tsx b/components/labels-and-certificates/rge/index.tsx index f62ea213b..875f6d61b 100644 --- a/components/labels-and-certificates/rge/index.tsx +++ b/components/labels-and-certificates/rge/index.tsx @@ -11,7 +11,6 @@ import { IRGECertification } from '#models/certifications/rge'; import { IUniteLegale } from '#models/core/types'; import { ISession } from '#models/user/session'; import React from 'react'; -import { certificatLogo } from './map-certicat-to-logo'; const renovLink = (slug: string) => { try { @@ -115,13 +114,10 @@ export const CertificationsRGESection: React.FC<{ head={['Certificat', 'Domaine(s) certifié(s)', 'Lien']} body={certificationsRGE.certifications.map((certification) => [
- {certification.nomCertificat in certificatLogo && ( + {certification.logoPath && (
{`Logo => { const siren = verifySiren(maybeSiren); - const response = clientApiEntrepriseAssociation(siren).catch((error) => + return clientApiEntrepriseAssociation(siren).catch((error) => handleApiEntrepriseError(error, { siren, apiResource: 'AssociationProtected', }) ); - - return response; }; diff --git a/models/espace-agent/certificats/qualifelec.ts b/models/espace-agent/certificats/qualifelec.ts index 5564a091b..66cc2cfd1 100644 --- a/models/espace-agent/certificats/qualifelec.ts +++ b/models/espace-agent/certificats/qualifelec.ts @@ -1,7 +1,12 @@ import { clientApiEntrepriseQualifelec } from '#clients/api-entreprise/qualifelec'; -import { IAPINotRespondingError } from '#models/api-not-responding'; +import { EAdministration } from '#models/administrations/EAdministration'; +import { + APINotRespondingFactory, + IAPINotRespondingError, +} from '#models/api-not-responding'; import { verifySiret } from '#utils/helpers'; import { handleApiEntrepriseError } from '../utils'; + export type IQualifelec = Array<{ documentUrl: string; numero: number; @@ -44,7 +49,13 @@ export const getQualifelec = async ( maybeSiret: string ): Promise => { const siret = verifySiret(maybeSiret); - return clientApiEntrepriseQualifelec(siret).catch((error) => - handleApiEntrepriseError(error, { siret, apiResource: 'Qualifelec' }) - ); + return clientApiEntrepriseQualifelec(siret) + .then((response) => + response.length === 0 + ? APINotRespondingFactory(EAdministration.QUALIFELEC, 404) + : response + ) + .catch((error) => + handleApiEntrepriseError(error, { siret, apiResource: 'Qualifelec' }) + ); }; diff --git a/public/images/logos/qualifelec.svg b/public/images/logos/qualifelec.svg new file mode 100644 index 000000000..181beaa7a --- /dev/null +++ b/public/images/logos/qualifelec.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/images/rge/logo-rge-qalifelec.jpg b/public/images/rge/logo-rge-qualifelec.jpg similarity index 100% rename from public/images/rge/logo-rge-qalifelec.jpg rename to public/images/rge/logo-rge-qualifelec.jpg diff --git a/utils/helpers/certifications/certificats-logo.test.ts b/utils/helpers/certifications/certificats-logo.test.ts new file mode 100644 index 000000000..3d0230857 --- /dev/null +++ b/utils/helpers/certifications/certificats-logo.test.ts @@ -0,0 +1,26 @@ +import { getCertificatLogoPath } from './certificats-logo'; + +describe('CertificatLogo works', () => { + test('valid certificatss names', () => { + expect(getCertificatLogoPath('qualifelec +')).toBe( + '/images/rge/logo-rge-qualifelec.jpg' + ); + expect(getCertificatLogoPath('qualipv')).toBe( + '/images/rge/logo-rge-qualiPV.jpg' + ); + expect(getCertificatLogoPath('chauffage +')).toBe( + '/images/rge/logo-rge-chauffage.jpg' + ); + expect(getCertificatLogoPath('habitat')).toBe( + '/images/rge/logo-rge-NF.jpg' + ); + }); + + test('Invalids certificates names', () => { + expect(getCertificatLogoPath('quali')).toBe(''); + expect(getCertificatLogoPath('3456')).toBe(''); + expect(getCertificatLogoPath('chauffage+')).toBe(''); + }); +}); + +export {}; diff --git a/utils/helpers/certifications/certificats-logo.ts b/utils/helpers/certifications/certificats-logo.ts new file mode 100644 index 000000000..729aef421 --- /dev/null +++ b/utils/helpers/certifications/certificats-logo.ts @@ -0,0 +1,29 @@ +const certificatsLogo = { + qualibat: 'qualibat.jpg', + qualifelec: 'qualifelec.jpg', + qualipac: 'qualiPAC.jpg', + qualibois: 'qualiBois.jpg', + opqibi: 'opqibi.jpg', + 'chauffage +': 'chauffage.jpg', + qualipv: 'qualiPV.jpg', + ventilation: 'ventillation.jpg', + qualisol: 'qualisol.jpg', + certibat: 'certibat.jpg', + habitat: 'NF.jpg', + qualiforage: 'aualiForage.jpg', +}; + +/** + * match logo path on partial certificats names as several certificates share the same logo + * + * eg : "Qualibois module Air" and "Qualibois module Eau" => QualiBois.jpg + * */ + +export const getCertificatLogoPath = (nomCertificat: string) => { + for (let [certificateSub, path] of Object.entries(certificatsLogo)) { + if ((nomCertificat || '').toLowerCase().indexOf(certificateSub) !== -1) { + return `/images/rge/logo-rge-${path}` || ''; + } + } + return ''; +};