Skip to content

Commit

Permalink
PRO-16890 : Enforce required flags for provar:metadatacache (#26)
Browse files Browse the repository at this point in the history
* 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 <mayank.nehru@HP-Mayanknehru>
  • Loading branch information
Mayank Nehru and mayank.nehru committed Aug 28, 2020
1 parent 609db17 commit 1d25b10
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 18 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
65 changes: 48 additions & 17 deletions src/commands/provar/metadatacache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {};
}
Expand All @@ -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 {};
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 1d25b10

Please sign in to comment.