Skip to content

Commit

Permalink
Wr/remove mock registry (#521)
Browse files Browse the repository at this point in the history
* chore: restore point - attempting global find/replace

* chore: working through tests, 34 failing

* test: the UTs are  passing :)

* chore: adding types for SDR

* refactor: remove mock/registry dir

* refactor: test constants easier to understand

* chore: restore tests

* chore: remove mock registry from new tests on main

* chore: cleanup, fix all test constant names

* chore: fix deps
  • Loading branch information
WillieRuemmele authored Jan 12, 2022
1 parent f2a2262 commit 8f19e30
Show file tree
Hide file tree
Showing 54 changed files with 868 additions and 1,390 deletions.
4 changes: 1 addition & 3 deletions contributing/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ Only `source:push` and `source:pull` support source tracking, so the target type

## Unit Testing

SDR Unit tests are abstract (mockRegistry tries to represent possible patterns). If your type uses a combination of properties that don't match an existing type in the registry, there's a chance the behavior isn't covered.

Reach out to the CLI team for help with unit tests.

[metadataResolverRealRegistry.ts](../test/resolve/metadataResolverRealRegistry.test.ts) is an example of unit testing one behavior (resolving from source files) of a real metadata type.
[metadataResolverRegistry.ts](../test/resolve/metadataResolverRegistry.test.ts) is an example of unit testing one behavior (resolving from source files) of a real metadata type.

