Skip to content

Commit

Permalink
Merge pull request #14 from forcedotcom/wr/packageInstalledList
Browse files Browse the repository at this point in the history
Wr/package installed list
  • Loading branch information
mshanemc authored Aug 10, 2022
2 parents a407029 + 56c73be commit 57a2a1d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"devDependencies": {
"@salesforce/cli-plugins-testkit": "^2.3.4",
"@salesforce/dev-config": "^3.0.1",
"@salesforce/dev-scripts": "^2.0.2",
"@salesforce/dev-scripts": "^2.0.4",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "^1.3.21",
"@types/debug": "4.1.7",
Expand All @@ -80,7 +80,7 @@
"pretty-quick": "^3.1.3",
"shelljs": "0.8.5",
"sinon": "14.0.0",
"ts-node": "^10.8.1",
"ts-node": "^10.9.1",
"typescript": "4.6.4"
},
"repository": "forcedotcom/packaging",
Expand Down
10 changes: 10 additions & 0 deletions src/interfaces/packagingInterfacesAndType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PackageProfileApi } from '../package/packageProfileApi';
import { PackagingSObjects } from './packagingSObjects';
import Package2VersionStatus = PackagingSObjects.Package2VersionStatus;
import PackageInstallRequest = PackagingSObjects.PackageInstallRequest;
import MetadataPackageVersion = PackagingSObjects.MetadataPackageVersion;

