Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly chunk query for getPackageVersionStrings #277

Merged
merged 3 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/utils/packageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,8 @@ export async function getPackageVersionStrings(
// remove any duplicate Ids
const ids = [...new Set<string>(subscriberPackageVersionIds)];

const query = `SELECT SubscriberPackageVersionId, MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE SubscriberPackageVersionId IN (${ids
.map((id) => `'${id}'`)
.join(',')})`;
const query =
"SELECT SubscriberPackageVersionId, MajorVersion, MinorVersion, PatchVersion, BuildNumber FROM Package2Version WHERE SubscriberPackageVersionId IN ('%IDS%')";

const records = await queryWithInConditionChunking<PackageVersionString>(query, ids, '%IDS%', connection);
if (records && records.length > 0) {
Expand Down
21 changes: 19 additions & 2 deletions test/utils/packageUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { assert, expect } from 'chai';
import { instantiateContext, restoreContext, stubContext } from '@salesforce/core/lib/testSetup';
import { instantiateContext, MockTestOrgData, restoreContext, stubContext } from '@salesforce/core/lib/testSetup';
import { SaveError } from 'jsforce';
import { Duration } from '@salesforce/kit';
import * as JSZIP from 'jszip';
import {
applyErrorAction,
getPackageVersionNumber,
getPackageVersionStrings,
massageErrorMessage,
combineSaveErrors,
zipDir,
Expand All @@ -25,6 +26,7 @@ import { PackagingSObjects } from '../../src/interfaces';

describe('packageUtils', () => {
const $$ = instantiateContext();
const testOrg = new MockTestOrgData();

beforeEach(() => {
stubContext($$);
Expand Down Expand Up @@ -67,7 +69,22 @@ describe('packageUtils', () => {
});
});
describe('getPackageVersionStrings', () => {
it.skip('should return the correct version strings', () => {});
it('should chunk a large query', async () => {
const conn = await testOrg.getConnection();
const queryStub = $$.SANDBOX.stub(conn.tooling, 'query').resolves({
records: [{ MajorVersion: 1 }],
done: true,
totalSize: 1,
});

// generate a large array of fake subscriber package version IDs
const spvs: string[] = [];
while (spvs.length < 201) {
spvs.push($$.uniqid());
}
mshanemc marked this conversation as resolved.
Show resolved Hide resolved
await getPackageVersionStrings(spvs, conn);
expect(queryStub.callCount).to.equal(2);
});
});
describe('getContainerOptions', () => {
it.skip('should return the correct value', () => {});
Expand Down