forked from salesforcecli/plugin-omnistudio-migration-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumentRegistry.test.ts
More file actions
140 lines (133 loc) · 5.63 KB
/
documentRegistry.test.ts
File metadata and controls
140 lines (133 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { execSync } from 'child_process';
import puppeteer from 'puppeteer';
import { expect } from 'chai';
import { documentRegistry } from '../../../src/utils/constants/documentRegistry';
import { Logger } from '../../../src/utils/logger';
// Ensure Chrome is installed before running tests
before(function () {
this.timeout(120000); // 2 minutes for Chrome installation
if (process.env.CI === 'true') {
try {
Logger.info('CI environment detected. Installing Chrome for Puppeteer...');
execSync('npx --yes puppeteer browsers install chrome', { stdio: 'inherit' });
Logger.info('Chrome installed successfully.');
} catch (error) {
Logger.error('Failed to install Chrome:', error);
throw error;
}
}
});
// Dictionary mapping documentRegistry keys to their expected page titles
const titles = {
invalidOrRepeatingOmniscriptElementNames: 'Omnistudio Naming Conventions',
duplicatedCardName: 'Omnistudio Naming Conventions',
duplicatedDrName: 'Omnistudio Naming Conventions',
duplicatedOSName: 'Omnistudio Naming Conventions',
duplicatedName: 'Omnistudio Naming Conventions',
errorWhileActivatingOs: 'Activating Omniscripts',
errorWhileActivatingCard: 'Activate and Publish a Flexcard',
errorWhileUploadingCard: 'Activate and Publish a Flexcard',
angularOSWarning: 'Convert an Angular Omniscript to an LWC Omniscript',
formulaSyntaxError: 'Formulas and Functions',
fileNoOmnistudioCalls: 'Callable Implementations',
cardNameChangeMessage: 'Omnistudio Naming Conventions',
omniScriptNameChangeMessage:
'Update Omniscript Custom Lightning Web Components and Omniscript Elements Overridden with Customized Components',
dataRaptorNameChangeMessage: 'Update References to Omnistudio Components After Migration',
integrationProcedureNameChangeMessage: 'Update References to Omnistudio Components After Migration',
integrationProcedureManualUpdateMessage: 'Update References to Omnistudio Components After Migration',
duplicateCardNameMessage: 'Clone a Flexcard',
reservedKeysFoundInPropertySet: 'Omnistudio Naming Conventions',
manualDeploymentSteps: 'Set Up Your Environment to Customize Omniscript Elements',
customLabelMigrationErrorMessage: 'Omnistudio Migration Prerequisites',
};
describe('DocumentRegistry', () => {
describe('URL Validation', () => {
// Helper function to make HTTP request and check if URL is accessible
async function checkSalesforceUrlWithPuppeteer(key: string, url: string): Promise<boolean> {
try {
const browser = await puppeteer.launch({
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-accelerated-2d-canvas',
'--no-first-run',
'--no-zygote',
'--disable-gpu',
],
});
const page = await browser.newPage();
try {
await page.goto(url, { waitUntil: 'networkidle2', timeout: 30000 });
const content = await page.content();
const notFoundText = "couldn't find that page.";
const isValid = !content.includes(notFoundText);
if (!isValid) {
Logger.error(`URL for ${key} (${url}) is not accessible`);
}
const isTitleValid = content.includes(titles[key]);
if (!isTitleValid) {
Logger.error(`The content of the page for ${key} (${url}) is not valid`);
}
await browser.close();
return isValid && isTitleValid;
} catch (error) {
await browser.close();
Logger.info(`Error checking URL with Puppeteer: ${url}`);
return true;
}
} catch (error) {
if (error instanceof Error && error.message.includes('Failed to launch')) {
Logger.warn('Puppeteer failed to launch - skipping URL validation tests');
return true; // Skip test gracefully
}
throw error;
}
}
// Cache to avoid duplicate checks
const urlCheckCache = new Map<string, boolean>();
// Test all URLs in the documentRegistry
Object.entries(documentRegistry).forEach(([key, url]: [string, string]) => {
it(`should have a valid URL for ${key}`, async function () {
// Increase timeout for network requests
this.timeout(30000);
const isValid = urlCheckCache.has(url)
? urlCheckCache.get(url)
: await checkSalesforceUrlWithPuppeteer(key, url);
urlCheckCache.set(url, isValid);
expect(isValid, `URL for ${key} (${url}) should be accessible`).to.be.true;
});
});
it('should have all required document registry entries', () => {
const expectedKeys = [
'invalidOrRepeatingOmniscriptElementNames',
'duplicatedCardName',
'duplicatedDrName',
'duplicatedOSName',
'duplicatedName',
'errorWhileActivatingOs',
'errorWhileActivatingCard',
'errorWhileUploadingCard',
'angularOSWarning',
'formulaSyntaxError',
'fileNoOmnistudioCalls',
'cardNameChangeMessage',
'omniScriptNameChangeMessage',
'dataRaptorNameChangeMessage',
'integrationProcedureNameChangeMessage',
'integrationProcedureManualUpdateMessage',
'duplicateCardNameMessage',
'reservedKeysFoundInPropertySet',
'manualDeploymentSteps',
'customLabelMigrationErrorMessage',
];
expectedKeys.forEach((key) => {
expect(documentRegistry).to.have.property(key);
expect(documentRegistry[key]).to.be.a('string');
expect(documentRegistry[key]).to.match(/^https:\/\/help\.salesforce\.com/);
});
});
});
});