Skip to content

Commit 7f41b72

Browse files
authored
Merge pull request #328 from shaurabh-tiwari-git/linkValidationCTA
@W-18480490 - Call to Action link Validation
2 parents 3e3aa76 + e41ce8a commit 7f41b72

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"jsdom": "^25.0.0",
1919
"lodash.chunk": "^4.2.0",
2020
"open": "^8.4.2",
21+
"puppeteer": "^24.12.1",
2122
"shelljs": "^0.8.5",
2223
"tslib": "^2",
2324
"xmldom": "^0.6.0"
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import puppeteer from 'puppeteer';
2+
import { expect } from '@salesforce/command/lib/test';
3+
import { documentRegistry } from '../../../src/utils/constants/documentRegistry';
4+
import { Logger } from '../../../src/utils/logger';
5+
6+
// Dictionary mapping documentRegistry keys to their expected page titles
7+
const titles = {
8+
errorNoOrgResults: 'Run the Omnistudio Migration Tool',
9+
couldNotDeactivateOmniProcesses: 'Deactivate and Activate OmniScripts',
10+
couldNotTruncate: 'Embed an Omniscript in Another Omniscript',
11+
couldNotTruncateOmnniProcess: 'Embed an Omniscript in Another Omniscript',
12+
invalidNameTypeSubtypeOrLanguage: 'Omnistudio Naming Conventions',
13+
invalidOrRepeatingOmniscriptElementNames: 'Omnistudio Naming Conventions',
14+
invalidDataRaptorName: 'Omnistudio Naming Conventions',
15+
duplicatedCardName: 'Omnistudio Naming Conventions',
16+
duplicatedDrName: 'Omnistudio Naming Conventions',
17+
duplicatedOSName: 'Omnistudio Naming Conventions',
18+
duplicatedName: 'Omnistudio Naming Conventions',
19+
errorWhileActivatingOs: 'Activating Omniscripts',
20+
errorWhileActivatingCard: 'Activate and Publish a Flexcard',
21+
errorWhileUploadingCard: 'Activate and Publish a Flexcard',
22+
errorWhileCreatingElements: 'Omniscript Element Reference',
23+
allVersionsDescription: 'Migrate All Versions of OmniStudio Components',
24+
changeMessage: 'Omnistudio Naming Conventions',
25+
angularOSWarning: 'Convert an Angular Omniscript to an LWC Omniscript',
26+
formulaSyntaxError: 'Formulas and Functions',
27+
fileNoOmnistudioCalls: 'Callable Implementations',
28+
fileAlreadyImplementsCallable: 'Callable Implementations',
29+
inApexDrNameWillBeUpdated: 'Update References to Omnistudio Data Mappers from Apex After Migration',
30+
fileUpdatedToAllowRemoteCalls: 'Make a Long-Running Remote Call Using Omnistudio.OmniContinuation',
31+
fileUpdatedToAllowCalls: 'Make a Long-Running Remote Call Using Omnistudio.OmniContinuation',
32+
fileImplementsVlocityOpenInterface: 'VlocityOpenInterface',
33+
methodCallBundleNameUpdated: 'Updates to Omnistudio Custom Functions',
34+
cardNameChangeMessage: 'Omnistudio Naming Conventions',
35+
authordNameChangeMessage: 'Omnistudio Naming Conventions',
36+
omniScriptNameChangeMessage:
37+
'Update Omniscript Custom Lightning Web Components and Omniscript Elements Overridden with Customized Components',
38+
dataRaptorNameChangeMessage: 'Update References to Omnistudio Data Mappers from Apex After Migration',
39+
integrationProcedureNameChangeMessage: 'Update Integration Procedure Type and Subtype After Migration',
40+
integrationProcedureManualUpdateMessage: 'Update Integration Procedure Type and Subtype After Migration',
41+
duplicateCardNameMessage: 'Clone a Flexcard',
42+
};
43+
44+
describe('DocumentRegistry', () => {
45+
describe('URL Validation', () => {
46+
// Helper function to make HTTP request and check if URL is accessible
47+
async function checkSalesforceUrlWithPuppeteer(key: string, url: string): Promise<boolean> {
48+
const browser = await puppeteer.launch({ headless: true }); // use true instead of 'new'
49+
const page = await browser.newPage();
50+
try {
51+
await page.goto(url, { waitUntil: 'networkidle2', timeout: 15000 });
52+
const content = await page.content();
53+
const notFoundText = "couldn't find that page.";
54+
const isValid = !content.includes(notFoundText);
55+
if (!isValid) {
56+
Logger.error(`URL for ${key} (${url}) is not accessible`);
57+
}
58+
const isTitleValid = content.includes(titles[key]);
59+
if (!isTitleValid) {
60+
Logger.error(`The content of the page for ${key} (${url}) is not valid`);
61+
}
62+
await browser.close();
63+
return isValid && isTitleValid;
64+
} catch (error) {
65+
await browser.close();
66+
Logger.info(`Error checking URL with Puppeteer: ${url}`);
67+
return true;
68+
}
69+
}
70+
71+
// Cache to avoid duplicate checks
72+
const urlCheckCache = new Map<string, boolean>();
73+
74+
// Test all URLs in the documentRegistry
75+
Object.entries(documentRegistry).forEach(([key, url]: [string, string]) => {
76+
it(`should have a valid URL for ${key}`, async function () {
77+
// Increase timeout for network requests
78+
this.timeout(20000);
79+
const isValid = urlCheckCache.has(url)
80+
? urlCheckCache.get(url)
81+
: await checkSalesforceUrlWithPuppeteer(key, url);
82+
urlCheckCache.set(url, isValid);
83+
expect(isValid, `URL for ${key} (${url}) should be accessible`).to.be.true;
84+
});
85+
});
86+
87+
it('should have all required document registry entries', () => {
88+
const expectedKeys = [
89+
'errorNoOrgResults',
90+
'couldNotDeactivateOmniProcesses',
91+
'couldNotTruncate',
92+
'couldNotTruncateOmnniProcess',
93+
'invalidNameTypeSubtypeOrLanguage',
94+
'invalidOrRepeatingOmniscriptElementNames',
95+
'invalidDataRaptorName',
96+
'duplicatedCardName',
97+
'duplicatedDrName',
98+
'duplicatedOSName',
99+
'duplicatedName',
100+
'errorWhileActivatingOs',
101+
'errorWhileActivatingCard',
102+
'errorWhileUploadingCard',
103+
'errorWhileCreatingElements',
104+
'allVersionsDescription',
105+
'changeMessage',
106+
'angularOSWarning',
107+
'formulaSyntaxError',
108+
'fileNoOmnistudioCalls',
109+
'fileAlreadyImplementsCallable',
110+
'inApexDrNameWillBeUpdated',
111+
'fileUpdatedToAllowRemoteCalls',
112+
'fileUpdatedToAllowCalls',
113+
'fileImplementsVlocityOpenInterface',
114+
'methodCallBundleNameUpdated',
115+
'cardNameChangeMessage',
116+
'authordNameChangeMessage',
117+
'omniScriptNameChangeMessage',
118+
'dataRaptorNameChangeMessage',
119+
'integrationProcedureNameChangeMessage',
120+
'integrationProcedureManualUpdateMessage',
121+
'duplicateCardNameMessage',
122+
];
123+
124+
expectedKeys.forEach((key) => {
125+
expect(documentRegistry).to.have.property(key);
126+
expect(documentRegistry[key]).to.be.a('string');
127+
expect(documentRegistry[key]).to.match(/^https:\/\/help\.salesforce\.com/);
128+
});
129+
});
130+
});
131+
});

0 commit comments

Comments
 (0)