Skip to content

Commit

Permalink
chore: work with singular child type
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Sep 10, 2024
1 parent 9055fd9 commit e52f110
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class DecomposedPermissionSetTransformer extends BaseMetadataTransformer
const preparedMetadata = composedMetadata
.filter(hasChildTypeId)
.map(addChildType)
.map((c) => toInfoContainer(mergeWith)(component)(c.childType)(c.tagValue as JsonMap))
.map((child) => toInfoContainer(mergeWith)(component)(child.childType)(child.tagValue as JsonMap))
.filter(forceIgnoreAllowsComponent(forceIgnore));

const writeInfosForChildren = combineChildWriteInfos(
Expand Down Expand Up @@ -249,8 +249,9 @@ const toInfoContainer =
(parent: SourceComponent) =>
(childType: MetadataType) =>
(tagValue: JsonMap): InfoContainer => {
const tagEntry: JsonMap[] = Array.isArray(tagValue) ? tagValue : [tagValue];
const entryName = childType.directoryName
? ((tagValue as unknown as JsonMap[]).at(0)?.[childType.uniqueIdElement!] as string).split('.')[0]
? (tagEntry.at(0)?.[childType.uniqueIdElement!] as string).split('.')[0]
: parent.name;
return {
parentComponent: parent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { presetMap } from '../../../src/registry/presets/presetMap';
import { DecomposedPermissionSetTransformer } from '../../../src/convert/transformers/decomposedPermissionSetTransformer';
import {
MD_FORMAT_PS,
MD_FORMAT_PS_ONE_CHILD,
ONLY_PS_PARENT,
SOURCE_FORMAT_PS,
} from '../../mock/type-constants/decomposedPermissionSetConstant';
Expand All @@ -36,6 +37,19 @@ describe('DecomposedPermissionSetTransformer', () => {
expect(result[3].output).to.match(/objectSettings[\\/]Broker__c.objectSettings-meta.xml$/);
expect(result[4].output).to.match(/myPS.permissionset-meta.xml$/);
});

it('multiple children combined, and some written to individual files', async () => {
const component = MD_FORMAT_PS_ONE_CHILD;
const xf = new DecomposedPermissionSetTransformer(regAcc);
const result = await xf.toSourceFormat({ component });
expect(result).to.have.length(2);
result.map((l) => {
expect(l.output).to.include(join('main', 'default', 'permissionsets'));
});
expect(result[0].output).to.match(/objectSettings[\\/]Case.objectSettings-meta.xml$/);
expect(result[1].output).to.match(/myPS.permissionset-meta.xml$/);
});

it('merge component in defaultDir', async () => {
const component = MD_FORMAT_PS;
const xf = new DecomposedPermissionSetTransformer(regAcc);
Expand Down
34 changes: 34 additions & 0 deletions test/mock/type-constants/decomposedPermissionSetConstant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,40 @@ export const MD_FORMAT_PS = new SourceComponent(
])
);

export const MD_FORMAT_PS_ONE_CHILD = new SourceComponent(
{
name: 'myPS',
type: permissionSet,
xml: join('permissionsets', MDAPI_XML_NAME),
},
new VirtualTreeContainer([
{
dirPath: 'permissionsets',
children: [
{
name: MDAPI_XML_NAME,
data: Buffer.from(`<?xml version="1.0" encoding="UTF-8" ?>
<PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
<description>This PS has only one object permission</description>
<hasActivationRequired>true</hasActivationRequired>
<label>test</label>
<license>testing</license>
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Case</object>
<viewAllRecords>true</viewAllRecords>
</objectPermissions>
</PermissionSet>`),
},
],
},
])
);

export const SOURCE_FORMAT_PS = new SourceComponent(
{
name: 'myPS',
Expand Down

2 comments on commit e52f110

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: e52f110 Previous: 9055fd9 Ratio
eda-componentSetCreate-linux 241 ms 244 ms 0.99
eda-sourceToMdapi-linux 2367 ms 2423 ms 0.98
eda-sourceToZip-linux 1898 ms 1929 ms 0.98
eda-mdapiToSource-linux 2936 ms 2996 ms 0.98
lotsOfClasses-componentSetCreate-linux 432 ms 435 ms 0.99
lotsOfClasses-sourceToMdapi-linux 3668 ms 3737 ms 0.98
lotsOfClasses-sourceToZip-linux 3257 ms 3269 ms 1.00
lotsOfClasses-mdapiToSource-linux 3588 ms 3642 ms 0.99
lotsOfClassesOneDir-componentSetCreate-linux 760 ms 756 ms 1.01
lotsOfClassesOneDir-sourceToMdapi-linux 6495 ms 6585 ms 0.99
lotsOfClassesOneDir-sourceToZip-linux 5529 ms 5750 ms 0.96
lotsOfClassesOneDir-mdapiToSource-linux 6556 ms 6570 ms 1.00

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: e52f110 Previous: 9055fd9 Ratio
eda-componentSetCreate-win32 610 ms 637 ms 0.96
eda-sourceToMdapi-win32 4367 ms 4375 ms 1.00
eda-sourceToZip-win32 2955 ms 3008 ms 0.98
eda-mdapiToSource-win32 5850 ms 5910 ms 0.99
lotsOfClasses-componentSetCreate-win32 1188 ms 1259 ms 0.94
lotsOfClasses-sourceToMdapi-win32 7849 ms 8032 ms 0.98
lotsOfClasses-sourceToZip-win32 5007 ms 5241 ms 0.96
lotsOfClasses-mdapiToSource-win32 7915 ms 8227 ms 0.96
lotsOfClassesOneDir-componentSetCreate-win32 2104 ms 2237 ms 0.94
lotsOfClassesOneDir-sourceToMdapi-win32 13758 ms 14351 ms 0.96
lotsOfClassesOneDir-sourceToZip-win32 9107 ms 9552 ms 0.95
lotsOfClassesOneDir-mdapiToSource-win32 13952 ms 14642 ms 0.95

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.