From a5f6ecc72de63f1fdd68961ed04cbf820047f16c Mon Sep 17 00:00:00 2001
From: build-token <build-token>
Date: Thu, 3 Aug 2023 15:07:25 +0000
Subject: [PATCH] publish: Merge branch
 '26-le-parcours-de-secours-ne-remonte-pas-correctement-le-champ-escalieretetageetappartement'
 into 'main'

generated from commit 358b2f25c486dde7beff690c8150881d336edfdd
---
 index.js           | 49 +++++++++++++++++++++++++++++++++++++++++++---
 onDeleteAccount.js | 27 +++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index 6056fa8..ae4781e 100644
--- a/index.js
+++ b/index.js
@@ -229245,6 +229245,32 @@ function removeMultipleSpaces(str) {
   return str.replace(/  +/g, ' ')
 }
 
+/**
+ * Remove SGE useless dots
+ * This regular expression matches one or more consecutive dots
+ * and then in the replacement function, it checks if the dots are surrounded by non-dot characters.
+ * If so, it replaces them with a space; otherwise, it removes them
+ * @example
+ * console.log(removeDots(".....03G2")); // Outputs: "03G2"
+ * console.log(removeDots("....ETG..4...D")); // Outputs: "ETG 4 D"
+ * console.log(removeDots("ETG 4 D")); // Outputs: "ETG 4 D"
+ * @param {string} input - The input string containing dots to be removed.
+ * @returns {string} The input string without dots.
+ */
+function removeDots(input) {
+  return input.replace(/\.+/g, (match, offset, string) => {
+    if (
+      offset > 0 &&
+      offset < string.length - match.length &&
+      string[offset - 1] !== '.' &&
+      string[offset + match.length] !== '.'
+    ) {
+      return ' '
+    }
+    return ''
+  })
+}
+
 /**
  * Remove SGE address number
  * @param {string} str
@@ -229286,6 +229312,7 @@ module.exports = {
   parseValueHalfHour,
   removeAddressNumber,
   removeMultipleSpaces,
+  removeDots,
 }
 
 
@@ -247365,6 +247392,7 @@ const { getInseeCode } = __webpack_require__(1727)
 const { findUserAddress } = __webpack_require__(1728)
 const {
   removeMultipleSpaces,
+  removeDots,
   removeAddressNumber,
 } = __webpack_require__(1599)
 const Sentry = __webpack_require__(1639)
@@ -247438,7 +247466,7 @@ async function verifyUserIdentity(
       escalierEtEtageEtAppartement
     )
 
-    // Third try, remove address number because it's buggy on SGE side
+    // Third try, remove address number
     if (!pdl) {
       log('warn', 'Third try onboarding for sge')
       pdl = await findUserPdl(
@@ -247452,9 +247480,24 @@ async function verifyUserIdentity(
       )
     }
 
-    // Fourth try, remove address number and add escalierEtEtageEtAppartement because it's buggy on SGE side
+    // Fourth try, add escalierEtEtageEtAppartement
     if (!pdl) {
       log('warn', 'Fourth try onboarding for sge')
+      pdl = await findUserPdl(
+        `${baseUrl}/enedis_SDE_recherche-point/1.0`,
+        apiAuthKey,
+        loginUtilisateur,
+        lastname,
+        removeMultipleSpaces(userAddress.numeroEtNomVoie),
+        userAddress.codePostal,
+        userAddress.commune.$.code,
+        removeDots(escalierEtEtageEtAppartement)
+      )
+    }
+
+    // Fifth try, remove address number and add escalierEtEtageEtAppartement
+    if (!pdl) {
+      log('warn', 'Fifth try onboarding for sge')
       pdl = await findUserPdl(
         `${baseUrl}/enedis_SDE_recherche-point/1.0`,
         apiAuthKey,
@@ -247463,7 +247506,7 @@ async function verifyUserIdentity(
         removeMultipleSpaces(removeAddressNumber(userAddress.numeroEtNomVoie)),
         userAddress.codePostal,
         userAddress.commune.$.code,
-        escalierEtEtageEtAppartement
+        removeDots(escalierEtEtageEtAppartement)
       )
     }
 
diff --git a/onDeleteAccount.js b/onDeleteAccount.js
index 5b77681..71e230d 100644
--- a/onDeleteAccount.js
+++ b/onDeleteAccount.js
@@ -228478,6 +228478,32 @@ function removeMultipleSpaces(str) {
   return str.replace(/  +/g, ' ')
 }
 
+/**
+ * Remove SGE useless dots
+ * This regular expression matches one or more consecutive dots
+ * and then in the replacement function, it checks if the dots are surrounded by non-dot characters.
+ * If so, it replaces them with a space; otherwise, it removes them
+ * @example
+ * console.log(removeDots(".....03G2")); // Outputs: "03G2"
+ * console.log(removeDots("....ETG..4...D")); // Outputs: "ETG 4 D"
+ * console.log(removeDots("ETG 4 D")); // Outputs: "ETG 4 D"
+ * @param {string} input - The input string containing dots to be removed.
+ * @returns {string} The input string without dots.
+ */
+function removeDots(input) {
+  return input.replace(/\.+/g, (match, offset, string) => {
+    if (
+      offset > 0 &&
+      offset < string.length - match.length &&
+      string[offset - 1] !== '.' &&
+      string[offset + match.length] !== '.'
+    ) {
+      return ' '
+    }
+    return ''
+  })
+}
+
 /**
  * Remove SGE address number
  * @param {string} str
@@ -228519,6 +228545,7 @@ module.exports = {
   parseValueHalfHour,
   removeAddressNumber,
   removeMultipleSpaces,
+  removeDots,
 }
 
 
-- 
GitLab