Skip to content

Commit

Permalink
fix: trim metadata type, and name to prevent unnecessary errors (#179)
Browse files Browse the repository at this point in the history
* fix: trim metadata type, and name to prevent unnecessary errors

* chore: map and trim
  • Loading branch information
WillieRuemmele authored Aug 26, 2021
1 parent 25c8201 commit 2011caa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/componentSetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class ComponentSetBuilder {

// Build a Set of metadata entries
metadata.metadataEntries.forEach((rawEntry) => {
const splitEntry = rawEntry.split(':');
const splitEntry = rawEntry.split(':').map((entry) => entry.trim());
// The registry will throw if it doesn't know what this type is.
registry.getTypeByName(splitEntry[0]);
const entry = {
Expand Down
25 changes: 25 additions & 0 deletions test/commands/source/componentSetBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ describe('ComponentSetBuilder', () => {
expect(compSet.has({ type: 'ApexClass', fullName: '*' })).to.equal(true);
});

it('should create ComponentSet from metadata with spaces between : (ApexClass: MyApexClass)', async () => {
componentSet.add(apexClassComponent);
fromSourceStub.returns(componentSet);
const packageDir1 = path.resolve('force-app');

const compSet = await ComponentSetBuilder.build({
sourcepath: undefined,
manifest: undefined,
metadata: {
metadataEntries: ['ApexClass: MyApexClass'],
directoryPaths: [packageDir1],
},
});
expect(fromSourceStub.calledOnce).to.equal(true);
const fromSourceArgs = fromSourceStub.firstCall.args[0] as FromSourceOptions;
expect(fromSourceArgs).to.have.deep.property('fsPaths', [packageDir1]);
const filter = new ComponentSet();
filter.add({ type: 'ApexClass', fullName: 'MyApexClass' });
expect(fromSourceArgs).to.have.property('include');
expect(fromSourceArgs.include.getSourceComponents()).to.deep.equal(filter.getSourceComponents());
expect(compSet.size).to.equal(2);
expect(compSet.has(apexClassComponent)).to.equal(true);
expect(compSet.has({ type: 'ApexClass', fullName: 'MyApexClass' })).to.equal(true);
});

it('should throw an error when it cant resolve a metadata type (Metadata)', async () => {
const packageDir1 = path.resolve('force-app');

Expand Down

0 comments on commit 2011caa

Please sign in to comment.