From c8e5333af75ffe8715bb3ac8bac099df7b41bb19 Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Fri, 23 Sep 2022 11:20:14 +0200 Subject: [PATCH] test --- src/onDeleteAccount.js | 97 +++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/src/onDeleteAccount.js b/src/onDeleteAccount.js index 5ccf9dc..42bf5c6 100644 --- a/src/onDeleteAccount.js +++ b/src/onDeleteAccount.js @@ -20,60 +20,61 @@ async function onDeleteAccount() { log('info', 'Getting secrets ...') const ACCOUNT_ID = getAccountId() const accountRev = getAccountRev() - - if (accountRev) { - log('info', 'Account rev exist') - const accountData = await getAccountForDelete(ACCOUNT_ID, accountRev) - // Parse local info for deletion test - if (isLocal()) { - log('warn', 'Local run') - const fields = JSON.parse( - process.env.COZY_FIELDS ? process.env.COZY_FIELDS : '{}' + if (!isAlpha()) { + if (accountRev) { + log('info', 'Account rev exist') + const accountData = await getAccountForDelete(ACCOUNT_ID, accountRev) + // Parse local info for deletion test + if (isLocal()) { + log('warn', 'Local run') + 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, + accountData.data.consentId ) - process.env.COZY_FIELDS = JSON.stringify({ - ...fields, - ...accountData.auth, - }) - } - const secrets = getAccountSecret() - const userConsent = await getBoConsent( - secrets.boBaseUrl, - secrets.boToken, - accountData.data.consentId - ) - if (userConsent.ID && userConsent.pointID) { - log('log', `Consent ${userConsent.ID} found for user`) - if (userConsent.serviceID) { - await deleteBoConsent( - secrets.boBaseUrl, - secrets.boToken, - userConsent.ID - ) - // Verify if it's dev env to prevent delete of real data - if (!isAlpha()) { - await terminateContract( - secrets.wso2BaseUrl, - secrets.apiToken, - secrets.sgeLogin, - secrets.contractId, - userConsent.pointID, - userConsent.serviceID + if (userConsent.ID && userConsent.pointID) { + log('log', `Consent ${userConsent.ID} found for user`) + if (userConsent.serviceID) { + await deleteBoConsent( + secrets.boBaseUrl, + secrets.boToken, + userConsent.ID ) + // Verify if it's dev env to prevent delete of real data + if (!isAlpha()) { + await terminateContract( + secrets.wso2BaseUrl, + secrets.apiToken, + secrets.sgeLogin, + secrets.contractId, + userConsent.pointID, + userConsent.serviceID + ) + } + } else { + log('error', `No service id retrieved from BO`) + throw errors.VENDOR_DOWN } - } else { - log('error', `No service id retrieved from BO`) - throw errors.VENDOR_DOWN } - } - log('info', 'Deleting account succeed') - } else { - log( - 'error', - 'No account revision was found, something went wrong during the deletion of said account' - ) - throw errors.VENDOR_DOWN + log('info', 'Deleting account succeed') + } else { + log( + 'error', + 'No account revision was found, something went wrong during the deletion of said account' + ) + throw errors.VENDOR_DOWN + } } } -- GitLab