Skip to content

Commit

Permalink
fix: detection of CustomMetadata type (scolladon#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon authored Apr 22, 2024
1 parent b161622 commit 412592b
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 89 deletions.
28 changes: 27 additions & 1 deletion __tests__/unit/lib/metadata/MetadataRepositoryImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ describe('MetadataRepositoryImpl', () => {
suffix: 'app',
xmlName: 'CustomApplication',
},
{
directoryName: 'customMetadata',
inFolder: false,
metaFile: false,
suffix: 'md',
xmlName: 'CustomMetadata',
},
{
directoryName: 'documents',
inFolder: true,
Expand Down Expand Up @@ -228,6 +235,17 @@ describe('MetadataRepositoryImpl', () => {
})

describe('special cases where it should only match on folder', () => {
it('matches `md` files inside `customMetadata` folder', () => {
// Act
const result = sut.get(
'force-app/customMetadata/testCustomMetadata.md'
)

// Assert
expect(result).toStrictEqual(
expect.objectContaining({ directoryName: 'customMetadata' })
)
})
it('matches `xml` files inside `emailservices` folder', () => {
// Act
const result = sut.get('force-app/emailservices/testService.xml')
Expand Down Expand Up @@ -346,7 +364,7 @@ describe('MetadataRepositoryImpl', () => {
expect(result).toBeUndefined()
})

it('matches on folder', () => {
it('does not match `app` files outside `applications` folder', () => {
// Act
const result = sut.get(
'Z force-app/main/folder/aura/TestApp/TestApp.app'
Expand All @@ -357,6 +375,14 @@ describe('MetadataRepositoryImpl', () => {
expect.objectContaining({ directoryName: 'aura' })
)
})

it('does not match `md` files outside `customMetadata` folder', () => {
// Act
const result = sut.get('README.md')

// Assert
expect(result).toBeUndefined()
})
})
})

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"author": "Sebastien Colladon <colladonsebastien@gmail.com>",
"dependencies": {
"@salesforce/command": "^5.3.9",
"@salesforce/core": "^7.3.0",
"@salesforce/core": "^7.3.1",
"async": "^3.2.5",
"fast-xml-parser": "^4.3.6",
"fs-extra": "^11.2.0",
Expand Down Expand Up @@ -178,7 +178,7 @@
"@commitlint/config-conventional": "^19.2.2",
"@jest/globals": "^29.7.0",
"@oclif/dev-cli": "^1.26.10",
"@salesforce/cli-plugins-testkit": "^5.2.1",
"@salesforce/cli-plugins-testkit": "^5.2.3",
"@salesforce/dev-config": "^4.1.0",
"@salesforce/ts-sinon": "^1.4.19",
"@stryker-mutator/core": "^8.2.6",
Expand All @@ -188,8 +188,8 @@
"@types/jest": "^29.5.12",
"@types/mocha": "^10.0.6",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"benchmark": "^2.1.4",
"chai": "^4.3.10",
"eslint": "^8.57.0",
Expand Down
3 changes: 2 additions & 1 deletion src/constant/metadataConstants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'
export const CUSTOM_APPLICATION_SUFFIX = 'app'
export const EMAILSERVICESFUNCTION_SUFFIX = 'xml'
export const CUSTOM_METADATA_SUFFIX = 'md'
export const EMAIL_SERVICES_FUNCTION_SUFFIX = 'xml'
export const FIELD_DIRECTORY_NAME = 'fields'
export const FLOW_XML_NAME = 'Flow'
export const INFOLDER_SUFFIX = `Folder`
Expand Down
6 changes: 4 additions & 2 deletions src/metadata/MetadataRepositoryImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { parse } from 'path'
import { DOT, PATH_SEP } from '../constant/fsConstants'
import {
CUSTOM_APPLICATION_SUFFIX,
EMAILSERVICESFUNCTION_SUFFIX,
CUSTOM_METADATA_SUFFIX,
EMAIL_SERVICES_FUNCTION_SUFFIX,
METAFILE_SUFFIX,
OBJECT_TRANSLATION_TYPE,
OBJECT_TYPE,
Expand Down Expand Up @@ -129,7 +130,8 @@ export class MetadataRepositoryImpl implements MetadataRepository {

private static UNSAFE_EXTENSION = new Set([
CUSTOM_APPLICATION_SUFFIX,
EMAILSERVICESFUNCTION_SUFFIX,
EMAIL_SERVICES_FUNCTION_SUFFIX,
CUSTOM_METADATA_SUFFIX,
])

private static COMPOSED_TYPES = new Set([
Expand Down
Loading

0 comments on commit 412592b

Please sign in to comment.