Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRO-16890 : Enforce required flags for provar:metadatacache #26

Merged
merged 5 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}