Skip to content

Commit

Permalink
feat: add package1:version:display command, NUT, pruned messages
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Jul 6, 2022
1 parent 7389687 commit 23e0c8e
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 19 deletions.
16 changes: 4 additions & 12 deletions messages/package1_version_display.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# longDescription

Displays detailed information about an individual first-generation package version.

# cliDescription
# description

display details about a first-generation package version

# cliHelp
# help

Display detailed information about an individual package version, including metadata package ID, name, the release state, and build number.

Expand All @@ -18,10 +14,6 @@ metadata package version ID (starts with 04t)

ID (starts with 04t) of the metadata package version whose details you want to display.

# humanSuccess

Successfully displayed the package version.

# action
# packageIdInvalid

Verify that you entered a valid package version ID and try again.
Verify that you entered a valid package version ID (starts with 04t) and try again.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"test:command-reference": "./bin/run commandreference:generate --erroronwarnings",
"test:deprecation-policy": "./bin/run snapshot:compare",
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"test:nuts:package1": "nyc mocha \"**/package1/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
"version": "oclif readme"
},
"publishConfig": {
Expand Down
39 changes: 32 additions & 7 deletions src/commands/force/package1/beta/version/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
*/

import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { Messages, SfError } from '@salesforce/core';
import { Package1Display, package1Display } from '@salesforce/packaging';
import { CliUx } from '@oclif/core';

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

export class Package1VersionDisplayCommand extends SfdxCommand {
public static readonly description = messages.getMessage('cliDescription');
public static readonly longDescription = messages.getMessage('longDescription');
public static readonly help = messages.getMessage('cliHelp');
public static readonly description = messages.getMessage('description');
public static readonly help = messages.getMessage('help');
public static readonly requiresUsername = true;
public static readonly requiresProject = true;
public static readonly flagsConfig: FlagsConfig = {
Expand All @@ -23,11 +24,35 @@ export class Package1VersionDisplayCommand extends SfdxCommand {
description: messages.getMessage('packageId'),
longDescription: messages.getMessage('packageIdLong'),
required: true,
validate: (id) => {
if (id.startsWith('04t') && id.length === 18) {
return true;
} else {
throw new SfError(messages.getMessage('packageIdInvalid'));
}
},
}),
};

public async run(): Promise<unknown> {
process.exitCode = 1;
return Promise.resolve('Not yet implemented');
public async run(): Promise<Package1Display[]> {
const conn = this.org.getConnection();
const results = await package1Display(conn, this.flags.packageversionid);

if (!this.flags.json) {
if (results.length === 0) {
CliUx.ux.log('No results found');
} else {
CliUx.ux.table(results, {
MetadataPackageVersionId: { header: 'MetadataPackageVersionId' },
MetadataPackageId: { header: 'MetadataPackageId' },
Name: { header: 'Name' },
Version: { header: 'Version' },
ReleaseState: { header: 'ReleaseState' },
BuildNumber: { header: 'BuildNumber' },
});
}
} else {
return results;
}
}
}
87 changes: 87 additions & 0 deletions test/commands/force/package1/versionDisplay.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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 * as path from 'path';
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit';
import { OrgConfigProperties } from '@salesforce/core';
import { expect } from 'chai';
import { Package1Display } from '../../../../../packaging';

describe('package1:version:display', () => {
let session: TestSession;
let usernameOrAlias: string;
// TODO: na40 required as DevHub
// hardcoded for now, eventually will be able to query from the org with package1:beta:version:list
const packageVersionId = '04t46000001ZfaAAAS';
before(async () => {
const executablePath = path.join(process.cwd(), 'bin', 'dev');
session = await TestSession.create({
setupCommands: [`${executablePath} config:get ${OrgConfigProperties.TARGET_DEV_HUB} --json`],
project: { name: 'package1VersionDisplay' },
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
usernameOrAlias = (session.setup[0] as { result: [{ value: string }] }).result[0].value;

if (!usernameOrAlias) throw Error('no default username set');
});

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

it('should list 1gp packages in dev hub - human readable results', function () {
const command = `force:package1:beta:version:display -i ${packageVersionId} -u ${usernameOrAlias}`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
expect(output).to.match(
/MetadataPackageVersionId\s+?MetadataPackageId\s+?Name\s+?Version\s+?ReleaseState\s+?BuildNumber/
);
});

it('should list 1gp packages in dev hub - human readable results - no results', function () {
// fake package ID
const command = `force:package1:beta:version:display -i 04t46000001ZfaXXXX -u ${usernameOrAlias}`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
expect(output).to.contain('No results found');
});

it('should validate packageversionid flag (too short)', function () {
// fake package ID - too short
const command = `force:package1:beta:version:display -i 04t46000001Zfa -u ${usernameOrAlias}`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 1 }).shellOutput.stderr as string;
expect(output).to.contain('Verify that you entered a valid package version ID (starts with 04t) and try again.');
});

it("should validate packageversionid flag (doesn't start with 04t)", function () {
// fake package ID - not an 04t package
const command = `force:package1:beta:version:display -i 05t46000001ZfaAAAS -u ${usernameOrAlias}`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 1 }).shellOutput.stderr as string;
expect(output).to.contain('Verify that you entered a valid package version ID (starts with 04t) and try again.');
});

it('should list 1gp packages in dev hub - json', function () {
const command = `force:package1:beta:version:display -i ${packageVersionId} -u ${usernameOrAlias} --json`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd<Package1Display[]>(command, { ensureExitCode: 0 }).jsonOutput.result[0];
expect(output).to.have.keys(
'MetadataPackageVersionId',
'MetadataPackageId',
'Name',
'Version',
'ReleaseState',
'BuildNumber'
);
expect(output.BuildNumber).to.be.a('number');
expect(output.ReleaseState).to.be.a('string');
expect(output.MetadataPackageVersionId).to.be.a('string');
expect(output.MetadataPackageId).to.be.a('string');
expect(output.Version).to.be.a('string');
});
});

0 comments on commit 23e0c8e

Please sign in to comment.