Skip to content

Commit

Permalink
feat: use StateAggregator (#646)
Browse files Browse the repository at this point in the history
* feat: use StateAggregator

* fix: use await

* chore: fix tests

* chore: auto-update metadata coverage in METADATA_SUPPORT.md

Co-authored-by: Eric Willhoit <[email protected]>
  • Loading branch information
mdonnalley and iowillhoit authored Jun 23, 2022
1 parent 123f51e commit f1d8848
Show file tree
Hide file tree
Showing 15 changed files with 557 additions and 569 deletions.
5 changes: 4 additions & 1 deletion METADATA_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ v56 introduces the following new types. Here's their current level of support

|Metadata Type|Support|Notes|
|:---|:---|:---|
|AccountingFieldMapping||Not supported, but support could be added|
|AccountingSettings|||
|BotBlock||Not supported, but support could be added|
|CollectionsDashboardSettings|||
Expand All @@ -518,16 +519,18 @@ v56 introduces the following new types. Here's their current level of support
|DataSourceBundleDefinition||Not supported, but support could be added|
|DataSrcDataModelFieldMap||Not supported, but support could be added|
|DataStreamTemplate||Not supported, but support could be added|
|ExperienceContainer||Not supported, but support could be added|
|ExplainabilityMsgActionDefinition||Not supported, but support could be added|
|ExpressionSetObjectAlias||Not supported, but support could be added|
|FuelType||Not supported, but support could be added|
|FuelTypeSustnUom||Not supported, but support could be added|
|IncludeEstTaxInQuoteSettings|||
|MfgServiceConsoleSettings|||
|OauthOidcSettings|||
|SearchExperience||Not supported, but support could be added|
|SearchExperienceField||Not supported, but support could be added|
|SearchExperienceObject||Not supported, but support could be added|
|SustainabilityUom||Not supported, but support could be added|
|SustnUomConversion||Not supported, but support could be added|

## Additional Types

Expand Down
5 changes: 2 additions & 3 deletions src/collections/componentSetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/* eslint complexity: ["error", 22] */

import * as path from 'path';
import { GlobalInfo, Logger, SfError } from '@salesforce/core';
import { StateAggregator, Logger, SfError } from '@salesforce/core';
import * as fs from 'graceful-fs';
import { ComponentSet } from '../collections';
import { RegistryAccess } from '../registry';
Expand Down Expand Up @@ -122,8 +122,7 @@ export class ComponentSetBuilder {
componentSet ??= new ComponentSet();
logger.debug(`Building ComponentSet from targetUsername: ${org.username}`);
const fromConnection = await ComponentSet.fromConnection({
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
usernameOrConnection: (await GlobalInfo.getInstance()).aliases.getUsername(org.username) || org.username,
usernameOrConnection: (await StateAggregator.getInstance()).aliases.getUsername(org.username) || org.username,
// exclude components based on the results of componentFilter function
// components with namespacePrefix where org.exclude includes manageableState (to exclude managed packages)
// components with namespacePrefix where manageableState equals undefined (to exclude components e.g. InstalledPackage)
Expand Down
9 changes: 1 addition & 8 deletions test/client/deployStrategies/auraDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { expect } from 'chai';
import * as fs from 'graceful-fs';
import { SaveError, SaveResult } from 'jsforce';
import { createSandbox, SinonSandbox } from 'sinon';
import { AnyJson } from '@salesforce/ts-types';
import { Messages } from '@salesforce/core';
import { ComponentStatus, ToolingDeployStatus } from '../../../src/client';
import { AuraDeploy } from '../../../src/client/deployStrategies';
Expand All @@ -39,13 +38,7 @@ describe('Aura Deploy Strategy', () => {

beforeEach(async () => {
sandboxStub = createSandbox();
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[testData.username]: testData as unknown as AnyJson,
}),
},
};
await $$.stubAuths(testData);
mockConnection = await Connection.create({
authInfo: await AuthInfo.create({
username: testData.username,
Expand Down
9 changes: 1 addition & 8 deletions test/client/deployStrategies/baseDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
import { assert, expect } from 'chai';
import * as fs from 'graceful-fs';
import { createSandbox, SinonSandbox } from 'sinon';
import { AnyJson } from '@salesforce/ts-types';
import { ContainerDeploy } from '../../../src/client/deployStrategies';

Messages.importMessagesDirectory(__dirname);
Expand All @@ -30,13 +29,7 @@ describe('Base Deploy Strategy', () => {

beforeEach(async () => {
sandboxStub = createSandbox();
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[testData.username]: testData as unknown as AnyJson,
}),
},
};
await $$.stubAuths(testData);
mockConnection = await Connection.create({
authInfo: await AuthInfo.create({
username: testData.username,
Expand Down
9 changes: 1 addition & 8 deletions test/client/deployStrategies/containerDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { expect } from 'chai';
import * as fs from 'graceful-fs';
import { Record, SaveError, SaveResult } from 'jsforce';
import { createSandbox, SinonSandbox } from 'sinon';
import { AnyJson } from '@salesforce/ts-types';
import { ContainerDeploy } from '../../../src/client/deployStrategies';
import { ComponentStatus, QueryResult, ToolingCreateResult, ToolingDeployStatus } from '../../../src/client/types';
import { SourceComponent } from '../../../src/resolve';
Expand Down Expand Up @@ -69,13 +68,7 @@ describe('Container Deploy Strategy', () => {

beforeEach(async () => {
sandboxStub = createSandbox();
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[testData.username]: testData as unknown as AnyJson,
}),
},
};
await $$.stubAuths(testData);
mockConnection = await Connection.create({
authInfo: await AuthInfo.create({
username: testData.username,
Expand Down
9 changes: 1 addition & 8 deletions test/client/deployStrategies/lwcDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { expect } from 'chai';
import * as fs from 'graceful-fs';
import { SaveError, SaveResult } from 'jsforce';
import { createSandbox, SinonSandbox } from 'sinon';
import { AnyJson } from '@salesforce/ts-types';
import { LwcDeploy } from '../../../src/client/deployStrategies';
import { LightningComponentResource, ToolingCreateResult } from '../../../src/client/types';
import { SourceComponent, VirtualTreeContainer } from '../../../src/resolve';
Expand Down Expand Up @@ -87,13 +86,7 @@ describe('LWC Deploy Strategy', () => {

beforeEach(async () => {
sandboxStub = createSandbox();
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[testData.username]: testData as unknown as AnyJson,
}),
},
};
await $$.stubAuths(testData);
mockConnection = await Connection.create({
authInfo: await AuthInfo.create({
username: testData.username,
Expand Down
9 changes: 4 additions & 5 deletions test/client/metadataApiRetrieve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import * as unzipper from 'unzipper';
import { createSandbox, match, SinonStub } from 'sinon';
import { getString } from '@salesforce/ts-types';
import * as fs from 'graceful-fs';
import { testSetup } from '@salesforce/core/lib/testSetup';
import {
ComponentSet,
ComponentStatus,
Expand Down Expand Up @@ -98,7 +97,7 @@ describe('MetadataApiRetrieve', () => {

expect(retrieveStub.calledOnce).to.be.true;
expect(retrieveStub.firstCall.args[0]).to.deep.equal({
apiVersion: (await mockConnection(testSetup())).getApiVersion(),
apiVersion: (await mockConnection()).getApiVersion(),
unpackaged: (await toRetrieve.getObject()).Package,
});
});
Expand All @@ -116,7 +115,7 @@ describe('MetadataApiRetrieve', () => {

expect(retrieveStub.calledOnce).to.be.true;
expect(retrieveStub.firstCall.args[0]).to.deep.equal({
apiVersion: (await mockConnection(testSetup())).getApiVersion(),
apiVersion: (await mockConnection()).getApiVersion(),
packageNames: options.packageOptions,
unpackaged: (await toRetrieve.getObject()).Package,
});
Expand All @@ -135,7 +134,7 @@ describe('MetadataApiRetrieve', () => {

expect(retrieveStub.calledOnce).to.be.true;
expect(retrieveStub.firstCall.args[0]).to.deep.equal({
apiVersion: (await mockConnection(testSetup())).getApiVersion(),
apiVersion: (await mockConnection()).getApiVersion(),
packageNames: [options.packageOptions[0].name],
unpackaged: (await toRetrieve.getObject()).Package,
});
Expand All @@ -154,7 +153,7 @@ describe('MetadataApiRetrieve', () => {

expect(retrieveStub.calledOnce).to.be.true;
expect(retrieveStub.firstCall.args[0]).to.deep.equal({
apiVersion: (await mockConnection(testSetup())).getApiVersion(),
apiVersion: (await mockConnection()).getApiVersion(),
packageNames: [options.packageOptions[0].name],
unpackaged: (await toRetrieve.getObject()).Package,
});
Expand Down
4 changes: 1 addition & 3 deletions test/client/metadataTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
import { fail } from 'assert';
import { createSandbox, SinonStub } from 'sinon';
import { testSetup } from '@salesforce/core/lib/testSetup';
import { AuthInfo, Connection, PollingClient, Messages } from '@salesforce/core';
import { expect } from 'chai';
import { Duration, sleep } from '@salesforce/kit';
Expand All @@ -18,7 +17,6 @@ import { mockConnection } from '../mock/client';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.load('@salesforce/source-deploy-retrieve', 'sdr', ['md_request_fail']);

const $$ = testSetup();
const env = createSandbox();

class TestTransfer extends MetadataTransfer<MetadataRequestStatus, MetadataTransferResult> {
Expand Down Expand Up @@ -52,7 +50,7 @@ describe('MetadataTransfer', () => {
let operation: TestTransfer;

beforeEach(async () => {
connection = await mockConnection($$);
connection = await mockConnection();
operation = new TestTransfer({
components: new ComponentSet(),
usernameOrConnection: connection,
Expand Down
9 changes: 1 addition & 8 deletions test/client/retrieve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
import { expect } from 'chai';
import * as fs from 'graceful-fs';
import { createSandbox, SinonSandbox } from 'sinon';
import { AnyJson } from '@salesforce/ts-types';
import { ToolingApi } from '../../src/client';
import { MetadataResolver, SourceComponent } from '../../src/resolve';
import { QueryResult, RequestStatus, SourceRetrieveResult } from '../../src/client/types';
Expand Down Expand Up @@ -65,13 +64,7 @@ describe('Tooling Retrieve', () => {

beforeEach(async () => {
sandboxStub = createSandbox();
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[testData.username]: testData as unknown as AnyJson,
}),
},
};
await $$.stubAuths(testData);
mockConnection = await Connection.create({
authInfo: await AuthInfo.create({
username: testData.username,
Expand Down
9 changes: 1 addition & 8 deletions test/client/toolingApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { AuthInfo, Connection, Messages } from '@salesforce/core';
import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
import { expect } from 'chai';
import { createSandbox, SinonSandbox } from 'sinon';
import { AnyJson } from '@salesforce/ts-types';
import { MetadataResolver, SourceComponent } from '../../src/resolve';
import { ComponentStatus, ToolingApi, ToolingDeployStatus } from '../../src/client';
import { ContainerDeploy } from '../../src/client/deployStrategies';
Expand All @@ -32,13 +31,7 @@ describe('Tooling API tests', () => {

beforeEach(async () => {
sandboxStub = createSandbox();
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[testData.username]: testData as unknown as AnyJson,
}),
},
};
await $$.stubAuths(testData);
mockConnection = await Connection.create({
authInfo: await AuthInfo.create({
username: testData.username,
Expand Down
33 changes: 10 additions & 23 deletions test/collections/componentSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { join } from 'path';
import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
import { expect } from 'chai';
import { createSandbox, SinonStub } from 'sinon';
import { AnyJson } from '@salesforce/ts-types';
import { AuthInfo, Connection, Messages } from '@salesforce/core';
import {
ComponentSet,
Expand Down Expand Up @@ -247,7 +246,7 @@ describe('ComponentSet', () => {

describe('fromConnection', () => {
it('should initialize using a connection', async () => {
const connection = await mockConnection($$);
const connection = await mockConnection();
const expected: MetadataComponent[] = [
{
fullName: 'Test',
Expand Down Expand Up @@ -279,16 +278,10 @@ describe('ComponentSet', () => {
apiVersion: '50.0',
});
env.stub(RegistryAccess.prototype, 'getTypeByName').returns(registry.types.apexclass);
const testData = new MockTestOrgData();
const username = '[email protected]';
const testData = new MockTestOrgData($$.uniqid(), { username });

$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[username]: testData as unknown as AnyJson,
}),
},
};
await $$.stubAuths(testData);
const set = await ComponentSet.fromConnection({
usernameOrConnection: username,
apiVersion: '50.0',
Expand All @@ -301,15 +294,9 @@ describe('ComponentSet', () => {
});

it('should initialize using an username', async () => {
const testData = new MockTestOrgData();
const username = '[email protected]';
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[username]: testData as unknown as AnyJson,
}),
},
};
const testData = new MockTestOrgData($$.uniqid(), { username });
await $$.stubAuths(testData);
const connection = await Connection.create({
authInfo: await AuthInfo.create({
username: '[email protected]',
Expand Down Expand Up @@ -642,7 +629,7 @@ describe('ComponentSet', () => {

describe('deploy', () => {
it('should properly construct a deploy operation', async () => {
const connection = await mockConnection($$);
const connection = await mockConnection();
const set = ComponentSet.fromSource({
fsPaths: ['.'],
registry: registryAccess,
Expand All @@ -664,7 +651,7 @@ describe('ComponentSet', () => {
});

it('should properly construct a deploy operation with overridden apiVersion', async () => {
const connection = await mockConnection($$);
const connection = await mockConnection();
const apiVersion = '50.0';
const set = ComponentSet.fromSource({
fsPaths: ['.'],
Expand Down Expand Up @@ -708,7 +695,7 @@ describe('ComponentSet', () => {

describe('retrieve', () => {
it('should properly construct a retrieve operation', async () => {
const connection = await mockConnection($$);
const connection = await mockConnection();
const set = ComponentSet.fromSource({
fsPaths: ['.'],
registry: registryAccess,
Expand Down Expand Up @@ -737,7 +724,7 @@ describe('ComponentSet', () => {
});

it('should properly construct a retrieve operation with overridden apiVersion', async () => {
const connection = await mockConnection($$);
const connection = await mockConnection();
const apiVersion = '50.0';
const set = ComponentSet.fromSource({
fsPaths: ['.'],
Expand Down Expand Up @@ -769,7 +756,7 @@ describe('ComponentSet', () => {
});

it('should properly construct a retrieve operation with packageName', async () => {
const connection = await mockConnection($$);
const connection = await mockConnection();
const set = new ComponentSet([]);
const operationArgs = {
components: set,
Expand Down
12 changes: 2 additions & 10 deletions test/mock/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import { pipeline, Writable } from 'stream';
import { promisify } from 'util';
import { AuthInfo, Connection } from '@salesforce/core';
import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup';
import { MockTestOrgData } from '@salesforce/core/lib/testSetup';
import { create as createArchive } from 'archiver';
import { AnyJson } from '@salesforce/ts-types';

export async function createMockZip(entries: string[]): Promise<Buffer> {
const archive = createArchive('zip');
Expand All @@ -27,15 +26,8 @@ export async function createMockZip(entries: string[]): Promise<Buffer> {
return Buffer.concat(buffers);
}

export async function mockConnection($$: TestContext): Promise<Connection> {
export async function mockConnection(): Promise<Connection> {
const testData = new MockTestOrgData();
$$.configStubs.GlobalInfo = {
contents: {
orgs: Object.assign($$.configStubs.GlobalInfo?.contents?.orgs || {}, {
[testData.username]: testData as unknown as AnyJson,
}),
},
};
return Connection.create({
authInfo: await AuthInfo.create({
username: testData.username,
Expand Down
Loading

0 comments on commit f1d8848

Please sign in to comment.