Skip to content

Commit

Permalink
fix: add package:beta:version:update and NUT
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Aug 25, 2022
1 parent ceb8d55 commit 1ac77a8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
2 changes: 1 addition & 1 deletion messages/package_version_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ new installation key for key-protected package (default: null)

The new installation key for the key-protected package. The default is null.

# humanSuccess
# success

Successfully updated the package version.

Expand Down
18 changes: 15 additions & 3 deletions src/commands/force/package/beta/version/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import * as os from 'os';
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { getPackageIdFromAlias, PackageSaveResult, PackageVersion } from '@salesforce/packaging';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_update');
Expand Down Expand Up @@ -51,8 +52,19 @@ export class PackageVersionUpdateCommand extends SfdxCommand {
}),
};

public async run(): Promise<unknown> {
process.exitCode = 1;
return Promise.resolve('Not yet implemented');
public async run(): Promise<PackageSaveResult> {
const pv = new PackageVersion({ connection: this.hubOrg.getConnection(), project: this.project });
const id = getPackageIdFromAlias(this.flags.package, this.project);
const result = await pv.update(id, {
VersionDescription: this.flags.versiondescription,
Branch: this.flags.branch,
InstallKey: this.flags.installationkey,
VersionName: this.flags.versionname,
Tag: this.flags.tag,
});

this.ux.log(messages.getMessage('success', [result.id]));

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

import { execCmd, genUniqueString, TestSession } from '@salesforce/cli-plugins-testkit';
import { expect } from 'chai';
import { getPackageIdFromAlias, PackageSaveResult } from '@salesforce/packaging';
import { SfProject } from '@salesforce/core';
// TODO: enable once `package:beta:version:create` is released
describe.skip('package:version:promote', () => {
import { PackageSaveResult } from '@salesforce/packaging';

describe('package:version:promote / package:version:update', () => {
let session: TestSession;
let packageId: string;
const pkgName = genUniqueString('dancingbears-');
Expand All @@ -24,12 +23,10 @@ describe.skip('package:version:promote', () => {
`force:package:beta:create --name ${pkgName} --packagetype Unlocked --path force-app --description "Don't ease, don't ease, don't ease me in."`,
{ ensureExitCode: 0 }
);
// TODO: requires this command
execCmd(
`force:package:beta:version:create --package ${pkgName} --version 1.0.0 --codecoverage --description "Initial version"`,
packageId = execCmd<{ SubscriberPackageVersionId: string }>(
`force:package:beta:version:create --package ${pkgName} -w 10 -x --json --codecoverage --versiondescription "Initial version"`,
{ ensureExitCode: 0 }
);
packageId = getPackageIdFromAlias(pkgName, SfProject.getInstance());
).jsonOutput.result.SubscriberPackageVersionId;
});

after(async () => {
Expand All @@ -38,23 +35,45 @@ describe.skip('package:version:promote', () => {

it('should promote a package (human readable)', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const result = execCmd(`force:package:beta:version:promote --package ${pkgName} --noprompt`, { ensureExitCode: 0 })
.shellOutput.stdout as string;
const result = execCmd(`force:package:beta:version:promote --package ${packageId} --noprompt`, {
ensureExitCode: 0,
}).shellOutput.stdout as string;
expect(result).to.contain(
`Successfully promoted the package version, ID: ${packageId}, to released. Starting in Winter ‘21, only unlocked package versions that have met the minimum 75% code coverage requirement can be promoted. Code coverage minimums aren’t enforced on org-dependent unlocked packages.`
);
});

it('should promote a package (--json)', () => {
const result = execCmd<PackageSaveResult>(
`force:package:beta:version:promote --package ${pkgName} --noprompt --json`,
`force:package:beta:version:promote --package ${packageId} --noprompt --json`,
{
ensureExitCode: 0,
}
).jsonOutput.result;
expect(result).to.have.all.keys('id', 'success', 'errors');
expect(result.id).to.equal(packageId);
expect(result.success).to.equal(true);
expect(result.errors).to.deep.equal([]);
});

it('should update a package (human readable)', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const result = execCmd(`force:package:beta:version:update --package ${packageId} --branch MySuperCoolBranch`, {
ensureExitCode: 0,
}).shellOutput.stdout as string;
expect(result).to.contain(`Successfully updated the package version. ${packageId}`);
});

it('should update a package (--json)', () => {
const result = execCmd<PackageSaveResult>(
`force:package:beta:version:update --package ${packageId} --branch MySuperCoolBranch2 --json`,
{
ensureExitCode: 0,
}
).jsonOutput.result;
expect(result).to.have.all.keys('id', 'success', 'errors');
expect(result.id).to.equal(packageId);
expect(result.success).to.equal(true);
expect(result.errors).to.equal([]);
expect(result.errors).to.deep.equal([]);
});
});

0 comments on commit 1ac77a8

Please sign in to comment.