cypress/e2e/specialFeatures/scriptSwitching/index.cy.js
import config from '../../../support/config/services';
import appConfig from '../../../../src/server/utilities/serviceConfigs';
import getPaths from '../../../support/helpers/getPaths';
import serviceHasPageType from '../../../support/helpers/serviceHasPageType';
import testsForCanonicalOnly from './testsForCanonicalOnly';
import testsForAMPOnly from './testsForAMPOnly';
const hasVariant = serviceName => {
return config[serviceName] && config[serviceName].variant !== 'default';
};
Object.keys(config)
.filter(hasVariant)
.forEach(serviceId => {
const { variant } = config[serviceId];
const serviceName = config[serviceId].name;
const { scriptLink } = appConfig[serviceName][variant];
const scriptLinkVariant = scriptLink && scriptLink.variant;
Object.keys(config[serviceId].pageTypes)
.filter(
pageType =>
serviceHasPageType(serviceId, pageType) &&
!pageType.includes('error'),
)
.forEach(pageType => {
const paths = getPaths(serviceId, pageType);
paths.forEach(path => {
testsForCanonicalOnly({
serviceId,
serviceName,
pageType,
path,
variant,
scriptLinkVariant,
});
});
paths
.map(path => `${path}.amp`)
.forEach(path => {
testsForAMPOnly({
serviceName,
pageType,
path,
});
});
});
});