|
| 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 | +describe('DocumentRegistry', () => { |
| 7 | + describe('URL Validation', () => { |
| 8 | + // Helper function to make HTTP request and check if URL is accessible |
| 9 | + async function checkSalesforceUrlWithPuppeteer(url: string): Promise<boolean> { |
| 10 | + const browser = await puppeteer.launch({ headless: true }); // use true instead of 'new' |
| 11 | + const page = await browser.newPage(); |
| 12 | + try { |
| 13 | + await page.goto(url, { waitUntil: 'networkidle2', timeout: 15000 }); |
| 14 | + const content = await page.content(); |
| 15 | + const notFoundText = "couldn't find that page."; |
| 16 | + const isValid = !content.includes(notFoundText); |
| 17 | + await browser.close(); |
| 18 | + return isValid; |
| 19 | + } catch (error) { |
| 20 | + await browser.close(); |
| 21 | + Logger.info(`Error checking URL with Puppeteer: ${url}`); |
| 22 | + return true; |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + // Cache to avoid duplicate checks |
| 27 | + const urlCheckCache = new Map<string, boolean>(); |
| 28 | + |
| 29 | + // Test all URLs in the documentRegistry |
| 30 | + Object.entries(documentRegistry).forEach(([key, url]: [string, string]) => { |
| 31 | + it(`should have a valid URL for ${key}`, async function () { |
| 32 | + // Increase timeout for network requests |
| 33 | + this.timeout(15000); |
| 34 | + const isValid = urlCheckCache.has(url) ? urlCheckCache.get(url) : await checkSalesforceUrlWithPuppeteer(url); |
| 35 | + urlCheckCache.set(url, isValid); |
| 36 | + expect(isValid, `URL for ${key} (${url}) should be accessible`).to.be.true; |
| 37 | + }); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should have all required document registry entries', () => { |
| 41 | + const expectedKeys = [ |
| 42 | + 'errorNoOrgResults', |
| 43 | + 'couldNotDeactivateOmniProcesses', |
| 44 | + 'couldNotTruncate', |
| 45 | + 'couldNotTruncateOmnniProcess', |
| 46 | + 'invalidNameTypeSubtypeOrLanguage', |
| 47 | + 'invalidOrRepeatingOmniscriptElementNames', |
| 48 | + 'invalidDataRaptorName', |
| 49 | + 'duplicatedCardName', |
| 50 | + 'duplicatedDrName', |
| 51 | + 'duplicatedOSName', |
| 52 | + 'duplicatedName', |
| 53 | + 'errorWhileActivatingOs', |
| 54 | + 'errorWhileActivatingCard', |
| 55 | + 'errorWhileUploadingCard', |
| 56 | + 'errorWhileCreatingElements', |
| 57 | + 'allVersionsDescription', |
| 58 | + 'changeMessage', |
| 59 | + 'angularOSWarning', |
| 60 | + 'formulaSyntaxError', |
| 61 | + 'fileNoOmnistudioCalls', |
| 62 | + 'fileAlreadyImplementsCallable', |
| 63 | + 'inApexDrNameWillBeUpdated', |
| 64 | + 'fileUpdatedToAllowRemoteCalls', |
| 65 | + 'fileUpdatedToAllowCalls', |
| 66 | + 'fileImplementsVlocityOpenInterface', |
| 67 | + 'methodCallBundleNameUpdated', |
| 68 | + 'cardNameChangeMessage', |
| 69 | + 'authordNameChangeMessage', |
| 70 | + 'omniScriptNameChangeMessage', |
| 71 | + 'dataRaptorNameChangeMessage', |
| 72 | + 'integrationProcedureNameChangeMessage', |
| 73 | + 'integrationProcedureManualUpdateMessage', |
| 74 | + 'duplicateCardNameMessage', |
| 75 | + 'testURL', |
| 76 | + ]; |
| 77 | + |
| 78 | + expectedKeys.forEach((key) => { |
| 79 | + expect(documentRegistry).to.have.property(key); |
| 80 | + expect(documentRegistry[key]).to.be.a('string'); |
| 81 | + expect(documentRegistry[key]).to.match(/^https:\/\/help\.salesforce\.com/); |
| 82 | + }); |
| 83 | + }); |
| 84 | + }); |
| 85 | +}); |
0 commit comments