From 9cc5749c5752d122bfcb39eabe57ad705f42deef Mon Sep 17 00:00:00 2001
From: build-token <build-token>
Date: Thu, 22 Sep 2022 10:04:19 +0000
Subject: [PATCH] publish: fix(ondelete): local testing and variables

generated from commit b7155d143ce2b7042ee81434f8333b0f389eb409
---
 onDeleteAccount.js | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/onDeleteAccount.js b/onDeleteAccount.js
index 78f89d5..37f98e3 100644
--- a/onDeleteAccount.js
+++ b/onDeleteAccount.js
@@ -227469,12 +227469,23 @@ const ACCOUNT_ID = isLocal() ? 'default_account_id' : 'enedis-sge-grandlyon'
 async function onDeleteAccount() {
   log('info', 'Deleting account ...')
   log('info', 'Getting secrets ...')
-  const secrets = getAccountSecret()
+
   const accountRev = getAccountRev()
 
   if (accountRev) {
     log('info', 'Account rev exist')
     const accountData = await getAccount(ACCOUNT_ID)
+    // Parse local info for deletion test
+    if (isLocal()) {
+      const fields = JSON.parse(
+        process.env.COZY_FIELDS ? process.env.COZY_FIELDS : '{}'
+      )
+      process.env.COZY_FIELDS = JSON.stringify({
+        ...fields,
+        ...accountData.auth,
+      })
+    }
+    const secrets = getAccountSecret()
     const userConsent = await getBoConsent(
       secrets.boBaseUrl,
       secrets.boToken,
@@ -227490,8 +227501,8 @@ async function onDeleteAccount() {
           userConsent.ID
         )
         await terminateContract(
-          secrets.baseUrl,
-          secrets.apiAuthKey,
+          secrets.wso2BaseUrl,
+          secrets.apiToken,
           secrets.sgeLogin,
           secrets.contractId,
           userConsent.pointID,
@@ -227559,18 +227570,12 @@ function getAccountRev() {
 /**
  * Return account secrets.
  * For local testing, change value with values from your konnector-dev-config.json
+ * @returns {Fields}
  */
 function getAccountSecret() {
   try {
     return isLocal()
-      ? {
-          baseUrl: 'https://test.fr',
-          sgeLogin: 'test@test.com',
-          contractId: '134567',
-          boBaseUrl: 'https://botest.grandlyon.com/',
-          boToken: 'tok31n',
-          apiAuthKey: 'authkeYeasqqd56dsdq',
-        }
+      ? JSON.parse(process.env.COZY_FIELDS)
       : JSON.parse(process.env.COZY_PARAMETERS).secret
   } catch (err) {
     throw new Error(
-- 
GitLab