Skip to content

Commit 80ade7b

Browse files
fix: add package:beta:update, NUT
1 parent fdbaef4 commit 80ade7b

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

messages/package_update.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ new package description
3535

3636
New description of the package.
3737

38-
# humanSuccess
38+
# success
3939

40-
Successfully updated the package.
40+
Successfully updated the package. %s

src/commands/force/package/beta/update.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import * as os from 'os';
99
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
1010
import { Messages } from '@salesforce/core';
11+
import { BY_LABEL, getPackageIdFromAlias, Package, PackageSaveResult, validateId } from '@salesforce/packaging';
1112

1213
Messages.importMessagesDirectory(__dirname);
1314
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_update');
@@ -42,8 +43,20 @@ export class PackageUpdateCommand extends SfdxCommand {
4243
}),
4344
};
4445

45-
// eslint-disable-next-line @typescript-eslint/require-await
46-
public async run(): Promise<unknown> {
47-
throw new Error('Beta command not yet implemented');
46+
public async run(): Promise<PackageSaveResult> {
47+
const pkg = new Package({ connection: this.hubOrg.getConnection() });
48+
const id = getPackageIdFromAlias(this.flags.package, this.project);
49+
validateId(BY_LABEL.PACKAGE_ID, id);
50+
51+
const result = await pkg.update({
52+
Id: id,
53+
Name: this.flags.name as string,
54+
Description: this.flags.description as string,
55+
PackageErrorUsername: this.flags.errornotificationusername as string,
56+
});
57+
58+
this.ux.log(messages.getMessage('success', [id]));
59+
60+
return result;
4861
}
4962
}

test/commands/force/package/packageCreateAndDelete.nut.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
1010
import { OrgConfigProperties } from '@salesforce/core';
1111
import { expect } from 'chai';
1212

13-
describe('package create and delete', () => {
13+
describe('package create/update/delete', () => {
1414
let session: TestSession;
1515
let devHubUsernameOrAlias: string;
1616
let pkgName: string;
@@ -29,7 +29,7 @@ describe('package create and delete', () => {
2929
after(async () => {
3030
await session?.clean();
3131
});
32-
describe('create/delete - human results', () => {
32+
describe('create/update/delete - human results', () => {
3333
before(async () => {
3434
pkgName = `test-pkg-${Date.now()}`;
3535
});
@@ -40,14 +40,20 @@ describe('package create and delete', () => {
4040
expect(output).to.contain('=== Ids');
4141
expect(output).to.match(/Package Id\s+?0Ho/);
4242
});
43+
it('should update a package - human readable results', function () {
44+
const command = `force:package:beta:update --package ${pkgName} --description "My new description" -v ${devHubUsernameOrAlias}`;
45+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
46+
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
47+
expect(output).to.match(/Successfully updated the package\.\s+0Ho/);
48+
});
4349
it('should delete a package - human readable results', function () {
4450
const command = `force:package:beta:delete -p ${pkgName} -v ${devHubUsernameOrAlias} --noprompt`;
4551
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4652
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
4753
expect(output).to.contain('Successfully deleted the package. 0Ho');
4854
});
4955
});
50-
describe('create/delete - json results', () => {
56+
describe('create/update/delete - json results', () => {
5157
before(async () => {
5258
pkgName = `test-pkg-${Date.now()}`;
5359
});
@@ -59,6 +65,14 @@ describe('package create and delete', () => {
5965
expect(output.result).to.have.property('Id');
6066
expect(output.result.Id).to.match(/0Ho.{12,15}/);
6167
});
68+
it('should update a package - json results', function () {
69+
const command = `force:package:beta:update --package ${pkgName} --description "My new description" -v ${devHubUsernameOrAlias} --json`;
70+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
71+
const output = execCmd<{ id: string }>(command, { ensureExitCode: 0 }).jsonOutput;
72+
expect(output.status).to.equal(0);
73+
expect(output.result).to.have.property('id');
74+
expect(output.result.id).to.match(/0Ho.{12,15}/);
75+
});
6276
it('should delete a package - json results', function () {
6377
const command = `force:package:beta:delete -p ${pkgName} -v ${devHubUsernameOrAlias} --json`;
6478
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access

0 commit comments

Comments
 (0)