From f753dabae49fed2e0d6dc803bf50b84817c50946 Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Wed, 18 Jan 2023 14:32:01 +0100 Subject: [PATCH] test: test login flow from invoices --- .vscode/settings.json | 1 + package.json | 1 + src/index.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 919e8c1..62efe43 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -43,6 +43,7 @@ "grandlyon", "HISTO", "insee", + "konnector", "konnectors", "lastname", "llle", diff --git a/package.json b/package.json index 7d0bd06..a1e17f4 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "pretest": "npm run clean", "release": "standard-version --no-verify", "standalone": "cozy-konnector-standalone", + "standalone-no-data": "NO_DATA=true cozy-konnector-standalone src/index.js", "start": "node ./src/index.js", "test:cov": "jest --coverage", "test": "jest", diff --git a/src/index.js b/src/index.js index 21306fa..8fd6b39 100644 --- a/src/index.js +++ b/src/index.js @@ -56,6 +56,7 @@ const startLoadDate = moment().subtract(7, 'day') const endDate = moment() const endDateString = endDate.format('YYYY-MM-DD') const ACCOUNT_ID = isLocal() ? 'default_account_id' : 'enedissgegrandlyon' +const NO_DATA = process.env.NO_DATA === 'true' module.exports = new BaseKonnector(start) @@ -92,6 +93,13 @@ async function start(fields, cozyParameters) { try { log('info', 'Konnector configuration ...') log('info', `isManual execution: ${manualExecution}`) + + if (NO_DATA) { + log( + 'debug', + 'NO_DATA is enabled, konnector will stop after verifyUserIdentity()' + ) + } const transaction = Sentry.startTransaction({ op: 'konnector', name: 'SGE Konnector', @@ -149,6 +157,8 @@ async function start(fields, cozyParameters) { sgeLogin ) + exitIfDebug(user) + let consent = await createBoConsent( boBaseUrl, boToken, @@ -230,6 +240,8 @@ async function start(fields, cozyParameters) { accountData.data.inseeCode ) + exitIfDebug(user) + if (!userConsent) { const errorMessage = 'No user consent found' log('error', errorMessage) @@ -623,3 +635,19 @@ function isFirstStart(account) { log('info', 'Konnector first start') return true } + +/** + * Check if konnector is launched in local with NO_DATA option + * If so, logs result from verifyUserIdentity() and stops the konnector before getting any data + * @param {User} user - The user object to log + */ +function exitIfDebug(user) { + if (NO_DATA) { + log( + 'debug', + `Stopping konnector before getting data, user found from verifyUserIdentity():` + ) + log('debug', user) + process.exit() + } +} -- GitLab