## Integration Testing

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"xmldom-sfdx-encoding": "^0.1.29"
},
"devDependencies": {
"@salesforce/dev-config": "^2.1.2",
"@salesforce/dev-config": "^2.1.3",
"@salesforce/dev-scripts": "^1.0.2",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "^1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion src/collections/componentSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import {
ComponentLike,
ManifestResolver,
MetadataComponent,
MetadataMember,
MetadataResolver,
SourceComponent,
TreeContainer,
} from '../resolve';
import { MetadataType, RegistryAccess } from '../registry';
import { MetadataMember } from '../resolve/types';
import {
DestructiveChangesType,
FromManifestOptions,
Expand Down
4 changes: 2 additions & 2 deletions src/resolve/metadataResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { basename, dirname, join, sep } from 'path';
import { Lifecycle } from '@salesforce/core';
import { TypeInferenceError } from '../errors';
import { extName, parentName, parseMetadataXml } from '../utils';
import { RegistryAccess } from '../registry/registryAccess';
import { MetadataType, RegistryAccess } from '../registry';
import { ComponentSet } from '../collections';
import { MetadataType } from '../registry';
import { META_XML_SUFFIX } from '../common';
import { SourceAdapterFactory } from './adapters/sourceAdapterFactory';
import { ForceIgnore } from './forceIgnore';
import { SourceComponent } from './sourceComponent';
import { NodeFSTreeContainer, TreeContainer } from './treeContainers';

/**
* Resolver for metadata type and component objects.
*
Expand Down
2 changes: 1 addition & 1 deletion test/client/auraDefinitionMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { QueryResult } from '../../src/client/types';
import { QueryResult } from '../../src';

export const auraComponent: QueryResult = {
size: 8,
Expand Down
4 changes: 1 addition & 3 deletions test/client/diagnosticUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import { join } from 'path';
import { expect } from 'chai';
import { DiagnosticUtil } from '../../src/client/diagnosticUtil';
import { SourceComponent } from '../../src/resolve/sourceComponent';
import { DeployMessage } from '../../src/client/types';
import { registry } from '../../src';
import { DeployMessage, registry, SourceComponent } from '../../src';

type MockDeployMessage = {
problem?: string;
Expand Down
2 changes: 1 addition & 1 deletion test/client/lightningComponentMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { QueryResult } from '../../src/client/types';
import { QueryResult } from '../../src';

export const lwcComponentMock: QueryResult = {
size: 4,
Expand Down
30 changes: 19 additions & 11 deletions test/client/metadataApiDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,31 @@ import { assert, expect } from 'chai';
import { AnyJson, getString } from '@salesforce/ts-types';
import { PollingClient, StatusResult } from '@salesforce/core';
import { Duration } from '@salesforce/kit';
import { ComponentSet, registry, SourceComponent, DeployResult, MetadataApiDeploy } from '../../src';
import { ComponentStatus, DeployMessage, FileResponse, MetadataApiDeployStatus } from '../../src/client/types';
import {
ComponentSet,
ComponentStatus,
DeployMessage,
DeployResult,
FileResponse,
MetadataApiDeploy,
MetadataApiDeployStatus,
registry,
SourceComponent,
} from '../../src';
import {
MOCK_ASYNC_RESULT,
MOCK_RECENTLY_VALIDATED_ID_REST,
MOCK_RECENTLY_VALIDATED_ID_SOAP,
stubMetadataDeploy,
} from '../mock/client/transferOperations';
import { mockRegistry, matchingContentFile } from '../mock/registry';
import { matchingContentFile } from '../mock';
import { META_XML_SUFFIX } from '../../src/common';
import {
DECOMPOSED_CHILD_COMPONENT_1,
DECOMPOSED_CHILD_COMPONENT_2,
DECOMPOSED_COMPONENT,
} from '../mock/registry/type-constants/decomposedConstants';
import { COMPONENT } from '../mock/registry/type-constants/matchingContentFileConstants';
} from '../mock/type-constants/customObjectConstant';
import { COMPONENT } from '../mock/type-constants/apexClassConstant';
import { MissingJobIdError } from '../../src/errors';

const env = createSandbox();
Expand Down Expand Up @@ -95,7 +104,7 @@ describe('MetadataApiDeploy', () => {

it('should return an AsyncResult', async () => {
const component = matchingContentFile.COMPONENT;
const deployedComponents = new ComponentSet([component], mockRegistry);
const deployedComponents = new ComponentSet([component]);
const { operation } = await stubMetadataDeploy(env, {
components: deployedComponents,
});
Expand All @@ -107,7 +116,7 @@ describe('MetadataApiDeploy', () => {

it('should set the deploy ID', async () => {
const component = matchingContentFile.COMPONENT;
const deployedComponents = new ComponentSet([component], mockRegistry);
const deployedComponents = new ComponentSet([component]);
const { operation, response } = await stubMetadataDeploy(env, {
components: deployedComponents,
});
Expand All @@ -121,7 +130,7 @@ describe('MetadataApiDeploy', () => {
describe('pollStatus', () => {
it('should construct a result object with deployed components', async () => {
const component = matchingContentFile.COMPONENT;
const deployedComponents = new ComponentSet([component], mockRegistry);
const deployedComponents = new ComponentSet([component]);
const { operation, response } = await stubMetadataDeploy(env, {
components: deployedComponents,
});
Expand All @@ -145,7 +154,7 @@ describe('MetadataApiDeploy', () => {

it('should override timeout and frequency by number', async () => {
const component = matchingContentFile.COMPONENT;
const deployedComponents = new ComponentSet([component], mockRegistry);
const deployedComponents = new ComponentSet([component]);
const { operation, pollingClientSpy } = await stubMetadataDeploy(env, {
components: deployedComponents,
});
Expand All @@ -161,8 +170,7 @@ describe('MetadataApiDeploy', () => {
});

it('should override polling client options', async () => {
const component = matchingContentFile.COMPONENT;
const deployedComponents = new ComponentSet([component], mockRegistry);
const deployedComponents = new ComponentSet([matchingContentFile.COMPONENT]);
const { operation, pollingClientSpy } = await stubMetadataDeploy(env, {
components: deployedComponents,
});
Expand Down
55 changes: 28 additions & 27 deletions test/client/metadataApiRetrieve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
FileResponse,
MetadataApiRetrieve,
MetadataApiRetrieveStatus,
registry,
RequestStatus,
RetrieveResult,
SourceComponent,
Expand All @@ -25,9 +26,9 @@ import {
import { MetadataApiRetrieveError, MissingJobIdError } from '../../src/errors';
import { nls } from '../../src/i18n';
import { MOCK_ASYNC_RESULT, MOCK_DEFAULT_OUTPUT, stubMetadataRetrieve } from '../mock/client/transferOperations';
import { mockRegistry, mockRegistryData, xmlInFolder } from '../mock/registry';
import { COMPONENT } from '../mock/registry/type-constants/matchingContentFileConstants';
import { DECOMPOSED_COMPONENT } from '../mock/registry/type-constants/decomposedConstants';
import { xmlInFolder } from '../mock';
import { COMPONENT } from '../mock/type-constants/apexClassConstant';
import { DECOMPOSED_COMPONENT } from '../mock/type-constants/customObjectConstant';

const env = createSandbox();

Expand All @@ -37,7 +38,7 @@ describe('MetadataApiRetrieve', () => {
describe('Lifecycle', () => {
describe('start', () => {
it('should throw error if there are no components to retrieve', async () => {
const toRetrieve = new ComponentSet([], mockRegistry);
const toRetrieve = new ComponentSet([]);
const { operation } = await stubMetadataRetrieve(env, {
toRetrieve,
merge: true,
Expand All @@ -53,7 +54,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should throw error if packageNames list is empty', async () => {
const toRetrieve = new ComponentSet([], mockRegistry);
const toRetrieve = new ComponentSet([]);
const { operation } = await stubMetadataRetrieve(env, {
toRetrieve,
merge: true,
Expand All @@ -70,7 +71,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should call retrieve for unpackaged data', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const options = {
toRetrieve,
merge: true,
Expand All @@ -87,7 +88,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should call retrieve for a package as string[]', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const options = {
toRetrieve,
packageOptions: ['MyPackage'],
Expand All @@ -106,7 +107,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should call retrieve for a package as PackageOptions[] with name only', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const options = {
toRetrieve,
packageOptions: [{ name: 'MyPackage' }],
Expand All @@ -125,7 +126,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should call retrieve for a package as PackageOptions[] with name and outputDir', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const options = {
toRetrieve,
packageOptions: [{ name: 'MyPackage', outputDir: 'fake/output/dir' }],
Expand All @@ -144,7 +145,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should return an AsyncResult', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const options = {
toRetrieve,
packageNames: ['MyPackage'],
Expand All @@ -159,7 +160,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should set the retrieve ID', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const options = {
toRetrieve,
packageNames: ['MyPackage'],
Expand All @@ -178,7 +179,7 @@ describe('MetadataApiRetrieve', () => {
const getPackageComponent = (packageName: string): SourceComponent => {
const contentName = 'z.mcf';
const metaName = `${contentName}-meta.xml`;
const type = mockRegistryData.types.matchingcontentfile;
const type = registry.types.apexclass;
return new SourceComponent(
{
name: 'z',
Expand All @@ -197,7 +198,7 @@ describe('MetadataApiRetrieve', () => {

it('should retrieve zip and extract to directory', async () => {
const component = COMPONENT;
const toRetrieve = new ComponentSet([component], mockRegistry);
const toRetrieve = new ComponentSet([component]);
const { operation, convertStub } = await stubMetadataRetrieve(env, {
toRetrieve,
successes: toRetrieve,
Expand All @@ -220,8 +221,8 @@ describe('MetadataApiRetrieve', () => {
const packageName = 'MyPackage';
const pkgComponent = getPackageComponent(packageName);
const fromSourceSpy = env.spy(ComponentSet, 'fromSource');
const toRetrieve = new ComponentSet([component], mockRegistry);
const successesCompSet = new ComponentSet([component, pkgComponent], mockRegistry);
const toRetrieve = new ComponentSet([component]);
const successesCompSet = new ComponentSet([component, pkgComponent]);
const { operation, convertStub } = await stubMetadataRetrieve(env, {
toRetrieve,
packageOptions: [packageName],
Expand Down Expand Up @@ -254,8 +255,8 @@ describe('MetadataApiRetrieve', () => {
const packageOutputDir = 'myPackageDir';
const pkgComponent = getPackageComponent(packageName);
const fromSourceSpy = env.spy(ComponentSet, 'fromSource');
const toRetrieve = new ComponentSet([component], mockRegistry);
const successesCompSet = new ComponentSet([component, pkgComponent], mockRegistry);
const toRetrieve = new ComponentSet([component]);
const successesCompSet = new ComponentSet([component, pkgComponent]);
const { operation, convertStub } = await stubMetadataRetrieve(env, {
toRetrieve,
packageOptions: [{ name: packageName, outputDir: packageOutputDir }],
Expand Down Expand Up @@ -285,7 +286,7 @@ describe('MetadataApiRetrieve', () => {
it('should save the temp directory if the environment variable is set', async () => {
try {
process.env.SFDX_MDAPI_TEMP_DIR = 'test';
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const { operation, convertStub } = await stubMetadataRetrieve(env, {
toRetrieve,
merge: true,
Expand All @@ -303,7 +304,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should NOT save the temp directory if the environment variable is NOT set', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const { operation, convertStub } = await stubMetadataRetrieve(env, {
toRetrieve,
merge: true,
Expand All @@ -319,7 +320,7 @@ describe('MetadataApiRetrieve', () => {

it('should retrieve zip and merge with existing components', async () => {
const component = COMPONENT;
const toRetrieve = new ComponentSet([component], mockRegistry);
const toRetrieve = new ComponentSet([component]);
const { operation, convertStub } = await stubMetadataRetrieve(env, {
toRetrieve,
merge: true,
Expand All @@ -341,7 +342,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should construct a result object with retrieved components', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const { operation, response } = await stubMetadataRetrieve(env, {
toRetrieve,
merge: true,
Expand All @@ -356,7 +357,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should construct a result object with no components when components are forceIgnored', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
toRetrieve.forceIgnoredPaths = new Set([COMPONENT.xml, COMPONENT.content]);
const { operation } = await stubMetadataRetrieve(env, {
toRetrieve,
Expand All @@ -371,7 +372,7 @@ describe('MetadataApiRetrieve', () => {
});

it('should construct a result object with no components when no components are retrieved', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const { operation, response } = await stubMetadataRetrieve(env, {
toRetrieve,
merge: true,
Expand All @@ -384,7 +385,7 @@ describe('MetadataApiRetrieve', () => {

await operation.start();
const result = await operation.pollStatus();
const compSet = new ComponentSet(undefined, mockRegistry);
const compSet = new ComponentSet(undefined);
const expected = new RetrieveResult(response, compSet, toRetrieve);

expect(result).to.deep.equal(expected);
Expand All @@ -394,7 +395,7 @@ describe('MetadataApiRetrieve', () => {

describe('checkStatus', () => {
it('should throw an error when attempting to call checkStatus without an id set', async () => {
const toRetrieve = new ComponentSet([COMPONENT], mockRegistry);
const toRetrieve = new ComponentSet([COMPONENT]);
const { operation } = await stubMetadataRetrieve(env, {
toRetrieve,
merge: true,
Expand Down Expand Up @@ -474,7 +475,7 @@ describe('MetadataApiRetrieve', () => {
describe('cancel', () => {
it('should immediately stop polling', async () => {
const component = COMPONENT;
const components = new ComponentSet([component], mockRegistry);
const components = new ComponentSet([component]);
const { operation, checkStatusStub } = await stubMetadataRetrieve(env, {
toRetrieve: components,
});
Expand Down Expand Up @@ -654,7 +655,7 @@ describe('MetadataApiRetrieve', () => {
const component = new SourceComponent(
{
name: 'OnlyContent',
type: mockRegistryData.types.matchingcontentfile,
type: registry.types.apexclass,
content: COMPONENT.content,
},
COMPONENT.tree
Expand Down
Loading

0 comments on commit 8f19e30

Please sign in to comment.