Skip to content

chore: add a test for decomposed permsets - W-18121982 #1572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { SourceComponent, VirtualTreeContainer, presetMap, RegistryAccess } from
import { getEffectiveRegistry } from '../../../src/registry/variants';

// Constants for a matching content file type
const regAcc = new RegistryAccess(getEffectiveRegistry({ presets: [presetMap.get('decomposeCustomLabelsBeta2')!] }));
export const regAcc = new RegistryAccess(
getEffectiveRegistry({ presets: [presetMap.get('decomposeCustomLabelsBeta2')!] })
);

const customLabelsType = regAcc.getTypeByName('CustomLabels');
const customLabelType = regAcc.getTypeByName('CustomLabel');
Expand Down
138 changes: 3 additions & 135 deletions test/mock/type-constants/decomposedPermissionSetConstant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { SourceComponent, VirtualTreeContainer, presetMap, RegistryAccess } from
import { getEffectiveRegistry } from '../../../src/registry/variants';

// Constants for a matching content file type
const regAcc = new RegistryAccess(getEffectiveRegistry({ presets: [presetMap.get('decomposePermissionSetBeta2')!] }));
export const regAcc = new RegistryAccess(
getEffectiveRegistry({ presets: [presetMap.get('decomposePermissionSetBeta2')!] })
);

const permissionSet = regAcc.getTypeByName('PermissionSet');

Expand Down Expand Up @@ -418,137 +420,3 @@ export const ONLY_PS_PARENT = new SourceComponent(
},
])
);

