From 1d25b10e87ec6ed0f17740594517ea226160d4bf Mon Sep 17 00:00:00 2001 From: Mayank Nehru Date: Fri, 28 Aug 2020 17:17:56 +0530 Subject: [PATCH] PRO-16890 : Enforce required flags for provar:metadatacache (#26) * PRO-16890 : Enforce required flags for provar:metadatacache The command started executing even when required flags were not given. Changed that to give error in typescript itself. Also made changes to make sure that the flags work correctly in tandem. * PRO-16890 : Implement review comments and add change log * PRO-16890 : Implement review comments Corrected conditional checks to use "===" & '!==' for comparison and renamed variables with self explanatory names * PRO-16890 : Implement review comments Co-authored-by: mayank.nehru --- CHANGELOG.md | 8 ++++ package.json | 3 +- src/commands/provar/metadatacache.ts | 65 ++++++++++++++++++++-------- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea80fa8..95b3b06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.2.4] - 2020-08-25 + +### Fixed + +- Enforced the required flags for ProvarDX metadatacache command +- Fixed the working of flags for ProvarDX metadatacache command in tandem + ## [0.2.3] - 2020-08-25 ### Fixed diff --git a/package.json b/package.json index 890eb04..fc96ee9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "@provartesting/provardx", "description": "A plugin for the Salesforce CLI to run provar testcases", - "version": "0.2.3", + + "version": "0.2.4", "author": "Provar", "bugs": "https://github.com/ProvarTesting/provardx/issues", "dependencies": { diff --git a/src/commands/provar/metadatacache.ts b/src/commands/provar/metadatacache.ts index d743610..b83757f 100644 --- a/src/commands/provar/metadatacache.ts +++ b/src/commands/provar/metadatacache.ts @@ -81,6 +81,22 @@ export default class MetadataCache extends SfdxCommand { const connections: string = this.flags.connections; const connectionoverrides: string = this.flags.connectionoverrides; + if ( + !metadataLevel || !cachePath + ) { + this.ux.error( + "ERROR running provar:metadatacache : Please specify a cachepath and metadatalevel" + ); + return {}; + } + + if (!["Reload", "Refresh", "Reuse"].includes(metadataLevel)) { + this.ux.error( + "ERROR running provar:metadatacache : Please specify a valid metadata level(-m flag). Valid levels are : 'Reuse', 'Refresh' and 'Reload'" + ); + return {}; + } + const provarDxUtils: ProvarDXUtility = new ProvarDXUtility(); const isValid: boolean = provarDxUtils.validatePropertiesJson( propertyFile @@ -96,7 +112,7 @@ export default class MetadataCache extends SfdxCommand { provarDxUtils.hasDuplicateConnectionOverride(propertiesInstance) ) { this.ux.error( - "Invalid property file. Run command sfdx provar:validate' to know the validation errors" + "ERROR running provar:metadatacache : Please specify a valid property file. Run command sfdx provar:validate' to know the validation errors" ); return {}; } @@ -117,26 +133,26 @@ export default class MetadataCache extends SfdxCommand { const userInfo = await provarDxUtils.getDxUsersInfo( properties.connectionOverride ); - if (userInfo == null) { + if (userInfo === null && !connections) { this.ux.error( '[ERROR] No valid user org found to download metadata. Terminating command.' ); return {}; } - const userInfoString = provarDxUtils.prepareRawProperties( + const userInfoString = connections && userInfo === null ? "NA" : provarDxUtils.prepareRawProperties( JSON.stringify({ dxUsers: userInfo }) ); const jarPath = properties.provarHome + '/provardx/provardx.jar'; execSync( 'java -cp "' + - jarPath + - '" com.provar.provardx.DxCommandExecuter ' + - updateProperties + - ' ' + - userInfoString + - ' ' + - 'Metadata', + jarPath + + '" com.provar.provardx.DxCommandExecuter ' + + updateProperties + + ' ' + + userInfoString + + ' ' + + 'Metadata', { stdio: 'inherit' } ); return {}; @@ -167,15 +183,30 @@ export default class MetadataCache extends SfdxCommand { properties: any, connectionOverride: string ): void { - if (!connectionOverride) { + if (!connectionOverride && !properties.connectionName) { return; } - const overrides = connectionOverride.split(','); - const connOver = []; - for (const override of overrides) { - const v = override.split(':'); - connOver.push({ connection: v[0], username: v[1] }); + + if (properties.connectionName && properties.connectionOverride) { + const overrides = properties.connectionName.split(','); + const connOver = []; + for (const override of properties.connectionOverride) { + if (overrides.indexOf(override.connection) !== -1) { + connOver.push(override); + } + } + properties.connectionOverride = connOver; + } + + if (connectionOverride) { + const overrides = connectionOverride.split(','); + for (const override of overrides) { + const overrideDetails = override.split(':'); + const prop = properties.connectionOverride.find(f => f.connection === overrideDetails[0]); + if(prop){ + prop.username = overrideDetails[1]; + } + } } - properties.connectionOverride = connOver; } }