Skip to content

Commit

Permalink
[DEMANDE DEVENIR AIDANT] Prends en compte les paramètres optionnels d…
Browse files Browse the repository at this point in the history
…e recherche
  • Loading branch information
bbougon committed Jan 6, 2025
1 parent 5bbbb20 commit 851a6b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,19 @@ export const routesAPIRechercheEntreprise = (
suite: NextFunction
) => {
const nomEntreprise: string = requete.query.nom as string;
const parametresRecherche = Object.entries(requete.query).reduce(
(precedent, courant) => {
const parametres = courant as [string, string];
if (parametres[0] !== 'nom') {
precedent += `&${parametres[0]}=${parametres[1]}`;
}
return precedent;
},
''
);
return adaptateurDeRequeteHTTP
.execute<ReponseAPIRechercheEntreprise>({
url: `${adaptateurEnvironnement.apiRechercheEntreprise().url()}/search?q=${encodeURIComponent(nomEntreprise)}&per_page=25&limite_matching_etablissements=1`,
url: `${adaptateurEnvironnement.apiRechercheEntreprise().url()}/search?q=${encodeURIComponent(nomEntreprise)}${parametresRecherche}&per_page=25&limite_matching_etablissements=1`,
headers: { Accept: 'application/json' },
methode: 'GET',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ describe('Le serveur MAC, sur les routes de recherche entreprise', () => {
);
});

it('Prends en compte les paramètres de requêtes optionnels', async () => {
testeurMAC.adaptateurDeRequeteHTTP.reponse({
results: [{ siege: { siret: '1234567890' }, nom_complet: 'Beta-Gouv' }],
});

await executeRequete(
donneesServeur.app,
'GET',
'/api/recherche-entreprise?nom=beta&est_association=true',
donneesServeur.portEcoute
);

expect(testeurMAC.adaptateurDeRequeteHTTP.requeteAttendue).toStrictEqual(
'/search?q=beta&est_association=true&per_page=25&limite_matching_etablissements=1'
);
});

it('Retourne une erreur si la requête a échoué', async () => {
testeurMAC.adaptateurDeRequeteHTTP.reponse(
{
Expand Down

0 comments on commit 851a6b4

Please sign in to comment.