Skip to content

Commit

Permalink
test: ut for forceignore of decomposed parent (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc authored Jul 24, 2023
1 parent 6fa99a2 commit 2f281d1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/convert/transformers/decomposedMetadataTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,20 @@ export class DecomposedMetadataTransformer extends BaseMetadataTransformer {
return [];
}

// eslint-disable-next-line complexity
public async toSourceFormat(component: SourceComponent, mergeWith?: SourceComponent): Promise<WriteInfo[]> {
const outputFile = mergeWith?.xml ?? getDefaultOutput(component);
const forceIgnore = component.getForceIgnore();

// if the whole parent is ignored, we won't worry about decomposing things
// this can happen if the manifest had a *; all the members will be retrieved.
if (forceIgnore.denies(outputFile)) {
return [];
}

const writeInfos: WriteInfo[] = [];
const childrenOfMergeComponent = new ComponentSet(mergeWith?.getChildren());
const { type, fullName: parentFullName } = component;
const forceIgnore = component.getForceIgnore();

let parentXmlObject: JsonMap | undefined;
const composedMetadata = await getComposedMetadataEntries(component);
Expand Down Expand Up @@ -147,20 +156,20 @@ export class DecomposedMetadataTransformer extends BaseMetadataTransformer {
if (!mergeWith) {
writeInfos.push({
source: parentSource,
output: getDefaultOutput(component),
output: outputFile,
});
} else if (mergeWith.xml) {
writeInfos.push({
source: parentSource,
output: mergeWith.xml,
output: outputFile,
});
this.setDecomposedState(component, { foundMerge: true });
} else {
this.setDecomposedState(component, {
foundMerge: false,
writeInfo: {
source: parentSource,
output: getDefaultOutput(component),
output: outputFile,
},
});
}
Expand Down
25 changes: 25 additions & 0 deletions test/convert/transformers/decomposedMetadataTransformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,31 @@ describe('DecomposedMetadataTransformer', () => {
expect(result).to.deep.equal([]);
});

it('should return no files when the parent is forceIgnored', async () => {
const { fullName } = component;
const context = new ConvertContext();
const transformer = new DecomposedMetadataTransformer(registryAccess, context);

$$.SANDBOX.stub(component, 'parseXml').resolves({
CustomObject: {
fullName,
customField: [{ fullName: 'child', test: 'testVal' }],
validationRules: [
{ fullName: 'child2', test: 'testVal2' },
{ fullName: 'child3', test: 'testVal3' },
],
},
});
$$.SANDBOX.stub(ForceIgnore.prototype, 'denies')
.returns(false)
.withArgs(join('main', 'default', 'objects', 'customObject__c', 'customObject__c.object-meta.xml'))
.returns(true);

const result = await transformer.toSourceFormat(component);

expect(result).to.deep.equal([]);
});

describe('Merging Components', () => {
it('should merge output with merge component that only has children', async () => {
assert(registry.types.customobject.children?.types.customfield.name);
Expand Down

0 comments on commit 2f281d1

Please sign in to comment.