Skip to content

Commit f2110d5

Browse files
Wr/double deb retrieve W-18057369 (#1546)
* test: add test for TDD * test: undo formatting change * fix: fix doubly retrieved DEB * test: undo file snap and remove projects * fix: restore deleted snapshot files * chore: realize is path.sep, not os.EOL
1 parent 549409b commit f2110d5

File tree

5 files changed

+144
-1
lines changed
  • src/convert/transformers
  • test/snapshot/sampleProjects/digitalExperienceBundle
    • __snapshots__
      • verify-md-files.expected/digitalExperiences/site/Capricorn_Coffee_A1/sfdc_cms__view/tooManyRequests/tablet
      • verify-source-files.expected/force-app/main/default/digitalExperiences/site/Capricorn_Coffee_A1/sfdc_cms__view/tooManyRequests/tablet
    • originalMdapi/digitalExperiences/site/Capricorn_Coffee_A1/sfdc_cms__view/tooManyRequests/tablet

5 files changed

+144
-1
lines changed

src/convert/transformers/defaultMetadataTransformer.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import { basename, dirname, join } from 'node:path';
8+
import fs from 'node:fs';
9+
import { sep } from 'node:path';
810
import { Messages } from '@salesforce/core/messages';
911
import { Lifecycle } from '@salesforce/core/lifecycle';
1012
import { SourcePath } from '../../common/types';
@@ -75,7 +77,19 @@ const getContentSourceDestination = (
7577
if (component.content && component.tree.isDirectory(component.content)) {
7678
// DEs are always inside a dir.
7779
if (component.type.strategies?.adapter === 'digitalExperience') {
78-
return join(mergeWith.content, basename(source));
80+
const parts = source.split(sep);
81+
const file = parts.pop() ?? '';
82+
const dir = join(mergeWith.content, parts.pop() ?? '');
83+
if (
84+
source.endsWith('content.json') ||
85+
source.endsWith('_meta.json') ||
86+
!(fs.existsSync(dir) && fs.statSync(dir).isDirectory())
87+
) {
88+
return join(mergeWith.content, basename(source));
89+
} else {
90+
// if a directory exists with the same name as source, merge into there
91+
return join(dir, file);
92+
}
7993
} else {
8094
const relative = trimUntil(source, basename(component.content));
8195
return join(dirname(mergeWith.content), relative);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"type" : "sfdc_cms__view",
3+
"title" : "Wishlist",
4+
"contentBody" : {
5+
"component" : {
6+
"children" : [ {
7+
"attributes" : {
8+
"dxpStyle" : {
9+
"padding" : {
10+
"bottom" : "0.5rem",
11+
"left" : "0.75rem",
12+
"right" : "0.75rem",
13+
"top" : "0.5rem"
14+
}
15+
}
16+
},
17+
"id" : "0d365a1d-3438-4942-a071-8d1e6ad79108"
18+
} ]
19+
}
20+
},
21+
"urlName" : "wishlist"
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"type" : "sfdc_cms__view",
3+
"title" : "Wishlist",
4+
"contentBody" : {
5+
"component" : {
6+
"children" : [ {
7+
"attributes" : {
8+
"dxpStyle" : {
9+
"padding" : {
10+
"bottom" : "0.5rem",
11+
"left" : "0.75rem",
12+
"right" : "0.75rem",
13+
"top" : "0.5rem"
14+
}
15+
}
16+
},
17+
"id" : "0d365a1d-3438-4942-a071-8d1e6ad79108"
18+
} ]
19+
}
20+
},
21+
"urlName" : "wishlist"
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"type" : "sfdc_cms__view",
3+
"title" : "Wishlist",
4+
"contentBody" : {
5+
"component" : {
6+
"children" : [ {
7+
"attributes" : {
8+
"dxpStyle" : {
9+
"padding" : {
10+
"bottom" : "0.5rem",
11+
"left" : "0.75rem",
12+
"right" : "0.75rem",
13+
"top" : "0.5rem"
14+
}
15+
}
16+
},
17+
"id" : "0d365a1d-3438-4942-a071-8d1e6ad79108"
18+
} ]
19+
}
20+
},
21+
"urlName" : "wishlist"
22+
}

test/snapshot/sampleProjects/digitalExperienceBundle/snapshots.test.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import * as fs from 'node:fs';
88
import * as path from 'node:path';
9+
import { expect } from 'chai';
910
import {
1011
FORCE_APP,
1112
MDAPI_OUT,
@@ -14,6 +15,7 @@ import {
1415
mdapiToSource,
1516
sourceToMdapi,
1617
} from '../../helper/conversions';
18+
import { ComponentSetBuilder, MetadataConverter, RegistryAccess } from '../../../../src';
1719

1820
// we don't want failing tests outputting over each other
1921
/* eslint-disable no-await-in-loop */
@@ -37,6 +39,67 @@ describe('digitalExperienceBundle', () => {
3739
path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP)
3840
);
3941
});
42+
43+
it('verifies source files after two conversions', async () => {
44+
// reads all files in a directory recursively
45+
function getAllFiles(dirPath: string, fileList: string[] = []): string[] {
46+
const files = fs.readdirSync(dirPath);
47+
48+
for (const file of files) {
49+
const filePath = path.join(dirPath, file);
50+
const stat = fs.statSync(filePath);
51+
52+
if (stat.isDirectory()) {
53+
getAllFiles(filePath, fileList); // Recursive call for subdirectories
54+
} else {
55+
fileList.push(filePath);
56+
}
57+
}
58+
59+
return fileList;
60+
}
61+
62+
// should contain correct file path, e.g. DEB/../tablet/tablet.json
63+
const fileList = getAllFiles(path.join(testDir, FORCE_APP));
64+
65+
await dirsAreIdentical(
66+
path.join(testDir, FORCE_APP),
67+
path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP)
68+
);
69+
70+
// build a new CS from the freshly-converted source-format metadata
71+
const cs = await ComponentSetBuilder.build({
72+
sourcepath: [path.join(testDir, 'originalMdapi')],
73+
projectDir: testDir,
74+
});
75+
const registry = new RegistryAccess(undefined, testDir);
76+
const converter = new MetadataConverter(registry);
77+
78+
// converts metadata format DEB into source-format, with a mergeWith option, merging into force-app
79+
await converter.convert(
80+
cs,
81+
'source', // loads custom registry if there is one
82+
{
83+
type: 'merge',
84+
mergeWith: (
85+
await ComponentSetBuilder.build({
86+
sourcepath: [path.join(testDir, 'force-app')],
87+
projectDir: testDir,
88+
})
89+
).getSourceComponents(),
90+
defaultDirectory: path.join(testDir, 'force-app'),
91+
}
92+
);
93+
94+
// this, currently, will have the incorrect file, DEB/.../tablet.json
95+
const fileList2 = getAllFiles(path.join(testDir, FORCE_APP));
96+
expect(fileList2).to.deep.equal(fileList);
97+
98+
await dirsAreIdentical(
99+
path.join(testDir, FORCE_APP),
100+
path.join(testDir, '__snapshots__', 'verify-source-files.expected', FORCE_APP)
101+
);
102+
});
40103
it('verify md files', async () => {
41104
for (const file of mdFiles) {
42105
await fileSnap(file, testDir);

0 commit comments

Comments
 (0)