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 1 commit
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@provartesting/provardx",
"description": "A plugin for the Salesforce CLI to run provar testcases",
"version": "0.2.2",
"version": "0.2.4",
"author": "Provar",
"bugs": "https://github.com/ProvarTesting/provardx/issues",
"dependencies": {
Expand Down
67 changes: 50 additions & 17 deletions src/commands/provar/metadatacache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ 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 (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it to:
if (!["Reload", "Refresh", "Reuse"].includes(metadataLevel))

metadataLevel !== "Reload" && metadataLevel !== "Refresh" && metadataLevel !== "Reuse"
) {
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 +114,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 +135,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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userInfo === null

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 +185,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 v = override.split(':');
const prop = properties.connectionOverride.find(f => f.connection === v[0]);
if(prop){
prop.username = v[1];
}
}
}
properties.connectionOverride = connOver;
}
}