diff --git a/src/package/packageVersionList.ts b/src/package/packageVersionList.ts index b5afb5701..6b4fd0381 100644 --- a/src/package/packageVersionList.ts +++ b/src/package/packageVersionList.ts @@ -37,16 +37,13 @@ const defaultFields = [ 'ValidationSkipped', 'CreatedById', 'ConvertedFromVersionId', -]; - -const verboseFields = [ - 'CodeCoverage', - 'HasPassedCodeCoverageCheck', 'ReleaseVersion', 'BuildDurationInSeconds', 'HasMetadataRemoved', ]; +const verboseFields = ['CodeCoverage', 'HasPassedCodeCoverageCheck']; + const verbose57Fields = ['Language']; export const DEFAULT_ORDER_BY_FIELDS = 'Package2Id, Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber'; @@ -74,7 +71,7 @@ export async function listPackageVersions( return connection.autoFetchQuery(query, { tooling: true }); } -function constructQuery(connectionVersion: number, options?: PackageVersionListOptions): string { +export function constructQuery(connectionVersion: number, options?: PackageVersionListOptions): string { // construct custom WHERE clause, if applicable const where = constructWhere(options); diff --git a/src/package/packageVersionReport.ts b/src/package/packageVersionReport.ts index f56b154a1..248109fef 100644 --- a/src/package/packageVersionReport.ts +++ b/src/package/packageVersionReport.ts @@ -14,16 +14,16 @@ import * as pkgUtils from '../utils/packageUtils'; import { PackageVersionReportResult } from '../interfaces'; const QUERY = - 'SELECT Package2Id, SubscriberPackageVersionId, Name, Description, Tag, Branch, AncestorId, ValidationSkipped, ' + + 'SELECT Id, Package2Id, SubscriberPackageVersionId, Name, Description, Tag, Branch, AncestorId, ValidationSkipped, ' + 'MajorVersion, MinorVersion, PatchVersion, BuildNumber, IsReleased, CodeCoverage, HasPassedCodeCoverageCheck, ' + 'Package2.IsOrgDependent, ReleaseVersion, BuildDurationInSeconds, HasMetadataRemoved, CreatedById, ConvertedFromVersionId ' + 'FROM Package2Version ' + "WHERE Id = '%s' AND IsDeprecated != true " + 'ORDER BY Package2Id, Branch, MajorVersion, MinorVersion, PatchVersion, BuildNumber'; -// verbose adds: Id, ConvertedFromVersionId, SubscriberPackageVersion.Dependencies +// verbose adds: ConvertedFromVersionId, SubscriberPackageVersion.Dependencies const QUERY_VERBOSE = - 'SELECT Id, Package2Id, SubscriberPackageVersionId, Name, Description, Tag, Branch, AncestorId, ValidationSkipped, ' + + 'SELECT Package2Id, SubscriberPackageVersionId, Name, Description, Tag, Branch, AncestorId, ValidationSkipped, ' + 'MajorVersion, MinorVersion, PatchVersion, BuildNumber, IsReleased, CodeCoverage, HasPassedCodeCoverageCheck, ConvertedFromVersionId, ' + 'Package2.IsOrgDependent, ReleaseVersion, BuildDurationInSeconds, HasMetadataRemoved, SubscriberPackageVersion.Dependencies, ' + 'CreatedById, CodeCoveragePercentages ' + diff --git a/test/package/packageTest.nut.ts b/test/package/packageTest.nut.ts index 1eae9f045..b11ca349f 100644 --- a/test/package/packageTest.nut.ts +++ b/test/package/packageTest.nut.ts @@ -105,6 +105,8 @@ describe('Integration tests for @salesforce/packaging library', () => { }); describe('create package/package version, report on pvc, update package/promote package', () => { + // An abbreviated list of the default keys that should be on a package version entry + const expectedVersionListKeys = ['Id', 'Package2Id', 'SubscriberPackageVersionId', 'Name', 'Package2']; it('package create', async () => { const options: PackageCreateOptions = { name: pkgName, @@ -265,7 +267,27 @@ describe('Integration tests for @salesforce/packaging library', () => { it('package version should be in results of static Package#listVersions', async () => { const pkgVersions = await Package.listVersions(devHubOrg.getConnection(), project, { createdLastDays: 5 }); + expect(pkgVersions.length).to.be.greaterThan(0); expect(pkgVersions.some((pvlr) => pvlr.SubscriberPackageVersionId === subscriberPkgVersionId)).to.be.true; + const pkgVersion = pkgVersions[0]; + // expect some of the default keys + expect(pkgVersion).to.include.keys(expectedVersionListKeys); + expect(pkgVersion).to.not.have.property('CodeCoverage'); + expect(pkgVersion).to.not.have.property('HasPassedCodeCoverageCheck'); + }); + + it('package version should include CodeCoverage in results of static Package#listVersions for verbose query', async () => { + const pkgVersions = await Package.listVersions(devHubOrg.getConnection(), project, { + createdLastDays: 5, + verbose: true, + }); + expect(pkgVersions.length).to.be.greaterThan(0); + expect(pkgVersions.some((pvlr) => pvlr.SubscriberPackageVersionId === subscriberPkgVersionId)).to.be.true; + const pkgVersion = pkgVersions[0]; + // expect some of the default keys + expect(pkgVersion).to.include.keys(expectedVersionListKeys); + expect(pkgVersion).to.have.property('CodeCoverage'); + expect(pkgVersion).to.have.property('HasPassedCodeCoverageCheck'); }); it('package version report', async () => { @@ -276,7 +298,7 @@ describe('Integration tests for @salesforce/packaging library', () => { }); const result = await pv.report(); - expect(result).to.not.have.property('Id'); + expect(result).to.have.property('Id'); expect(result.Package2Id).to.equal( pkgId, `Package Version Report Package Id mismatch: expected '${pkgId}', got '${result.Package2Id}'` diff --git a/test/package/packageVersionList.test.ts b/test/package/packageVersionList.test.ts index 7ae64146c..c7e78c954 100644 --- a/test/package/packageVersionList.test.ts +++ b/test/package/packageVersionList.test.ts @@ -12,6 +12,7 @@ import { constructWhere, DEFAULT_ORDER_BY_FIELDS, validateDays, + constructQuery, } from '../../src/package/packageVersionList'; describe('package version list', () => { @@ -75,6 +76,50 @@ describe('package version list', () => { expect(where).to.include('LastModifiedDate = LAST_N_DAYS:2'); }); }); + + describe('_constructQuery', () => { + it('should include verbose fields', async () => { + const options = { + packages: ['0Ho3h000000xxxxCAG'], + createdLastDays: 1, + modifiedLastDays: 2, + isReleased: true, + verbose: true, + }; + const constQuery = constructQuery(50, options); + expect(constQuery).to.include('CodeCoverage'); + expect(constQuery).to.include('HasPassedCodeCoverageCheck'); + expect(constQuery).to.not.include('Language'); + }); + + it('should include verbose fields with langage', async () => { + const options = { + packages: ['0Ho3h000000xxxxCAG'], + createdLastDays: 1, + modifiedLastDays: 2, + isReleased: true, + verbose: true, + }; + const constQuery = constructQuery(59, options); + expect(constQuery).to.include('CodeCoverage'); + expect(constQuery).to.include('HasPassedCodeCoverageCheck'); + expect(constQuery).to.include('Language'); + }); + + it('should not include verbose fields', async () => { + const options = { + packages: ['0Ho3h000000xxxxCAG'], + createdLastDays: 1, + modifiedLastDays: 2, + isReleased: true, + }; + const constQuery = constructQuery(59, options); + expect(constQuery).to.not.include('CodeCoverage'); + expect(constQuery).to.not.include('HasPassedCodeCoverageCheck'); + expect(constQuery).to.not.include('Language'); + }); + }); + describe('_assembleQueryParts', () => { it('should return the proper query', () => { const assembly = assembleQueryParts('select foo,bar,baz from foobarbaz', ['foo=1', "bar='2'"], 'foo,bar,baz');