export interface IPackage {
create(): Promise<void>;
Expand Down Expand Up @@ -280,3 +281,12 @@ export type Package1VersionCreateRequest = Pick<PackagingSObjects.PackageUploadR
| 'Password'
>
>;

export type InstalledPackages = {
Id: string;
SubscriberPackageId: string;
SubscriberPackageVersionId: string;
MinPackageVersionId: string;
SubscriberPackage?: PackagingSObjects.SubscriberPackage;
SubscriberPackageVersion?: Omit<MetadataPackageVersion, 'MetadataPackageId' | 'ReleaseState' | 'IsDeprecated'>;
};
1 change: 1 addition & 0 deletions src/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export { listPackageVersions } from './packageVersionList';
export { createPackage } from './packageCreate';
export { deletePackage } from './packageDelete';
export { uninstallPackage } from './packageUninstall';
export * from './packageInstalledList';
14 changes: 14 additions & 0 deletions src/package/packageInstalledList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2020, 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 { Connection } from '@salesforce/core';
import { InstalledPackages } from '../interfaces';

export async function packageInstalledList(conn: Connection): Promise<InstalledPackages[]> {
const query =
'SELECT Id, SubscriberPackageId, SubscriberPackage.NamespacePrefix, SubscriberPackage.Name, SubscriberPackageVersion.Id, SubscriberPackageVersion.Name, SubscriberPackageVersion.MajorVersion, SubscriberPackageVersion.MinorVersion, SubscriberPackageVersion.PatchVersion, SubscriberPackageVersion.BuildNumber FROM InstalledSubscriberPackage ORDER BY SubscriberPackageId';
return (await conn.tooling.query<InstalledPackages>(query)).records;
}
24 changes: 17 additions & 7 deletions test/package/packageTest.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {
PackageVersionCreateReportProgress,
PackageVersionCreateRequestResultInProgressStatuses,
} from '../../src/interfaces';
import { createPackage, uninstallPackage } from '../../src/package';
import { createPackage } from '../../src/package';
import { uninstallPackage } from '../../src/package';
import { packageInstalledList } from '../../src/package';
import { deletePackage } from '../../src/package';
import { PackageVersion } from '../../src/package';
import { Package } from '../../src/package';
Expand Down Expand Up @@ -254,7 +256,7 @@ describe('Integration tests for #salesforce/packaging library', function () {
expect(pollResult).to.have.property('Errors', null);
expect(pollResult).to.have.property('SubscriberPackageVersionKey', subscriberPkgVersionId);

if (pollResult.Status === 'IN_PROGRESS' && counter < 40) {
if (pollResult.Status === 'IN_PROGRESS' && counter < 80) {
return sleep(WAIT_INTERVAL_MS, Duration.Unit.MILLISECONDS).then(() =>
waitForInstallRequestAndValidate(counter++)
);
Expand All @@ -271,15 +273,23 @@ describe('Integration tests for #salesforce/packaging library', function () {
expect(result.Status).to.equal('SUCCESS');
});

it('run force:package:installed:list to verify in target scratch org', () => {
const result = execCmd<[{ SubscriberPackageVersionId: string }]>(
`force:package:installed:list --json --targetusername ${SUB_ORG_ALIAS}`
).jsonOutput.result;
it('packageInstalledList returns the correct information', async () => {
const connection = scratchOrg.getConnection();
const result = await packageInstalledList(connection);
const foundRecord = result.filter((item) => item.SubscriberPackageVersion.Id === subscriberPkgVersionId);

expect(result).to.have.length.at.least(1);
const foundRecord = result.filter((item) => item.SubscriberPackageVersionId === subscriberPkgVersionId);
expect(foundRecord, `Did not find SubscriberPackageVersionId ${subscriberPkgVersionId}`).to.have.length(1);
expect(foundRecord[0]).to.have.property('Id');
expect(foundRecord[0]).to.have.property('SubscriberPackageId');
expect(foundRecord[0].SubscriberPackage).to.have.property('Name');
expect(foundRecord[0].SubscriberPackage).to.have.property('NamespacePrefix');
expect(foundRecord[0].SubscriberPackageVersion).to.have.property('Id');
expect(foundRecord[0].SubscriberPackageVersion).to.have.property('Name');
expect(foundRecord[0].SubscriberPackageVersion).to.have.property('MajorVersion');
expect(foundRecord[0].SubscriberPackageVersion).to.have.property('MinorVersion');
expect(foundRecord[0].SubscriberPackageVersion).to.have.property('PatchVersion');
expect(foundRecord[0].SubscriberPackageVersion).to.have.property('BuildNumber');
});
});

Expand Down
11 changes: 3 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@
resolved "https://registry.yarnpkg.com/@salesforce/dev-config/-/dev-config-3.1.0.tgz#8eb5b35860ff60d1c1dc3fd9329b01a28475d5b9"
integrity sha512-cPph7ibj3DeSzWDFLcLtxOh5fmUlDUY2Ezq43n0V6auVP+l8orxRHjCExHS86SB3QKVgXkC8yYhryXiS8KF7Zw==

"@salesforce/dev-scripts@^2.0.2":
"@salesforce/dev-scripts@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@salesforce/dev-scripts/-/dev-scripts-2.0.4.tgz#d37e16c772075c2745c3c1f20dbd384fab194953"
integrity sha512-iZgY4Us+7/q3X/qM5YiTE4mqpFum2uPI9tvHGqxA4py/bR1jPIelZR9a4EuFoW43isUvIXm2TpdUA3V/UBa23Q==
Expand Down Expand Up @@ -793,12 +793,7 @@
resolved "https://registry.yarnpkg.com/@salesforce/prettier-config/-/prettier-config-0.0.2.tgz#ded39bf7cb75238edc9db6dd093649111350f8bc"
integrity sha512-KExM355BLbxCW6siGBV7oUOotXvvVp0tAWERgzUkM2FcMb9fWrjwXDrIHc8V0UdDlA3UXtFltDWgN+Yqi+BA/g==

"@salesforce/schemas@^1.1.0":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.1.3.tgz#fce83f55c7557d47b9c814d5d02978ad734300b3"
integrity sha512-XWohlOT2oQDqAJH00OXS3f2MGjkwZ6pr4emnnkHSQbg7UdGW0rvGpEnRKqBbDUfZ4K5YKSo9Gj216ZtaP3JLXg==

"@salesforce/schemas@^1.2.0":
"@salesforce/schemas@^1.1.0", "@salesforce/schemas@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.2.0.tgz#3c7ed492e3ee5d9d9fb24a32b5c574893f6648db"
integrity sha512-76oYf/9Rsn6Yl+awrTQvLaQuRDNX7F3X9ksRiw53OCJdydIF05buX6XLzN0WDWpkCg/asw+lZMuAzbDVS0tBmg==
Expand Down Expand Up @@ -6108,7 +6103,7 @@ trim-newlines@^3.0.0:
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144"
integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==

ts-node@^10.0.0, ts-node@^10.8.1:
ts-node@^10.0.0, ts-node@^10.8.1, ts-node@^10.9.1:
version "10.9.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b"
integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==
Expand Down

0 comments on commit 57a2a1d

Please sign in to comment.