Skip to content

Commit

Permalink
feat: get types from sdr registry
Browse files Browse the repository at this point in the history
* feat: get types from sdr registry

* test: only assert require properties
  • Loading branch information
mshanemc authored Mar 10, 2023
1 parent 1e89caa commit e3df9ce
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
11 changes: 8 additions & 3 deletions src/commands/force/source/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
RequestStatus,
RetrieveVersionData,
RetrieveResult,
RegistryAccess,
} from '@salesforce/source-deploy-retrieve';
import { SourceTracking } from '@salesforce/source-tracking';
import { SourceCommand } from '../../../sourceCommand';
Expand Down Expand Up @@ -96,6 +97,7 @@ export class Retrieve extends SourceCommand {
protected retrieveResult: RetrieveResult;
protected tracking: SourceTracking;
private resolvedTargetDir: string;
private registry = new RegistryAccess();

public async run(): Promise<RetrieveCommandResult> {
await this.preChecks();
Expand Down Expand Up @@ -161,7 +163,10 @@ export class Retrieve extends SourceCommand {
if (this.getFlag<string>('manifest') || this.getFlag<string>('metadata')) {
if (this.wantsToRetrieveCustomFields()) {
this.ux.warn(messages.getMessage('wantsToRetrieveCustomFields'));
this.componentSet.add({ fullName: ComponentSet.WILDCARD, type: { id: 'customobject', name: 'CustomObject' } });
this.componentSet.add({
fullName: ComponentSet.WILDCARD,
type: this.registry.getTypeByName('CustomObject'),
});
}
}
if (this.getFlag<boolean>('tracksource')) {
Expand Down Expand Up @@ -241,12 +246,12 @@ export class Retrieve extends SourceCommand {

private wantsToRetrieveCustomFields(): boolean {
const hasCustomField = this.componentSet.has({
type: { name: 'CustomField', id: 'customfield' },
type: this.registry.getTypeByName('CustomField'),
fullName: ComponentSet.WILDCARD,
});

const hasCustomObject = this.componentSet.has({
type: { name: 'CustomObject', id: 'customobject' },
type: this.registry.getTypeByName('CustomObject'),
fullName: ComponentSet.WILDCARD,
});
return hasCustomField && !hasCustomObject;
Expand Down
10 changes: 3 additions & 7 deletions test/commands/source/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ComponentSetBuilder,
ComponentSetOptions,
SourceComponent,
RegistryAccess,
} from '@salesforce/source-deploy-retrieve';
import { Lifecycle, Org, SfProject } from '@salesforce/core';
import { fromStub, stubInterface, stubMethod } from '@salesforce/ts-sinon';
Expand All @@ -23,6 +24,7 @@ import { Delete } from '../../../src/commands/force/source/delete';
import { exampleDeleteResponse, exampleSourceComponent } from './testConsts';

const fsPromises = fs.promises;
const registry = new RegistryAccess();

describe('force:source:delete', () => {
const sandbox = sinon.createSandbox();
Expand Down Expand Up @@ -186,13 +188,7 @@ describe('force:source:delete', () => {
buildComponentSetStub.restore();
const comp = new SourceComponent({
name: 'mylwc',
type: {
id: 'lightningcomponentbundle',
name: 'LightningComponentBundle',
strategies: {
adapter: 'bundle',
},
},
type: registry.getTypeByName('LightningComponentBundle'),
});
stubMethod(sandbox, ComponentSetBuilder, 'build').resolves({
toArray: () => [comp],
Expand Down
4 changes: 2 additions & 2 deletions test/commands/source/retrieve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ describe('force:source:retrieve', () => {
expect(component)
.to.be.a('object')
.and.to.have.property('type')
.and.to.deep.equal({ id: 'customobject', name: 'CustomObject' });
.and.to.deep.include({ id: 'customobject', name: 'CustomObject' });
expect(component).and.to.have.property('fullName').and.to.be.equal(ComponentSet.WILDCARD);
},
has: (component: ComponentLike) => {
Expand Down Expand Up @@ -376,7 +376,7 @@ describe('force:source:retrieve', () => {
expect(component)
.to.be.a('object')
.and.to.have.property('type')
.and.to.deep.equal({ id: 'customobject', name: 'CustomObject' });
.and.to.deep.include({ id: 'customobject', name: 'CustomObject' });
expect(component).and.to.have.property('fullName').and.to.be.equal(ComponentSet.WILDCARD);
},
has: (component: ComponentLike) => {
Expand Down

0 comments on commit e3df9ce

Please sign in to comment.