From df5d4c921770e9acc21b381ffbc40ff7b8cc779a Mon Sep 17 00:00:00 2001 From: Andrea Ligios <11974750+andrea-ligios@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:42:34 +0200 Subject: [PATCH 1/2] Straighten the method with guard clauses --- lib/commons/config.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/commons/config.js b/lib/commons/config.js index 0700b92..9c924c7 100644 --- a/lib/commons/config.js +++ b/lib/commons/config.js @@ -18,18 +18,13 @@ const getRequiredOption = (options, optionName) => { }; const getApiKey = ({ apiKey, token }) => { - let calculatedApiKey = apiKey; - if (!calculatedApiKey) { - calculatedApiKey = token; - if (!calculatedApiKey) { - throw new ReportPortalRequiredOptionError('apiKey'); - } else { - console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`); - } - } - - return calculatedApiKey; -}; + if (apiKey) return apiKey; + + if (!token) throw new ReportPortalRequiredOptionError('apiKey'); + + console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`); + return token; +} const getOAuthConfig = (options) => { const oauthParams = options.oauth || {}; From f43d930a27ee494621791b6546f9086e8e6d0a92 Mon Sep 17 00:00:00 2001 From: Andrea Ligios <11974750+andrea-ligios@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:50:02 +0200 Subject: [PATCH 2/2] Fix syntax and whitespaces --- lib/commons/config.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/commons/config.js b/lib/commons/config.js index 9c924c7..9ef0dd7 100644 --- a/lib/commons/config.js +++ b/lib/commons/config.js @@ -19,12 +19,10 @@ const getRequiredOption = (options, optionName) => { const getApiKey = ({ apiKey, token }) => { if (apiKey) return apiKey; - if (!token) throw new ReportPortalRequiredOptionError('apiKey'); - console.warn(`Option 'token' is deprecated. Use 'apiKey' instead.`); return token; -} +}; const getOAuthConfig = (options) => { const oauthParams = options.oauth || {};