// export const THREE_CUSTOM_LABELS_CMP = new SourceComponent(
// {
// name: 'CustomLabels',
// type: permissionSet,
// xml: join('labels', MDAPI_XML_NAME),
// },
// new VirtualTreeContainer([
// {
// dirPath: 'permissionSet',
// children: [
// {
// name: MDAPI_XML_NAME,
// data: Buffer.from(`<?xml version="1.0" encoding="UTF-8"?>
// <CustomLabels xmlns="http://soap.sforce.com/2006/04/metadata">
// <labels>
// <fullName>DeleteMe</fullName>
// <language>en_US</language>
// <protected>true</protected>
// <shortDescription>DeleteMe</shortDescription>
// <value>Test</value>
// </labels>
// <labels>
// <fullName>KeepMe1</fullName>
// <language>en_US</language>
// <protected>true</protected>
// <shortDescription>KeepMe1</shortDescription>
// <value>Test</value>
// </labels>
// <labels>
// <fullName>KeepMe2</fullName>
// <language>en_US</language>
// <protected>true</protected>
// <shortDescription>KeepMe2</shortDescription>
// <value>Test</value>
// </labels>
// </CustomLabels>`),
// },
// ],
// },
// ])
// );
//
// const ONLY_LABEL_CONTENTS = `<?xml version="1.0" encoding="UTF-8"?>
// <CustomLabel xmlns="http://soap.sforce.com/2006/04/metadata">
// <fullName>OnlyLabel</fullName>
// <language>en_US</language>
// <protected>true</protected>
// <shortDescription>OnlyLabel</shortDescription>
// <value>OnlyLabel</value>
// </CustomLabel>`;
//
// export const ONLY_LABEL_CMP_IN_DEFAULT_DIR_CMP = new SourceComponent(
// {
// name: 'OnlyLabel',
// type: customLabelType,
// xml: join('main', 'default', 'labels', 'OnlyLabel.label-meta.xml'),
// },
// new VirtualTreeContainer([
// {
// dirPath: join('main', 'default', 'labels'),
// children: [
// {
// name: 'OnlyLabel.label-meta.xml',
// data: Buffer.from(ONLY_LABEL_CONTENTS),
// },
// ],
// },
// ])
// );
//
// export const ONLY_LABEL_CMP_IN_ANOTHER_DIR_CMP = new SourceComponent(
// {
// name: 'OnlyLabel',
// type: customLabelType,
// xml: join('other', 'dir', 'labels', 'OnlyLabel.label-meta.xml'),
// },
// new VirtualTreeContainer([
// {
// dirPath: join('other', 'dir', 'labels'),
// children: [
// {
// name: 'OnlyLabel.label-meta.xml',
// data: Buffer.from(ONLY_LABEL_CONTENTS),
// },
// ],
// },
// ])
// );
//
// export const ONLY_LABEL_NO_DIR_CMP = new SourceComponent(
// {
// name: 'OnlyLabel',
// type: customLabelType,
// xml: 'OnlyLabel.label-meta.xml',
// },
// new VirtualTreeContainer([
// {
// dirPath: '',
// children: [
// {
// name: 'OnlyLabel.label-meta.xml',
// data: Buffer.from(ONLY_LABEL_CONTENTS),
// },
// ],
// },
// ])
// );
//
// export const OTHER_LABEL_CMP = new SourceComponent(
// {
// name: 'OtherLabel',
// type: customLabelType,
// xml: join('labels', 'OtherLabel.label-meta.xml'),
// },
// new VirtualTreeContainer([
// {
// dirPath: 'permissionSet',
// children: [
// {
// name: 'OtherLabel.label-meta.xml',
// data: Buffer.from(`<?xml version="1.0" encoding="UTF-8"?>
// <CustomLabel xmlns="http://soap.sforce.com/2006/04/metadata">
// <fullName>OtherLabel</fullName>
// <language>en_US</language>
// <protected>true</protected>
// <shortDescription>OtherLabel</shortDescription>
// <value>OtherLabel</value>
// </CustomLabel>`),
// },
// ],
// },
// ])
// );
25 changes: 25 additions & 0 deletions test/resolve/metadataResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ import {
MIXED_CONTENT_DIRECTORY_VIRTUAL_FS,
MIXED_CONTENT_DIRECTORY_XML_PATHS,
} from '../mock/type-constants/staticresourceConstant';
import {
SOURCE_FORMAT_PS,
regAcc as regAccPermissionSet,
} from '../mock/type-constants/decomposedPermissionSetConstant';
// import { THREE_CUSTOM_LABELS_CMP, regAcc as regAccCustomLabels } from '../mock/type-constants/decomposedCustomLabelsConstant';
import { META_XML_SUFFIX } from '../../src/common';
import { DE_METAFILE } from '../mock/type-constants/digitalExperienceBundleConstants';
import { RegistryTestUtil } from './registryTestUtil';
Expand Down Expand Up @@ -94,6 +99,7 @@ describe('MetadataResolver', () => {
expect(resolver.getComponentsFromPath(CONTENT_PATHS[0])).to.deep.equal([COMPONENTS[0]]);
});
});

describe('getComponentsFromPath', () => {
afterEach(() => testUtil.restore());

Expand Down Expand Up @@ -147,6 +153,25 @@ describe('MetadataResolver', () => {
expect(access.getComponentsFromPath(path)).to.deep.equal([matchingContentFile.COMPONENT]);
});

it('Should resolve decomposed permission set file to PermissionSet type', () => {
const resolver = new MetadataResolver(regAccPermissionSet, SOURCE_FORMAT_PS.tree);
const objectSettingsPath = join(
'main',
'default',
'permissionsets',
'myPS',
'objectSettings',
'Account.objectSettings-meta.xml'
);
const classAccessPath = join('main', 'default', 'permissionsets', 'myPS', 'myPS.classAccess-meta.xml');
const components = resolver.getComponentsFromPath(objectSettingsPath);
const components2 = resolver.getComponentsFromPath(classAccessPath);
expect(components).to.have.lengthOf(1);
expect(components[0].type.name).to.equal('PermissionSet');
expect(components2).to.have.lengthOf(1);
expect(components2[0].type.name).to.equal('PermissionSet');
});

it('Should determine type for metadata file with known suffix and strictDirectoryName', () => {
// CustomSite is an example. The conditions are:
// 1. Type has "strictDirectoryName": true
Expand Down
Loading