From 823966e8e003151c97700a397d467a794794e902 Mon Sep 17 00:00:00 2001 From: Steve Hetzel Date: Fri, 1 Apr 2022 16:13:00 -0600 Subject: [PATCH] fix: resolve strictDirectoryName types in mdapi format (#601) * fix: resolve strictDirectoryName types in mdapi format * chore: adding types for SDR * fix: add test for EmailServicesFunction Co-authored-by: Willie Ruemmele --- METADATA_SUPPORT.md | 5 +-- src/resolve/metadataResolver.ts | 4 +- test/resolve/metadataResolver.test.ts | 55 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/METADATA_SUPPORT.md b/METADATA_SUPPORT.md index 5fae33be63..20734954eb 100644 --- a/METADATA_SUPPORT.md +++ b/METADATA_SUPPORT.md @@ -499,8 +499,6 @@ v55 introduces the following new types. Here's their current level of support |ExpressionSetDefinition|✅|| |ExpressionSetDefinitionVersion|✅|| |ExternalDataSrcDescriptor|❌|Not supported, but support could be added| -|ExternalDataTranField|❌|Not supported, but support could be added| -|ExternalDataTranObject|❌|Not supported, but support could be added| |FlowTest|✅|| |ForecastingFilter|❌|Not supported, but support could be added| |ForecastingFilterCondition|❌|Not supported, but support could be added| @@ -511,10 +509,11 @@ v55 introduces the following new types. Here's their current level of support |MessagingChannel|undefined|undefined| |PaymentsManagementEnabledSettings|✅|| |RegisteredExternalService|❌|Not supported, but support could be added| -|SchedulingObjective|❌|Not supported, but support could be added| +|SchedulingObjective|undefined|undefined| |StreamingAppDataConnector|❌|Not supported, but support could be added| |SubscriptionManagementSettings|✅|| |VoiceSettings|✅|| +|WarrantyLifecycleMgmtSettings|✅|| ## Additional Types diff --git a/src/resolve/metadataResolver.ts b/src/resolve/metadataResolver.ts index a3423fbace..53ead0b320 100644 --- a/src/resolve/metadataResolver.ts +++ b/src/resolve/metadataResolver.ts @@ -174,8 +174,8 @@ export class MetadataResolver { // any of the following 3 options is considered a good match // mixedContent and bundles don't have a suffix to match ['mixedContent', 'bundle'].includes(type.strategies?.adapter) || - // the suffix matches the type we think it is - (type.suffix && fsPath.endsWith(`${type.suffix}${META_XML_SUFFIX}`)) || + // the file suffix (in source or mdapi format) matches the type suffix we think it is + (type.suffix && [type.suffix, `${type.suffix}${META_XML_SUFFIX}`].some((s) => fsPath.endsWith(s))) || // the type has children and the path also includes THAT directory (type.children?.types && Object.values(type.children?.types) diff --git a/test/resolve/metadataResolver.test.ts b/test/resolve/metadataResolver.test.ts index 436d7fb8ec..501095e995 100644 --- a/test/resolve/metadataResolver.test.ts +++ b/test/resolve/metadataResolver.test.ts @@ -142,6 +142,61 @@ describe('MetadataResolver', () => { expect(access.getComponentsFromPath(path)).to.deep.equal([matchingContentFile.COMPONENT]); }); + it('Should determine type for metadata file with known suffix and strictDirectoryName', () => { + // CustomSite is an example. The conditions are: + // 1. Type has "strictDirectoryName": true + // 2. Type strategy adapter is neither "mixedContent" nor "bundle" + // 3. Type doesn't have children + // 4. mdapi format file path (E_Bikes.site) + const path = join('unpackaged', 'sites', 'E_Bikes.site'); + const treeContainer = VirtualTreeContainer.fromFilePaths([path]); + const mdResolver = new MetadataResolver(undefined, treeContainer); + const expectedComponent = new SourceComponent( + { + name: 'E_Bikes', + type: registry.types.customsite, + xml: path, + }, + treeContainer + ); + expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]); + }); + + it('Should determine type for source file with known suffix and strictDirectoryName', () => { + // CustomSite is an example. The conditions are: + // 1. Type has "strictDirectoryName": true + // 2. Type strategy adapter is neither "mixedContent" nor "bundle" + // 3. Type doesn't have children + // 4. source format file path (E_Bikes.site-meta.xml) + const path = join('unpackaged', 'sites', 'E_Bikes.site-meta.xml'); + const treeContainer = VirtualTreeContainer.fromFilePaths([path]); + const mdResolver = new MetadataResolver(undefined, treeContainer); + const expectedComponent = new SourceComponent( + { + name: 'E_Bikes', + type: registry.types.customsite, + xml: path, + }, + treeContainer + ); + expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]); + }); + + it('Should determine type for EmailServicesFunction metadata file (mdapi format)', () => { + const path = join('unpackaged', 'emailservices', 'MyEmailServices.xml'); + const treeContainer = VirtualTreeContainer.fromFilePaths([path]); + const mdResolver = new MetadataResolver(undefined, treeContainer); + const expectedComponent = new SourceComponent( + { + name: 'MyEmailServices', + type: registry.types.emailservicesfunction, + xml: path, + }, + treeContainer + ); + expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]); + }); + it('Should determine type for path of mixed content type', () => { const path = mixedContentDirectory.MIXED_CONTENT_DIRECTORY_SOURCE_PATHS[1]; const access = testUtil.createMetadataResolver([