Skip to content

Commit

Permalink
fix: add package:version:create:list command, NUT
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Aug 30, 2022
1 parent 1398c77 commit 5a4e558
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 122 deletions.
4 changes: 4 additions & 0 deletions messages/package_version_create_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ Tag
# installUrl

Installation URL

# createdBy

Created By
42 changes: 39 additions & 3 deletions src/commands/force/package/beta/version/create/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import * as os from 'os';
import { flags, FlagsConfig, SfdxCommand } from '@salesforce/command';
import { Messages } from '@salesforce/core';
import { PackageVersion, PackageVersionCreateRequestResult } from '@salesforce/packaging';
import * as chalk from 'chalk';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_create_list');
Expand All @@ -31,8 +33,42 @@ export class PackageVersionCreateListCommand extends SfdxCommand {
}),
};

// eslint-disable-next-line @typescript-eslint/require-await
public async run(): Promise<never> {
throw new Error('Beta command not yet implemented');
public async run(): Promise<PackageVersionCreateRequestResult[]> {
const pv = new PackageVersion({ connection: this.hubOrg.getConnection(), project: undefined });
const results = await pv.createdList({ ...this.flags });

if (results.length === 0) {
this.ux.log('No results found');
} else {
this.ux.styledHeader(chalk.blue(`Package Version Create Requests [${results.length}]`));
const columnData = {
Id: {},
Status: {
header: messages.getMessage('status'),
},
Package2Id: {
header: messages.getMessage('packageId'),
},
Package2VersionId: {
header: messages.getMessage('packageVersionId'),
},
SubscriberPackageVersionId: {
header: messages.getMessage('subscriberPackageVersionId'),
},
Tag: {
header: messages.getMessage('tag'),
},
Branch: {
header: messages.getMessage('branch'),
},
CreatedDate: { header: 'Created Date' },
CreatedBy: {
header: messages.getMessage('createdBy'),
},
};
this.ux.table(results, columnData, { 'no-truncate': true });
}

return results;
}
}
167 changes: 167 additions & 0 deletions test/commands/force/package/packageVersion.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* 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';

describe('package:version:create:*', () => {
let session: TestSession;
let usernameOrAlias: string;
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: 'packageVersionList' },
});
// 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();
});
describe('package:version:create:list', () => {
it('should list the package versions created (human)', async () => {
const command = `force:package:beta:version:create:list -v ${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('=== Package Version Create Requests [');
expect(output).to.match(
/ Id\s+Status\s+Package Id\s+Package Version Id\s+Subscriber Package Version Id\s+Tag\s+Branch\s+Created Date\s+Created By\s+/
);
});

it('should list all of the successful package versions created', async () => {
const command = `force:package:beta:version:create:list --status Success -v ${usernameOrAlias} --json`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd<[{ Status: string }]>(command, { ensureExitCode: 0 }).jsonOutput;
output.result.forEach((result) => {
expect(result.Status).to.equal('Success');
});
});

it('should list the package versions created (json)', async () => {
const command = `force:package:beta:version:create:list -v ${usernameOrAlias} --json`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).jsonOutput as {
status: number;
result: { [key: string]: unknown };
};
const keys = [
'Id',
'Status',
'Package2Id',
'Package2VersionId',
'SubscriberPackageVersionId',
'Tag',
'Branch',
'Error',
'CreatedDate',
'HasMetadataRemoved',
'CreatedBy',
];
expect(output).to.be.ok;
expect(output.status).to.equal(0);
expect(output.result).to.have.length.greaterThan(0);
expect(output.result[0]).to.have.keys(keys);
});
});
describe('package:version:list', () => {
it('should list package versions in dev hub - human readable results', () => {
const command = `force:package:beta:version:list -v ${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('=== Package Versions [');
expect(output).to.match(
/Package Name\s+Namespace\s+Version Name\s+Version\s+Subscriber Package Version Id\sAlias\s+Installation Key\s+Released\s+Validation Skipped\s+Ancestor\s+Ancestor Version\s+Branch/
);
});

it('should list package versions in dev hub - concise output', () => {
const command = `force:package:beta:version:list -v ${usernameOrAlias} --concise`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
expect(output).to.contain('=== Package Versions [');
expect(output).to.match(/Package Id\s+Version\s+Subscriber Package Version Id\s+Released/);
});

it('should list package versions modified in the last 5 days', () => {
const command = `force:package:beta:version:list -v ${usernameOrAlias} --modifiedlastdays 5`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
expect(output).to.contain('=== Package Versions [');
expect(output).to.match(
/Package Name\s+Namespace\s+Version Name\s+Version\s+Subscriber Package Version Id\sAlias\s+Installation Key\s+Released\s+Validation Skipped\s+Ancestor\s+Ancestor Version\s+Branch/
);
});
it('should list package versions created in the last 5 days', () => {
const command = `force:package:beta:version:list -v ${usernameOrAlias} --createdlastdays 5`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
expect(output).to.contain('=== Package Versions [');
expect(output).to.match(
/Package Name\s+Namespace\s+Version Name\s+Version\s+Subscriber Package Version Id\sAlias\s+Installation Key\s+Released\s+Validation Skipped\s+Ancestor\s+Ancestor Version\s+Branch/
);
});
it('should list installed packages in dev hub - verbose human readable results', () => {
const command = `force:package:beta:version:list -v ${usernameOrAlias} --verbose`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).shellOutput.stdout as string;
expect(output).to.contain('=== Package Versions [');
expect(output).to.match(
/Package Name\s+Namespace\s+Version Name\s+Version\s+Subscriber Package Version Id\sAlias\s+Installation Key\s+Released\s+Validation Skipped\s+Ancestor\s+Ancestor Version\s+Branch\s+Package Id\s+Installation URL\s+Package Version Id\s+Created Date\s+Last Modified Date\s+Tag\s+Description\s+Code Coverage\s+Code Coverage Met\s+Converted From Version Id\s+Org-Dependent\s+Unlocked Package\s+Release\s+Version\s+Build Duration in Seconds\s+Managed Metadata Removed\s+Created By/
);
});
it('should list package versions in dev hub - json results', () => {
const command = `force:package:beta:version:list -v ${usernameOrAlias} --json`;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const output = execCmd(command, { ensureExitCode: 0 }).jsonOutput as {
status: number;
result: { [key: string]: unknown };
};
const keys = [
'Package2Id',
'Branch',
'Tag',
'MajorVersion',
'MinorVersion',
'PatchVersion',
'BuildNumber',
'Id',
'SubscriberPackageVersionId',
'Name',
'NamespacePrefix',
'Package2Name',
'Description',
'Version',
'IsPasswordProtected',
'IsReleased',
'CreatedDate',
'LastModifiedDate',
'InstallUrl',
'CodeCoverage',
'ValidationSkipped',
'AncestorId',
'AncestorVersion',
'Alias',
'IsOrgDependent',
'ReleaseVersion',
'BuildDurationInSeconds',
'HasMetadataRemoved',
'CreatedBy',
];
expect(output).to.be.ok;
expect(output.status).to.equal(0);
expect(output.result).to.have.length.greaterThan(0);
expect(output.result[0]).to.have.keys(keys);
});
});
});
119 changes: 0 additions & 119 deletions test/commands/force/package/packageVersionList.nut.ts

This file was deleted.

0 comments on commit 5a4e558

Please sign in to comment.