Skip to content

Commit

Permalink
feat: more resilient email comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
rdubigny committed Oct 9, 2023
1 parent 52e81e1 commit 8a8870e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/connectors/api-annuaire-education-nationale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,18 @@ export const getAnnuaireEducationNationaleContactEmail = async (
},
] = records;

if (!isEmailValid(mail)) {
const formattedEmail = mail.toLowerCase().trim();

if (!isEmailValid(formattedEmail)) {
throw new ApiAnnuaireInvalidEmailError();
}

if (DO_NOT_USE_ANNUAIRE_EMAILS) {
console.log(
`Test email address ${TEST_CONTACT_EMAIL} was used instead of the real one ${mail}.`
`Test email address ${TEST_CONTACT_EMAIL} was used instead of the real one ${formattedEmail}.`
);
return TEST_CONTACT_EMAIL;
}

return mail;
return formattedEmail;
};
8 changes: 5 additions & 3 deletions src/connectors/api-annuaire-service-public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,18 @@ export const getAnnuaireServicePublicContactEmail = async (
},
] = features;

if (!isEmailValid(email)) {
const formattedEmail = email.toLowerCase().trim();

if (!isEmailValid(formattedEmail)) {
throw new ApiAnnuaireInvalidEmailError();
}

if (DO_NOT_USE_ANNUAIRE_EMAILS) {
console.log(
`Test email address ${TEST_CONTACT_EMAIL} was used instead of the real one ${email}.`
`Test email address ${TEST_CONTACT_EMAIL} was used instead of the real one ${formattedEmail}.`
);
return TEST_CONTACT_EMAIL;
}

return email;
return formattedEmail;
};

0 comments on commit 8a8870e

Please sign in to comment.