Skip to content

Commit

Permalink
fix: throw deploy error when missing required params (#150)
Browse files Browse the repository at this point in the history
* fix: throw deploy error when missing required params

* chore: comma separate values

Co-authored-by: Willie Ruemmele <[email protected]>
  • Loading branch information
cristiand391 and WillieRuemmele authored Jul 26, 2021
1 parent 95739bf commit 234c596
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions messages/deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"validateDeployRequestId": "deploy request ID of the validated deployment to run a Quick Deploy",
"soapDeploy": "deploy metadata with SOAP API instead of REST API"
},
"MissingRequiredParam": "Missing one of the following parameters: %s",
"checkOnlySuccess": "Successfully validated the deployment. %s components deployed and %s tests run.\nUse the --verbose parameter to see detailed output.",
"MissingDeployId": "No deploy ID was provided or found in deploy history",
"deployCanceled": "The deployment has been canceled by %s",
Expand Down
10 changes: 9 additions & 1 deletion src/commands/force/source/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import * as os from 'os';
import { flags, FlagsConfig } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { Messages, SfdxError } from '@salesforce/core';
import { AsyncResult, DeployResult } from '@salesforce/source-deploy-retrieve';
import { Duration } from '@salesforce/kit';
import { getString, isString } from '@salesforce/ts-types';
Expand All @@ -23,6 +23,9 @@ import { DeployProgressStatusFormatter } from '../../../formatters/deployProgres
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-source', 'deploy');

// One of these flags must be specified for a valid deploy.
const requiredFlags = ['manifest', 'metadata', 'sourcepath', 'validateddeployrequestid'];

type TestLevel = 'NoTestRun' | 'RunSpecifiedTests' | 'RunLocalTests' | 'RunAllTestsInOrg';

export class Deploy extends DeployCommand {
Expand Down Expand Up @@ -109,6 +112,11 @@ export class Deploy extends DeployCommand {
});

public async run(): Promise<DeployCommandResult | DeployCommandAsyncResult> {
// verify that the user defined one of: manifest, metadata, sourcepath, validateddeployrequestid
if (!Object.keys(this.flags).some((flag) => requiredFlags.includes(flag))) {
throw SfdxError.create('@salesforce/plugin-source', 'deploy', 'MissingRequiredParam', [requiredFlags.join(', ')]);
}

await this.deploy();
this.resolveSuccess();
return this.formatResult();
Expand Down
15 changes: 14 additions & 1 deletion test/commands/source/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as sinon from 'sinon';
import { expect } from 'chai';
import { MetadataApiDeployOptions } from '@salesforce/source-deploy-retrieve';
import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon';
import { ConfigAggregator, Lifecycle, Org, SfdxProject } from '@salesforce/core';
import { ConfigAggregator, Lifecycle, Org, SfdxProject, Messages } from '@salesforce/core';
import { UX } from '@salesforce/command';
import { IConfig } from '@oclif/config';
import { Deploy } from '../../../src/commands/force/source/deploy';
Expand All @@ -24,6 +24,10 @@ import { DeployProgressBarFormatter } from '../../../src/formatters/deployProgre
import { DeployProgressStatusFormatter } from '../../../src/formatters/deployProgressStatusFormatter';
import { getDeployResult } from './deployResponses';
import { exampleSourceComponent } from './testConsts';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-source', 'deploy');

describe('force:source:deploy', () => {
const sandbox = sinon.createSandbox();
const username = '[email protected]';
Expand Down Expand Up @@ -177,6 +181,15 @@ describe('force:source:deploy', () => {
expect(initProgressBarStub.callCount).to.equal(callCount);
};

it('should error if sourcepath or manifest arguments are not provided', async () => {
const requiredFlags = 'manifest, metadata, sourcepath, validateddeployrequestid';
try {
await runDeployCmd([]);
} catch (e) {
expect((e as Error).message).to.equal(messages.getMessage('MissingRequiredParam', [requiredFlags]));
}
});

it('should pass along sourcepath', async () => {
const sourcepath = ['somepath'];
const result = await runDeployCmd(['--sourcepath', sourcepath[0], '--json']);
Expand Down

0 comments on commit 234c596

Please sign in to comment.