Skip to content

Commit

Permalink
Merge pull request #548 from forcedotcom/ma/less-verbose-fields
Browse files Browse the repository at this point in the history
fix: move verbose field to default fields
  • Loading branch information
shetzel authored Apr 18, 2024
2 parents 3c79c0f + 21ad423 commit 3d8d443
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 10 deletions.
9 changes: 3 additions & 6 deletions src/package/packageVersionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,7 +71,7 @@ export async function listPackageVersions(
return connection.autoFetchQuery<PackageVersionListResult & Schema>(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);

Expand Down
6 changes: 3 additions & 3 deletions src/package/packageVersionReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' +
Expand Down
24 changes: 23 additions & 1 deletion test/package/packageTest.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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}'`
Expand Down
45 changes: 45 additions & 0 deletions test/package/packageVersionList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
constructWhere,
DEFAULT_ORDER_BY_FIELDS,
validateDays,
constructQuery,
} from '../../src/package/packageVersionList';

describe('package version list', () => {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 3d8d443

Please sign in to comment.