Skip to content

Commit 1be8b10

Browse files
committed
test: update tests for web_app hash computation
- Fix manifest.json test: only webapp.json is manifest, not manifest.json - Update child file tests: getComponent returns bundle, hashes computed in deploy/retrieve - Update metadataApiDeploy test: expect hashed fullName format
1 parent 63669d4 commit 1be8b10

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

test/client/metadataApiDeploy.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,11 +1260,12 @@ describe('MetadataApiDeploy', () => {
12601260
filePath: bundlePath,
12611261
});
12621262

1263-
// Remaining responses should be DigitalExperience child files
1263+
// Remaining responses should be DigitalExperience child files with hashed names
12641264
const childResponses = responses.slice(1);
12651265
childResponses.forEach((response) => {
12661266
expect(response.type).to.equal('DigitalExperience');
1267-
expect(response.fullName).to.match(/^web_app\/zenith\//);
1267+
// Hash format: web_app/zenith.<contentType>/m<hash>
1268+
expect(response.fullName).to.match(/^web_app\/zenith\.sfdc_cms__webApplicationAsset\/m[a-f0-9]{39}$/);
12681269
expect(response.state).to.equal(ComponentStatus.Created);
12691270
});
12701271
});

test/resolve/adapters/digitalExperienceSourceAdapter.test.ts

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,15 @@ describe('DigitalExperienceSourceAdapter', () => {
290290
expect(computeWebAppHashedName(manifestFile, bundleDir)).to.include('sfdc_cms__webApplicationAsset');
291291
});
292292

293-
it('should use correct content type for manifest.json', () => {
293+
it('should use correct content type for json files (only webapp.json is manifest)', () => {
294294
const manifestFile = join('path', 'to', 'digitalExperiences', 'web_app', 'dist2', 'manifest.json');
295+
const webappJsonFile = join('path', 'to', 'digitalExperiences', 'web_app', 'dist2', 'webapp.json');
295296
const otherJsonFile = join('path', 'to', 'digitalExperiences', 'web_app', 'dist2', 'config.json');
296297
const bundleDir = join('path', 'to', 'digitalExperiences', 'web_app', 'dist2');
297298

298-
expect(computeWebAppHashedName(manifestFile, bundleDir)).to.include('sfdc_cms__webApplicationManifest');
299+
// Only webapp.json is treated as manifest, manifest.json is a regular asset
300+
expect(computeWebAppHashedName(webappJsonFile, bundleDir)).to.include('sfdc_cms__webApplicationManifest');
301+
expect(computeWebAppHashedName(manifestFile, bundleDir)).to.include('sfdc_cms__webApplicationAsset');
299302
expect(computeWebAppHashedName(otherJsonFile, bundleDir)).to.include('sfdc_cms__webApplicationAsset');
300303
});
301304
});
@@ -307,40 +310,29 @@ describe('DigitalExperienceSourceAdapter', () => {
307310

308311
const webappTree = VirtualTreeContainer.fromFilePaths([WEBAPP_ICON_FILE, WEBAPP_404_FILE]);
309312

310-
assert(registry.types.digitalexperiencebundle.children?.types.digitalexperience);
311-
const webappChildAdapter = new DigitalExperienceSourceAdapter(
312-
registry.types.digitalexperiencebundle.children.types.digitalexperience,
313+
// Use the bundle type adapter since web_app files are resolved as part of the bundle
314+
const webappBundleAdapter = new DigitalExperienceSourceAdapter(
315+
registry.types.digitalexperiencebundle,
313316
registryAccess,
314317
forceIgnore,
315318
webappTree
316319
);
317320

318-
it('should create child component with hashed name for nested file', () => {
319-
const component = webappChildAdapter.getComponent(WEBAPP_ICON_FILE);
321+
it('should resolve nested file to bundle component', () => {
322+
// For web_app bundles, getComponent returns the bundle for individual files
323+
// The hashed child names are computed during deploy/retrieve FileResponse generation
324+
const component = webappBundleAdapter.getComponent(WEBAPP_ICON_FILE);
320325
expect(component).to.not.be.undefined;
321-
expect(component?.type.name).to.equal('DigitalExperience');
322-
323-
// Verify hashed name format - hash is computed from FULL path 'web_app/dist2/assets/icon.png'
324-
const expectedHash = createHash('sha256').update('web_app/dist2/assets/icon.png', 'utf8').digest('hex').substring(0, 39);
325-
expect(component?.fullName).to.equal(`web_app/dist2.sfdc_cms__image/m${expectedHash}`);
326-
327-
// Verify parent
328-
expect(component?.parent?.type.name).to.equal('DigitalExperienceBundle');
329-
expect(component?.parent?.fullName).to.equal('web_app/dist2');
326+
expect(component?.type.name).to.equal('DigitalExperienceBundle');
327+
expect(component?.fullName).to.equal('web_app/dist2');
330328
});
331329

332-
it('should create child component with hashed name for root file', () => {
333-
const component = webappChildAdapter.getComponent(WEBAPP_404_FILE);
330+
it('should resolve root file to bundle component', () => {
331+
// For web_app bundles, getComponent returns the bundle for individual files
332+
const component = webappBundleAdapter.getComponent(WEBAPP_404_FILE);
334333
expect(component).to.not.be.undefined;
335-
expect(component?.type.name).to.equal('DigitalExperience');
336-
337-
// Verify hashed name format - hash is computed from FULL path 'web_app/dist2/404.html'
338-
const expectedHash = createHash('sha256').update('web_app/dist2/404.html', 'utf8').digest('hex').substring(0, 39);
339-
expect(component?.fullName).to.equal(`web_app/dist2.sfdc_cms__webApplicationAsset/m${expectedHash}`);
340-
341-
// Verify parent
342-
expect(component?.parent?.type.name).to.equal('DigitalExperienceBundle');
343-
expect(component?.parent?.fullName).to.equal('web_app/dist2');
334+
expect(component?.type.name).to.equal('DigitalExperienceBundle');
335+
expect(component?.fullName).to.equal('web_app/dist2');
344336
});
345337
});
346338
});

0 commit comments

Comments
 (0)