Skip to content

Commit

Permalink
fix: do not disassemble files if the file only has leaf elements
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Mar 7, 2024
1 parent 2c183f2 commit ca9efbb
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/service/buildDisassembledFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function buildDisassembledFiles(
}
let leafContent = "";
let leafCount = 0;
let hasNestedElements: boolean = false;

// Iterate through child elements to find the field name for each
Object.keys(rootElement)
Expand All @@ -47,6 +48,7 @@ export function buildDisassembledFiles(
key,
indent,
);
hasNestedElements = true;
} else {
const fieldValue = element;
leafContent += `${indent}<${key}>${String(fieldValue)}</${key}>\n`;
Expand All @@ -63,6 +65,7 @@ export function buildDisassembledFiles(
key,
indent,
);
hasNestedElements = true;
} else {
// Process XML elements that do not have children (e.g., leaf elements)
const fieldValue = rootElement[key];
Expand All @@ -72,6 +75,13 @@ export function buildDisassembledFiles(
}
});

if (!hasNestedElements) {
logger.error(
`The XML file ${baseName}.xml only has leaf elements. This file will not be disassembled.`,
);
return;
}

if (leafCount > 0) {
let leafFile = `${XML_HEADER}\n`;
leafFile += `<${rootElementName}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<description>Grants all rights needed for an HR administrator to manage employees.</description>
<label>HR Administration</label>
<userLicense>Salesforce</userLicense>
</PermissionSet>
44 changes: 44 additions & 0 deletions test/baselines/no-nested-elements/HR_Admin.permissionset-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<applicationVisibilities>
<application>JobApps__Recruiting</application>
<visible>true</visible>
</applicationVisibilities>
<classAccesses>
<apexClass>Send_Email_Confirmation</apexClass>
<enabled>true</enabled>
</classAccesses>
<fieldPermissions>
<editable>true</editable>
<field>Job_Request__c.Salary__c</field>
<readable>true</readable>
</fieldPermissions>
<description>Grants all rights needed for an HR administrator to manage employees.</description>
<label>HR Administration</label>
<userLicense>Salesforce</userLicense>
<objectPermissions>
<allowCreate>true</allowCreate>
<allowDelete>true</allowDelete>
<allowEdit>true</allowEdit>
<allowRead>true</allowRead>
<viewAllRecords>true</viewAllRecords>
<modifyAllRecords>true</modifyAllRecords>
<object>Job_Request__c</object>
</objectPermissions>
<pageAccesses>
<apexPage>Job_Request_Web_Form</apexPage>
<enabled>true</enabled>
</pageAccesses>
<recordTypeVisibilities>
<recordType>Recruiting.DevManager</recordType>
<visible>true</visible>
</recordTypeVisibilities>
<tabSettings>
<tab>Job_Request__c</tab>
<visibility>Available</visibility>
</tabSettings>
<userPermissions>
<enabled>true</enabled>
<name>APIEnabled</name>
</userPermissions>
</PermissionSet>
8 changes: 8 additions & 0 deletions test/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ describe("main function", () => {
xmlPath: "test/baselines/no-root-element/Assessment_Bot",
});

expect(logger.error).toHaveBeenCalled();
});
it("should test disassemble error condition (XML file only has leaf elements).", async () => {
const handler = new DisassembleXMLFileHandler();
await handler.disassemble({
xmlPath: "test/baselines/no-nested-elements",
});

expect(logger.error).toHaveBeenCalled();
});
});

0 comments on commit ca9efbb

Please sign in to comment.