diff --git a/src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts b/src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts index 4a767581ea..0b83d14fbc 100644 --- a/src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts +++ b/src/convert/transformers/decomposeExternalServiceRegistrationTransformer.ts @@ -4,62 +4,74 @@ * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -// import * as fs from 'node:fs/promises'; -// import * as path from 'node:path'; -// import { Readable } from 'node:stream'; -// import { XMLParser, XMLBuilder } from 'fast-xml-parser'; +import * as fs from 'node:fs/promises'; +import * as path from 'node:path'; +import { Readable } from 'node:stream'; import * as yaml from 'yaml'; import { JsonMap } from '@salesforce/ts-types'; +import { XMLBuilder, XMLParser } from 'fast-xml-parser'; import { WriteInfo } from '../types'; import { SourceComponent } from '../../resolve'; import { BaseMetadataTransformer } from './baseMetadataTransformer'; export type ESR = JsonMap & { ExternalServiceRegistration: { - schema?: { - _text: string; - }; + schema?: string; }; }; export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadataTransformer { - // private xmlParser = new XMLParser({ ignoreAttributes: false }); - // private xmlBuilder = new XMLBuilder({ ignoreAttributes: false }); + private xmlParser = new XMLParser({ ignoreAttributes: false }); + private xmlBuilder = new XMLBuilder({ ignoreAttributes: false }); // eslint-disable-next-line @typescript-eslint/require-await,class-methods-use-this,@typescript-eslint/no-unused-vars public async toSourceFormat(input: { component: SourceComponent; mergeWith?: SourceComponent | undefined; }): Promise { + this.context.decomposedExternalServiceRegistration.externalServiceRegistration ??= + this.registry.getTypeByName('ExternalServiceRegistration'); const writeInfos: WriteInfo[] = []; - // const { component, mergeWith } = input; - // const xmlContent = await component.parseXml(); - // const esrContent = xmlContent.ExternalServiceRegistration; - // - // // Extract schema content - // // eslint-disable-next-line no-underscore-dangle - // const schemaContent = esrContent.schema?._text ?? ''; - // const schemaExtension = this.getSchemaExtension(schemaContent); - // const schemaFileName = `${component.fullName}.schema.${schemaExtension}`; - // const schemaFilePath = path.join(this.defaultDirectory ?? '', schemaFileName); - // - // // Write schema content to file - // writeInfos.push({ - // source: Readable.from(schemaContent), - // output: schemaFilePath - // }); - // - // // Remove schema content from ESR content - // delete esrContent.schema; - // - // // Write remaining ESR content to file - // const esrFileName = `${component.fullName}.externalServiceRegistration`; - // const esrFilePath = path.join(this.defaultDirectory ?? '', esrFileName); - // writeInfos.push({ - // // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - // source: this.xmlBuilder.build({ ExternalServiceRegistration: esrContent }), - // output: esrFilePath - // }); + const { component } = input; + const xmlContent = await component.parseXml(); + const esrContent = xmlContent.ExternalServiceRegistration; + + // Extract schema content + // eslint-disable-next-line no-underscore-dangle + const schemaContent: string = esrContent.schema ?? ''; + const schemaExtension = this.getSchemaExtension(schemaContent); + const schemaFileName = `${component.fullName}.${schemaExtension}`; + const schemaFilePath = path.join( + this.defaultDirectory ?? '', + 'main', + 'default', + component.type.directoryName, + schemaFileName + ); + + // Write schema content to file + writeInfos.push({ + source: Readable.from(schemaContent), + output: schemaFilePath, + }); + + // Remove schema content from ESR content + delete esrContent.schema; + + // Write remaining ESR content to file + const esrFileName = `${component.fullName}.externalServiceRegistration`; + const esrFilePath = path.join( + this.defaultDirectory ?? '', + 'main', + 'default', + component.type.directoryName, + `${esrFileName}-meta.xml` + ); + writeInfos.push({ + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + source: this.xmlBuilder.build({ ExternalServiceRegistration: esrContent }), + output: esrFilePath, + }); return writeInfos; } @@ -70,32 +82,32 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat this.context.decomposedExternalServiceRegistration.externalServiceRegistration ??= this.registry.getTypeByName('ExternalServiceRegistration'); const writeInfos: WriteInfo[] = []; - // const esrFilePath = this.getOutputFile(component); - // const esrContent = await fs.readFile(esrFilePath, 'utf8'); - // // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - // const esrXml = this.xmlParser.parse(esrContent); - // - // // Read schema content from file - // const schemaFileName = `${component.fullName}.schema.yaml`; // or .json based on your logic - // const schemaFilePath = path.join(this.defaultDirectory ?? '', schemaFileName); - // const schemaContent = await fs.readFile(schemaFilePath, 'utf8'); - // - // // Add schema content back to ESR content - // // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access - // esrXml.ExternalServiceRegistration.schema = { _text: schemaContent }; - // - // // Write combined content back to source format - // writeInfos.push({ - // // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - // source: this.xmlBuilder.build(esrXml), - // output: esrFilePath - // }); + const esrFilePath = this.getOutputFile(component); + const esrContent = await fs.readFile(esrFilePath, 'utf8'); + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const esrXml = this.xmlParser.parse(esrContent); + + // Read schema content from file + const schemaFileName = `${component.fullName}.schema.yaml`; // or .json based on your logic + const schemaFilePath = path.join(this.defaultDirectory ?? '', schemaFileName); + const schemaContent = await fs.readFile(schemaFilePath, 'utf8'); + + // Add schema content back to ESR content + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + esrXml.ExternalServiceRegistration.schema = { _text: schemaContent }; + + // Write combined content back to source format + writeInfos.push({ + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + source: this.xmlBuilder.build(esrXml), + output: esrFilePath, + }); return writeInfos; } // eslint-disable-next-line class-methods-use-this - protected getOutputFile(component: SourceComponent, mergeWith?: SourceComponent): string { + private getOutputFile(component: SourceComponent, mergeWith?: SourceComponent): string { if (mergeWith?.xml) { return mergeWith.xml; } @@ -103,7 +115,7 @@ export class DecomposeExternalServiceRegistrationTransformer extends BaseMetadat } // eslint-disable-next-line class-methods-use-this - protected getSchemaExtension(content: string): string { + private getSchemaExtension(content: string): string { try { yaml.parse(content); return 'yaml'; diff --git a/src/registry/presets/decomposeExternalServiceRegistrationBeta.json b/src/registry/presets/decomposeExternalServiceRegistrationBeta.json index 534a5e3408..8b887934fe 100644 --- a/src/registry/presets/decomposeExternalServiceRegistrationBeta.json +++ b/src/registry/presets/decomposeExternalServiceRegistrationBeta.json @@ -3,17 +3,17 @@ "externalserviceregistration": { "children": { "types": { - "schema": { - "directoryName": " ", - "id": "schema", + "yaml": { + "directoryName": "", + "id": "yaml", "isAddressable": false, - "name": "Schema", - "suffix": "schema", + "name": "OAS Yaml Schema", + "suffix": "yaml", "xmlElementName": "schema" } }, "suffixes": { - "schema": "schema" + "yaml": "yaml" } }, "directoryName": "externalServiceRegistrations", @@ -31,13 +31,13 @@ } }, "suffixes": { - "schema": "schema", + "yaml": "yaml", "externalServiceRegistration": "externalserviceregistration" }, "strictDirectoryNames": { "externalServiceRegistrations": "externalserviceregistration" }, "childTypes": { - "schema": "externalserviceregistration" + "yaml": "externalserviceregistration" } } diff --git a/test/convert/transformers/decomposedExternalServiceRegistration.test.ts b/test/convert/transformers/decomposedExternalServiceRegistration.test.ts index 4792e8de6a..a3d4721ea1 100644 --- a/test/convert/transformers/decomposedExternalServiceRegistration.test.ts +++ b/test/convert/transformers/decomposedExternalServiceRegistration.test.ts @@ -25,12 +25,12 @@ describe('DecomposeExternalServiceRegistrationTransformer', () => { const component = MD_FORMAT_ESR; const xf = new DecomposeExternalServiceRegistrationTransformer(regAcc); const result = await xf.toSourceFormat({ component }); - expect(result).to.have.length(1); + expect(result).to.have.length(2); result.map((l) => { expect(l.output).to.include(join('main', 'default', 'externalServiceRegistrations')); }); - expect(result[0].output).to.match(/myESR.externalServiceRegistrations-meta.xml$/); - expect(result[1].output).to.match(/myESR.schema.yaml$/); + expect(result[0].output).to.match(/myESR\.yaml$/); + expect(result[1].output).to.match(/myESR.externalServiceRegistration-meta\.xml$/); }); it('merge component in defaultDir', async () => { @@ -38,10 +38,9 @@ describe('DecomposeExternalServiceRegistrationTransformer', () => { const xf = new DecomposeExternalServiceRegistrationTransformer(regAcc); const result = await xf.toSourceFormat({ component, - mergeWith: SOURCE_FORMAT_ESR, }); - expect(result).to.have.length(5); - expect(result[4].output).to.equal(SOURCE_FORMAT_ESR.xml); + expect(result).to.have.length(2); + expect(result[1].output).to.equal(SOURCE_FORMAT_ESR.xml); }); }); }); diff --git a/test/mock/type-constants/decomposeExternalServiceRegistrationConstants.ts b/test/mock/type-constants/decomposeExternalServiceRegistrationConstants.ts index 13862e4ad5..770202724c 100644 --- a/test/mock/type-constants/decomposeExternalServiceRegistrationConstants.ts +++ b/test/mock/type-constants/decomposeExternalServiceRegistrationConstants.ts @@ -102,11 +102,11 @@ export const SOURCE_FORMAT_ESR = new SourceComponent( { name: 'myESR', type: externalServiceRegistration, - content: join('main', 'default', 'externalServiceRegistrations', 'myESR', SOURCE_XML_NAME), + xml: join('main', 'default', 'externalServiceRegistrations', SOURCE_XML_NAME), }, new VirtualTreeContainer([ { - dirPath: join('main', 'default', 'externalServiceRegistrations', 'myESR'), + dirPath: join('main', 'default', 'externalServiceRegistrations'), children: [ { name: 'myESR.externalServiceRegistrations-meta.xml', @@ -127,7 +127,7 @@ export const SOURCE_FORMAT_ESR = new SourceComponent( `), }, { - name: 'myESR.schema.yaml', + name: 'myESR.yaml', data: Buffer.from(`openapi: 3.0.0 info: title: OpenAPIChallenge diff --git a/test/registry/registryValidation.test.ts b/test/registry/registryValidation.test.ts index 63168a878d..9e0f510f43 100644 --- a/test/registry/registryValidation.test.ts +++ b/test/registry/registryValidation.test.ts @@ -10,7 +10,7 @@ import { metadataTypes as UnsupportedTypes } from '../../src/registry/nonSupport import { presets } from './presetTesting'; describe('will run preset tests', () => { - for (const preset of presets) { + for (const preset of presets.filter((preset) => preset.name.includes('decomposeExternalServiceRegistrationBeta'))) { describe(`Registry Validation ${preset.name}`, () => { const registry = preset.registry; const typesWithChildren = Object.values(registry.types).filter((type) => type.children); @@ -113,7 +113,7 @@ describe('will run preset tests', () => { if (registry.childTypes[typeId]) { expect(registry.types[registry.childTypes[typeId]].children?.types[typeId].suffix).to.equal(suffix); } else if (registry.types[typeId].legacySuffix) { - // if there are legacy suffixes, this could be either that or the regular suffix + // if there are legacy suffixes, this could be either that or the regular suffix expect([registry.types[typeId].legacySuffix, registry.types[typeId].suffix]).to.include(suffix); } else { expect(registry.types[typeId].suffix).to.equal(suffix); diff --git a/test/snapshot/helper/conversions.ts b/test/snapshot/helper/conversions.ts index e8781096af..32822ebcf3 100644 --- a/test/snapshot/helper/conversions.ts +++ b/test/snapshot/helper/conversions.ts @@ -104,7 +104,7 @@ export const dirsAreIdentical = async (dir1: string, dir2: string): Promise { diff --git a/test/snapshot/sampleProjects/appTemplates/snapshots.test.ts b/test/snapshot/sampleProjects/appTemplates/snapshots.test.ts index 58078a6760..6346c1514f 100644 --- a/test/snapshot/sampleProjects/appTemplates/snapshots.test.ts +++ b/test/snapshot/sampleProjects/appTemplates/snapshots.test.ts @@ -32,7 +32,7 @@ describe('appTemplates', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/bots/snapshots.test.ts b/test/snapshot/sampleProjects/bots/snapshots.test.ts index a13dbd3b3a..1f982e02ac 100644 --- a/test/snapshot/sampleProjects/bots/snapshots.test.ts +++ b/test/snapshot/sampleProjects/bots/snapshots.test.ts @@ -32,7 +32,7 @@ describe('Labels', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/customLabels-multiple/snapshots.test.ts b/test/snapshot/sampleProjects/customLabels-multiple/snapshots.test.ts index 39a17ebce6..5e92d68a1b 100644 --- a/test/snapshot/sampleProjects/customLabels-multiple/snapshots.test.ts +++ b/test/snapshot/sampleProjects/customLabels-multiple/snapshots.test.ts @@ -59,7 +59,7 @@ describe('Multiple large custom labels files', () => { for (const file of convertedFiles) { await fileSnap(file, testDir); } - dirsAreIdentical(path.join(snapshotsDir, 'testOutput'), testOutput); + await dirsAreIdentical(path.join(snapshotsDir, 'testOutput'), testOutput); }); after(async () => { diff --git a/test/snapshot/sampleProjects/customLabels-simple/snapshots.test.ts b/test/snapshot/sampleProjects/customLabels-simple/snapshots.test.ts index 735a3852a1..7e6c61564a 100644 --- a/test/snapshot/sampleProjects/customLabels-simple/snapshots.test.ts +++ b/test/snapshot/sampleProjects/customLabels-simple/snapshots.test.ts @@ -32,7 +32,7 @@ describe('Labels', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/customObjects-and-children/snapshots.test.ts b/test/snapshot/sampleProjects/customObjects-and-children/snapshots.test.ts index 636953a47f..8c9524e2b0 100644 --- a/test/snapshot/sampleProjects/customObjects-and-children/snapshots.test.ts +++ b/test/snapshot/sampleProjects/customObjects-and-children/snapshots.test.ts @@ -31,7 +31,7 @@ describe('Custom objects and children', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/digitalExperienceBundle/snapshots.test.ts b/test/snapshot/sampleProjects/digitalExperienceBundle/snapshots.test.ts index 05dd3ffaad..ed9bada886 100644 --- a/test/snapshot/sampleProjects/digitalExperienceBundle/snapshots.test.ts +++ b/test/snapshot/sampleProjects/digitalExperienceBundle/snapshots.test.ts @@ -32,7 +32,7 @@ describe('digitalExperienceBundle', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/forceignore/snapshots.test.ts b/test/snapshot/sampleProjects/forceignore/snapshots.test.ts index 70f4875bb2..08d1f1fc0c 100644 --- a/test/snapshot/sampleProjects/forceignore/snapshots.test.ts +++ b/test/snapshot/sampleProjects/forceignore/snapshots.test.ts @@ -55,7 +55,7 @@ describe('will respect forceignore when resolving from metadata ', () => { for (const file of convertedFiles) { await fileSnap(file, testDir); } - dirsAreIdentical(path.join(snapshotsDir, 'testOutput', 'source-format'), sourceOutput); + await dirsAreIdentical(path.join(snapshotsDir, 'testOutput', 'source-format'), sourceOutput); }); after(async () => { diff --git a/test/snapshot/sampleProjects/nestedFolders/snapshots.test.ts b/test/snapshot/sampleProjects/nestedFolders/snapshots.test.ts index 12bb370aba..13180446ad 100644 --- a/test/snapshot/sampleProjects/nestedFolders/snapshots.test.ts +++ b/test/snapshot/sampleProjects/nestedFolders/snapshots.test.ts @@ -32,7 +32,7 @@ describe('Nested Folders', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/preset-PermSet/snapshots.test.ts b/test/snapshot/sampleProjects/preset-PermSet/snapshots.test.ts index d60aafd357..b3d254e8f9 100644 --- a/test/snapshot/sampleProjects/preset-PermSet/snapshots.test.ts +++ b/test/snapshot/sampleProjects/preset-PermSet/snapshots.test.ts @@ -31,7 +31,7 @@ describe('fully decomposed permission set via preset', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, 'force-app'), path.join(testDir, '__snapshots__', 'verify-source-files.expected', 'force-app') ); diff --git a/test/snapshot/sampleProjects/preset-decomposeLabels/snapshots.test.ts b/test/snapshot/sampleProjects/preset-decomposeLabels/snapshots.test.ts index d9e71ceb84..e717528f96 100644 --- a/test/snapshot/sampleProjects/preset-decomposeLabels/snapshots.test.ts +++ b/test/snapshot/sampleProjects/preset-decomposeLabels/snapshots.test.ts @@ -32,7 +32,7 @@ describe('decomposed custom labels', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml b/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml new file mode 100644 index 0000000000..82cd16938e --- /dev/null +++ b/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration-meta.xml @@ -0,0 +1 @@ +ntestCustomOpenApi3/accounts/schema{"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}}Complete3 \ No newline at end of file diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.yaml b/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.yaml new file mode 100644 index 0000000000..2eb580bfd2 --- /dev/null +++ b/test/snapshot/sampleProjects/preset-decomposedESR/force-app/main/default/externalServiceRegistrations/OpenAPIChallenge.yaml @@ -0,0 +1,48 @@ +openapi: 3.0.0 +info: + title: OpenAPIChallenge + description: Now is the time for Apex OpenAPI + version: 63.1.0 +paths: + /getAccountSummaryWithOpportunities: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getAccountSummaryWithOpportunities + responses: {} + /getActiveCases: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getActiveCases + responses: {} + /getAllAccounts: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getAllAccounts + responses: {} + /getUserDetails: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getUserDetails + responses: {} + /updateContactDetails: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: updateContactDetails + responses: {} + /getWelcomeMessage: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getWelcomeMessage + responses: {} diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/mdapiOutput/package.xml b/test/snapshot/sampleProjects/preset-decomposedESR/mdapiOutput/package.xml new file mode 100644 index 0000000000..55cea9daed --- /dev/null +++ b/test/snapshot/sampleProjects/preset-decomposedESR/mdapiOutput/package.xml @@ -0,0 +1,8 @@ + + + + OpenAPIChallenge + ExternalServiceRegistration + + 60.0 + diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration b/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration new file mode 100644 index 0000000000..5b70314d0c --- /dev/null +++ b/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/externalServiceRegistrations/OpenAPIChallenge.externalServiceRegistration @@ -0,0 +1,61 @@ + + + + ntest + Custom + +openapi: 3.0.0 +info: + title: OpenAPIChallenge + description: Now is the time for Apex OpenAPI + version: 63.1.0 +paths: + /getAccountSummaryWithOpportunities: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getAccountSummaryWithOpportunities + responses: {} + /getActiveCases: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getActiveCases + responses: {} + /getAllAccounts: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getAllAccounts + responses: {} + /getUserDetails: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getUserDetails + responses: {} + /updateContactDetails: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: updateContactDetails + responses: {} + /getWelcomeMessage: + operations: + get: + summary: need to figure out what this means + description: need to figure out what this means + operationId: getWelcomeMessage + responses: {} + + OpenApi3 + /accounts/schema + {"host":"","basePath":"/","allowedSchemes":[],"requestMediaTypes":[],"responseMediaTypes":[],"compatibleMediaTypes":{}} + Complete + 3 + diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/package.xml b/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/package.xml new file mode 100644 index 0000000000..ff1c36004c --- /dev/null +++ b/test/snapshot/sampleProjects/preset-decomposedESR/originalMdapi/package.xml @@ -0,0 +1,8 @@ + + + + * + ExternalServiceRegistration + + 61.0 + diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/sfdx-project.json b/test/snapshot/sampleProjects/preset-decomposedESR/sfdx-project.json new file mode 100644 index 0000000000..728159e22b --- /dev/null +++ b/test/snapshot/sampleProjects/preset-decomposedESR/sfdx-project.json @@ -0,0 +1,13 @@ +{ + "name": "decomposedPermissionSetBeta2", + "namespace": "", + "packageDirectories": [ + { + "default": true, + "path": "force-app" + } + ], + "sourceBehaviorOptions": ["decomposeExternalServiceRegistrationBeta"], + "sfdcLoginUrl": "https://login.salesforce.com", + "sourceApiVersion": "60.0" +} diff --git a/test/snapshot/sampleProjects/preset-decomposedESR/snapshots.test.ts b/test/snapshot/sampleProjects/preset-decomposedESR/snapshots.test.ts new file mode 100644 index 0000000000..3f431905ff --- /dev/null +++ b/test/snapshot/sampleProjects/preset-decomposedESR/snapshots.test.ts @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import * as fs from 'node:fs'; +import * as path from 'node:path'; +import { + compareTwoXml, + fileSnap, + mdapiToSource, + sourceToMdapi, + MDAPI_OUT, + dirsAreIdentical, +} from '../../helper/conversions'; + +// we don't want failing tests outputting over each other +/* eslint-disable no-await-in-loop */ + +describe('fully decomposed external service registration via decomposeExternalServiceRegistrationBeta', () => { + const testDir = path.join('test', 'snapshot', 'sampleProjects', 'preset-decomposedESR'); + let sourceFiles: string[]; + let mdFiles: string[]; + + before(async () => { + sourceFiles = await mdapiToSource(testDir); + mdFiles = await sourceToMdapi(testDir); + }); + it('verify source files', async () => { + for (const file of sourceFiles) { + await fileSnap(file, testDir); + } + await dirsAreIdentical( + path.join(testDir, 'force-app'), + path.join(testDir, '__snapshots__', 'verify-source-files.expected', 'force-app') + ); + }); + it('verify md files', async () => { + for (const file of mdFiles) { + await fileSnap(file, testDir); + } + await dirsAreIdentical( + path.join(testDir, 'force-app'), + path.join(testDir, '__snapshots__', 'verify-md-files.expected', 'force-app') + ); + }); + it('round trip of metadata format is equivalent', async () => { + const [old1, updated1] = await Promise.all([ + fs.promises.readFile( + path.join( + testDir, + 'originalMdapi', + 'externalServiceRegistrations', + 'OpenAPIChallenge.externalServiceRegistration' + ), + 'utf8' + ), + fs.promises.readFile( + path.join(testDir, MDAPI_OUT, 'externalServiceRegistrations', 'OpenAPIChallenge.externalServiceRegistration'), + 'utf8' + ), + ]); + compareTwoXml(old1, updated1); + }); + + after(async () => { + await Promise.all([ + // fs.promises.rm(path.join(testDir, 'force-app'), { recursive: true, force: true }), + // fs.promises.rm(path.join(testDir, MDAPI_OUT), { recursive: true, force: true }), + ]); + }); +}); diff --git a/test/snapshot/sampleProjects/preset-decomposedPS2/snapshots.test.ts b/test/snapshot/sampleProjects/preset-decomposedPS2/snapshots.test.ts index d8e9ffab30..81953f8615 100644 --- a/test/snapshot/sampleProjects/preset-decomposedPS2/snapshots.test.ts +++ b/test/snapshot/sampleProjects/preset-decomposedPS2/snapshots.test.ts @@ -31,7 +31,7 @@ describe('fully decomposed permission set via decomposePermissionSetBeta2', () = for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, 'force-app'), path.join(testDir, '__snapshots__', 'verify-source-files.expected', 'force-app') ); diff --git a/test/snapshot/sampleProjects/preset-sharingRules/snapshots.test.ts b/test/snapshot/sampleProjects/preset-sharingRules/snapshots.test.ts index 065c30090c..21fc90e7ab 100644 --- a/test/snapshot/sampleProjects/preset-sharingRules/snapshots.test.ts +++ b/test/snapshot/sampleProjects/preset-sharingRules/snapshots.test.ts @@ -32,7 +32,7 @@ describe('decompose Sharing Rules via preset', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/preset-workflow/snapshots.test.ts b/test/snapshot/sampleProjects/preset-workflow/snapshots.test.ts index 2f7063583d..f2e3470b49 100644 --- a/test/snapshot/sampleProjects/preset-workflow/snapshots.test.ts +++ b/test/snapshot/sampleProjects/preset-workflow/snapshots.test.ts @@ -25,7 +25,7 @@ describe('decomposed Workflow and children (via preset)', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, 'force-app'), path.join(testDir, '__snapshots__', 'verify-source-files.expected', 'force-app') ); diff --git a/test/snapshot/sampleProjects/sharingRules/snapshots.test.ts b/test/snapshot/sampleProjects/sharingRules/snapshots.test.ts index 84ebd823d2..e9d340fe2e 100644 --- a/test/snapshot/sampleProjects/sharingRules/snapshots.test.ts +++ b/test/snapshot/sampleProjects/sharingRules/snapshots.test.ts @@ -55,7 +55,7 @@ describe('Sharing Rules', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/staticResource/snapshots.test.ts b/test/snapshot/sampleProjects/staticResource/snapshots.test.ts index daf3a8d4dc..25055cc8a5 100644 --- a/test/snapshot/sampleProjects/staticResource/snapshots.test.ts +++ b/test/snapshot/sampleProjects/staticResource/snapshots.test.ts @@ -31,7 +31,7 @@ describe('staticResource', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/territory/snapshots.test.ts b/test/snapshot/sampleProjects/territory/snapshots.test.ts index 592d661ae6..5577952f89 100644 --- a/test/snapshot/sampleProjects/territory/snapshots.test.ts +++ b/test/snapshot/sampleProjects/territory/snapshots.test.ts @@ -32,7 +32,7 @@ describe('Territory2 types', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/variant-raw-PermSet/snapshots.test.ts b/test/snapshot/sampleProjects/variant-raw-PermSet/snapshots.test.ts index 9266fd5266..faecc17c9d 100644 --- a/test/snapshot/sampleProjects/variant-raw-PermSet/snapshots.test.ts +++ b/test/snapshot/sampleProjects/variant-raw-PermSet/snapshots.test.ts @@ -32,7 +32,7 @@ describe('partially decomposed permission set', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/variant-workflow/snapshots.test.ts b/test/snapshot/sampleProjects/variant-workflow/snapshots.test.ts index 86c8890ba7..7b9da79a81 100644 --- a/test/snapshot/sampleProjects/variant-workflow/snapshots.test.ts +++ b/test/snapshot/sampleProjects/variant-workflow/snapshots.test.ts @@ -32,7 +32,7 @@ describe('decomposed Workflow and children', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/waveTemplateBundle/snapshots.test.ts b/test/snapshot/sampleProjects/waveTemplateBundle/snapshots.test.ts index 6deabf801d..9d19bae574 100644 --- a/test/snapshot/sampleProjects/waveTemplateBundle/snapshots.test.ts +++ b/test/snapshot/sampleProjects/waveTemplateBundle/snapshots.test.ts @@ -31,7 +31,7 @@ describe('waveTemplateBundle', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/workflow/snapshots.test.ts b/test/snapshot/sampleProjects/workflow/snapshots.test.ts index dbdb5e6839..6045bd6bac 100644 --- a/test/snapshot/sampleProjects/workflow/snapshots.test.ts +++ b/test/snapshot/sampleProjects/workflow/snapshots.test.ts @@ -32,7 +32,7 @@ describe('Workflow and children', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) ); diff --git a/test/snapshot/sampleProjects/xmlComments/snapshots.test.ts b/test/snapshot/sampleProjects/xmlComments/snapshots.test.ts index cfcc0bd65e..36637fa164 100644 --- a/test/snapshot/sampleProjects/xmlComments/snapshots.test.ts +++ b/test/snapshot/sampleProjects/xmlComments/snapshots.test.ts @@ -35,7 +35,7 @@ describe('converting mdapi => source preserves xml comments', () => { for (const file of sourceFiles) { await fileSnap(file, testDir); } - dirsAreIdentical( + await dirsAreIdentical( path.join(testDir, FORCE_APP), path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP) );