Skip to content

Commit

Permalink
fix: adds unit tests and NUTs
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Aug 10, 2022
1 parent 5a93522 commit 24dbd52
Show file tree
Hide file tree
Showing 7 changed files with 679 additions and 6 deletions.
10 changes: 5 additions & 5 deletions messages/package_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Supply the ID of the package version to install. The package installs in your de
For package upgrades, to specify options for component deprecation or deletion of removed components, include an --upgradetype value. To delete components that can be safely deleted and deprecate the others, specify --upgradetype Mixed (the default). To deprecate all removed components, specify --upgradetype DeprecateOnly. To delete all removed components, except for custom objects and custom fields, that don't have dependencies, specify --upgradetype Delete. (Note: This option can result in the loss of data that is associated with the deleted components.) The default is Mixed.

Examples:
$ sfdx force:package:install --package 04t... -u me@example.com
$ sfdx force:package:install --package awesome_package_alias
$ sfdx force:package:install --package "Awesome Package Alias"
$ sfdx force:package:install --package 04t... -t DeprecateOnly
$ sfdx force:package:beta:install --package 04t... -u me@example.com
$ sfdx force:package:beta:install --package awesome_package_alias
$ sfdx force:package:beta:install --package "Awesome Package Alias"
$ sfdx force:package:beta:install --package 04t... -t DeprecateOnly

# id

Expand Down Expand Up @@ -167,7 +167,7 @@ Waiting for the package install request to complete. Status = %s
# packageInstallInProgress

PackageInstallRequest is currently InProgress. You can continue to query the status using
sfdx force:package:install:report -i %s -u %s
sfdx force:package:beta:install:report -i %s -u %s

# packageInstallError

Expand Down
9 changes: 9 additions & 0 deletions src/commands/force/package/beta/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getPackageTypeBy04t,
PackageInstallCreateRequest,
} from '@salesforce/packaging';
import { Optional } from '@salesforce/ts-types';
import { QueryResult } from 'jsforce';
type PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
type SubscriberPackageVersion = PackagingSObjects.SubscriberPackageVersion;
Expand Down Expand Up @@ -147,6 +148,14 @@ export class Install extends SfdxCommand {
return pkgInstallRequest;
}

protected async finally(err: Optional<Error>): Promise<void> {
// Remove all the event listeners or they will still handle events
Lifecycle.getInstance().removeAllListeners('PackageInstallRequest:warning');
Lifecycle.getInstance().removeAllListeners('PackageInstallRequest:status');
Lifecycle.getInstance().removeAllListeners('SubscriberPackageVersion:status');
await super.finally(err);
}

private async confirmUpgradeType(request: PackageInstallCreateRequest, noPrompt: boolean): Promise<void> {
const pkgType = await getPackageTypeBy04t(request.SubscriberPackageVersionKey, this.connection, request.Password);
if (pkgType === 'Unlocked' && !noPrompt) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/force/package/beta/install/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Report extends SfdxCommand {
private parseStatus(request: PackageInstallRequest): void {
const { Status } = request;
if (Status === 'SUCCESS') {
this.ux.log(installMsgs.getMessage('packageInstallSuccess', [request.Id]));
this.ux.log(installMsgs.getMessage('packageInstallSuccess', [request.SubscriberPackageVersionKey]));
} else if (['IN_PROGRESS', 'UNKNOWN'].includes(Status)) {
this.ux.log(installMsgs.getMessage('packageInstallInProgress', [request.Id, this.org.getUsername()]));
} else {
Expand Down
Empty file.
42 changes: 42 additions & 0 deletions test/commands/force/package/install.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { expect } from 'chai';
import { PackagingSObjects } from '@salesforce/packaging';
type PackageInstallRequest = PackagingSObjects.PackageInstallRequest;

describe('package install', () => {
let session: TestSession;
before(async () => {
session = await TestSession.create({
setupCommands: ['sfdx force:org:create -d 1 -s -f config/project-scratch-def.json'],
project: { name: 'packageInstall' },
});
});

after(async () => {
await session?.clean();
});

it('should install ElectronBranding package with polling', function () {
const command = 'force:package:beta:install -p 04t6A000002zgKSQAY -w 10';
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
expect(output).to.contain('Successfully installed package');
});

it('should install DFXP Escape Room package (async) and report', function () {
const installCommand = 'force:package:beta:install -p 04t6A000002zgKSQAY --json';
const installJson = execCmd<PackageInstallRequest>(installCommand, { ensureExitCode: 0 }).jsonOutput.result;
expect(installJson).to.have.property('Status', 'IN_PROGRESS');

const reportCommand = `force:package:beta:install:report -i ${installJson.Id} --json`;
const reportJson = execCmd<PackageInstallRequest>(reportCommand, { ensureExitCode: 0 }).jsonOutput.result;
expect(reportJson).to.have.property('Status', 'IN_PROGRESS');
});
});
Loading

0 comments on commit 24dbd52

Please sign in to comment.