Skip to content

Commit

Permalink
fix: recomposition failing for child components (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Powell authored Aug 13, 2020
1 parent 8a04524 commit fd4a3ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
18 changes: 10 additions & 8 deletions src/metadata-registry/manifestGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ export class ManifestGenerator {
private createMetadataMap(components: MetadataComponent[]): Map<string, Set<string>> {
const metadataMap: Map<string, Set<string>> = new Map<string, Set<string>>();
for (const component of components) {
const metadataType = this.registryAccess.getTypeFromName(component.type.name).name;
const metadataName = component.fullName;
if (metadataMap.has(metadataType)) {
const metadataNames = metadataMap.get(metadataType);
metadataNames.add(metadataName);
metadataMap.set(metadataType, metadataNames);
const {
fullName,
type: { name: typeName },
} = component;
if (metadataMap.has(typeName)) {
const metadataNames = metadataMap.get(typeName);
metadataNames.add(fullName);
metadataMap.set(typeName, metadataNames);
} else {
const metadataNames: Set<string> = new Set<string>();
metadataNames.add(metadataName);
metadataMap.set(metadataType, metadataNames);
metadataNames.add(fullName);
metadataMap.set(typeName, metadataNames);
}
}
return metadataMap;
Expand Down
25 changes: 9 additions & 16 deletions test/metadata-registry/manifestGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ import { fail } from 'assert';
describe('ManifestGenerator', () => {
let sandboxStub: SinonSandbox;
const manifestGenerator = new ManifestGenerator();

beforeEach(async () => {
sandboxStub = createSandbox();
});

afterEach(() => {
sandboxStub.restore();
});

it('should generate manifest for one type', () => {
const component = {
fullName: 'someName',
type: { id: 'apexclass', name: 'ApexClass' },
type: { id: 'foobar', name: 'FooBar' },
};
let expectedManifest = '<?xml version="1.0" encoding="UTF-8"?>\n';
expectedManifest += '<Package xmlns="http://soap.sforce.com/2006/04/metadata">\n';
expectedManifest +=
' <types>\n <members>someName</members>\n <name>ApexClass</name>\n </types>\n';
' <types>\n <members>someName</members>\n <name>FooBar</name>\n </types>\n';
expectedManifest += ' <version>48.0</version>\n</Package>';
expect(manifestGenerator.createManifest([component])).to.equal(expectedManifest);
});

it('should generate manifest for multiple types', () => {
const component1 = {
fullName: 'apexClass1',
Expand All @@ -52,6 +56,7 @@ describe('ManifestGenerator', () => {
expectedManifest += ' <version>48.0</version>\n</Package>';
expect(manifestGenerator.createManifest([component1, component2])).to.equal(expectedManifest);
});

it('should generate manifest for multiple components', () => {
const component1 = {
fullName: 'apexClass1',
Expand All @@ -76,6 +81,7 @@ describe('ManifestGenerator', () => {
expectedManifest
);
});

it('should generate manifest for multiple components passed in different order', () => {
const component1 = {
fullName: 'apexClass1',
Expand All @@ -100,6 +106,7 @@ describe('ManifestGenerator', () => {
expectedManifest
);
});

it('should generate manifest by overriding apiversion', () => {
const component = {
fullName: 'someName',
Expand All @@ -112,20 +119,6 @@ describe('ManifestGenerator', () => {
expectedManifest += ' <version>45.0</version>\n</Package>';
expect(manifestGenerator.createManifest([component], '45.0')).to.equal(expectedManifest);
});
it('should throw error for non valid type', () => {
const component = {
fullName: 'someName',
type: { id: 'someveryunknowntype', name: 'someveryunknowntype' },
};
try {
manifestGenerator.createManifest([component]);
expect.fail('should have failed');
} catch (e) {
expect(e.message).to.equal(
"Missing metadata type definition in registry for id 'someveryunknowntype'"
);
}
});

const rootPath = path.join('file', 'path');
const mdComponents = [
Expand Down

0 comments on commit fd4a3ab

Please sign in to comment.