diff --git a/src/app/routes/utils/regex/index.test.js b/src/app/routes/utils/regex/index.test.js index 510f07001e9..be48f59075a 100644 --- a/src/app/routes/utils/regex/index.test.js +++ b/src/app/routes/utils/regex/index.test.js @@ -105,8 +105,6 @@ describe('articleDataPath', () => { describe('frontPagePath', () => { const validRoutes = [ - '/news', - '/news.amp', '/ukchina/simp', '/ukchina/trad', '/serbian/lat.amp', @@ -120,14 +118,14 @@ describe('frontPagePath', () => { '/iplayer', '/news/foobar', '/news/foobar.amp', - '/persian', - '/persian.amp', + '/kyrgyz', + '/kyrgyz.amp', ]; shouldNotMatchInvalidRoutes(invalidRoutes, frontPagePath); }); describe('frontPageDataPath', () => { - const validRoutes = ['/news.json', '/serbian/cyr.json', '/ukchina/trad.json']; + const validRoutes = ['/serbian/cyr.json', '/ukchina/trad.json']; shouldMatchValidRoutes(validRoutes, frontPageDataPath); const invalidRoutes = [ @@ -529,8 +527,6 @@ describe('legacyAssetPageDataPath', () => { describe('frontPage -> homePage migration', () => { const services = Object.keys(serviceConfig); - const servicesWithVariants = ['serbian', 'ukchina', 'zhongwen']; - const servicesNotCoveredByWorldService = [ 'sport', 'scotland', @@ -541,13 +537,27 @@ describe('frontPage -> homePage migration', () => { 'archive', ]; - const homePageServices = services.filter( - service => - !servicesWithVariants.includes(service) && - !servicesNotCoveredByWorldService.includes(service), + const worldServices = services.filter( + service => !servicesNotCoveredByWorldService.includes(service), ); - const homePageRoutes = homePageServices.map(service => `/${service}`); + const serviceToRoute = service => `/${service}`; + + const servicesWithVariants = ['serbian', 'ukchina', 'zhongwen']; + const servicesWithVariantsRoutes = servicesWithVariants.map(serviceToRoute); + + const servicesWithoutVariantsRoutes = worldServices + .filter(service => !servicesWithVariants.includes(service)) + .map(serviceToRoute); + + const migratedServices = ['kyrgyz']; + const migratedWorldServiceRoutes = migratedServices.map(serviceToRoute); + + const liveFrontPageServices = worldServices.filter( + service => !migratedServices.includes(service), + ); + + const liveFrontPageRoutes = liveFrontPageServices.map(serviceToRoute); const originalApplicationEnvironment = process.env.SIMORGH_APP_ENV; @@ -562,7 +572,9 @@ describe('frontPage -> homePage migration', () => { const homePageRegex = getHomePageRegex(services); - shouldMatchValidRoutes(homePageRoutes, homePageRegex); + shouldMatchValidRoutes(servicesWithoutVariantsRoutes, homePageRegex); + + shouldNotMatchInvalidRoutes(servicesWithVariantsRoutes, homePageRegex); }, ); @@ -573,7 +585,12 @@ describe('frontPage -> homePage migration', () => { const frontPageRegex = getFrontPageRegex(services); - shouldNotMatchInvalidRoutes(homePageRoutes, frontPageRegex); + shouldMatchValidRoutes(servicesWithVariantsRoutes, frontPageRegex); + + shouldNotMatchInvalidRoutes( + servicesWithoutVariantsRoutes, + frontPageRegex, + ); }, ); @@ -582,7 +599,9 @@ describe('frontPage -> homePage migration', () => { const frontPageRegex = getFrontPageRegex(services); - shouldMatchValidRoutes(homePageRoutes, frontPageRegex); + shouldMatchValidRoutes(liveFrontPageRoutes, frontPageRegex); + + shouldNotMatchInvalidRoutes(migratedWorldServiceRoutes, frontPageRegex); }); describe(`homePage regex on the live environment`, () => { @@ -590,6 +609,8 @@ describe('frontPage -> homePage migration', () => { const homePageRegex = getHomePageRegex(services); - shouldNotMatchInvalidRoutes(homePageRoutes, homePageRegex); + shouldMatchValidRoutes(migratedWorldServiceRoutes, homePageRegex); + + shouldNotMatchInvalidRoutes(liveFrontPageRoutes, homePageRegex); }); }); diff --git a/src/app/routes/utils/regex/utils/__snapshots__/index.test.js.snap b/src/app/routes/utils/regex/utils/__snapshots__/index.test.js.snap index 2514a132516..270bc043cdc 100644 --- a/src/app/routes/utils/regex/utils/__snapshots__/index.test.js.snap +++ b/src/app/routes/utils/regex/utils/__snapshots__/index.test.js.snap @@ -2,50 +2,50 @@ exports[`regex utils snapshots should create expected regex from getAfricaEyeTVPageRegex 1`] = `"/worldservice/tv/africa_eye/:episodeId([a-z0-9]+)?"`; -exports[`regex utils snapshots should create expected regex from getArticleManifestRegex 1`] = `"/:service(news|persian|igbo)/:local(articles|erthyglau|sgeulachdan)/manifest.json"`; +exports[`regex utils snapshots should create expected regex from getArticleManifestRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/:local(articles|erthyglau|sgeulachdan)/manifest.json"`; -exports[`regex utils snapshots should create expected regex from getArticleRegex 1`] = `"/:service(news|persian|igbo)?:discipline(/[a-z0-9-_]{1,})?/:local(articles|erthyglau|sgeulachdan)/:id(c[a-zA-Z0-9]{10}o):variant(/simp|/trad|/cyr|/lat)?:nonCanonicalArticleRenderPlatform(.amp|.app)?"`; +exports[`regex utils snapshots should create expected regex from getArticleRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)?:discipline(/[a-z0-9-_]{1,})?/:local(articles|erthyglau|sgeulachdan)/:id(c[a-zA-Z0-9]{10}o):variant(/simp|/trad|/cyr|/lat)?:nonCanonicalArticleRenderPlatform(.amp|.app)?"`; -exports[`regex utils snapshots should create expected regex from getArticleSwRegex 1`] = `"/:service(news|persian|igbo)/:local(articles|erthyglau|sgeulachdan)/sw.js"`; +exports[`regex utils snapshots should create expected regex from getArticleSwRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/:local(articles|erthyglau|sgeulachdan)/sw.js"`; -exports[`regex utils snapshots should create expected regex from getCpsAssetRegex 1`] = `"/:service(news|persian|igbo):variant(/simp|/trad|/cyr|/lat)?/:assetUri([a-z0-9-_]{0,}[0-9]{8,}):amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getCpsAssetRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/:assetUri([a-z0-9-_]{0,}[0-9]{8,}):amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getErrorPageRegex 1`] = `"/:service(news|persian|igbo)/:errorCode(404|500):variant(/simp|/trad|/cyr|/lat)?"`; +exports[`regex utils snapshots should create expected regex from getErrorPageRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/:errorCode(404|500):variant(/simp|/trad|/cyr|/lat)?"`; -exports[`regex utils snapshots should create expected regex from getFrontPageRegex 1`] = `"/:service(news):variant(/simp|/trad|/cyr|/lat)?:amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getFrontPageRegex 1`] = `"/:service(serbian|ukchina|zhongwen):variant(/simp|/trad|/cyr|/lat)?:amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getHomePageRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|azeri|bengali|burmese|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|nepali|pashto|persian|pidgin|portuguese|punjabi|russian|sinhala|somali|swahili|tamil|telugu|thai|tigrinya|turkce|ukrainian|urdu|uzbek|vietnamese|yoruba):variant(/simp|/trad|/cyr|/lat)?:amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getHomePageRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukrainian|urdu|uzbek|vietnamese|yoruba):variant(/simp|/trad|/cyr|/lat)?:amp(.amp)?"`; exports[`regex utils snapshots should create expected regex from getIdxPageRegex 1`] = `"/:idx(persian/afghanistan|ukrainian/ukraine_in_russian):amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getLegacyAssetRegex 1`] = `"/:service(news|persian|igbo):variant(/simp|/trad|/cyr|/lat)?/:assetUri([a-z0-9-_]{1,}/[a-z0-9-_/]{1,}):amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getLegacyAssetRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/:assetUri([a-z0-9-_]{1,}/[a-z0-9-_/]{1,}):amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getLiveRadioRegex 1`] = `"/:service(news|persian|igbo)/:masterBrand(bbc_[a-z]+_radio)/:mediaId(liveRadio):amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getLiveRadioRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/:masterBrand(bbc_[a-z]+_radio)/:mediaId(liveRadio):amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getManifestRegex 1`] = `"/:service(news|persian|igbo)/manifest.json"`; +exports[`regex utils snapshots should create expected regex from getManifestRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/manifest.json"`; -exports[`regex utils snapshots should create expected regex from getMostReadDataRegex 1`] = `"/:service(news|persian|igbo)/mostread:variant(/simp|/trad|/cyr|/lat)?.json"`; +exports[`regex utils snapshots should create expected regex from getMostReadDataRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/mostread:variant(/simp|/trad|/cyr|/lat)?.json"`; -exports[`regex utils snapshots should create expected regex from getMostReadPageRegex 1`] = `"/:service(news|persian|igbo):variant(/simp|/trad|/cyr|/lat)?/popular/read:amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getMostReadPageRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/popular/read:amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getMostWatchedDataRegex 1`] = `"/:service(news|persian|igbo)/mostwatched:variant(/simp|/trad|/cyr|/lat)?.json"`; +exports[`regex utils snapshots should create expected regex from getMostWatchedDataRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/mostwatched:variant(/simp|/trad|/cyr|/lat)?.json"`; -exports[`regex utils snapshots should create expected regex from getMostWatchedPageRegex 1`] = `"/:service(news|persian|igbo):variant(/simp|/trad|/cyr|/lat)?/media/video:amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getMostWatchedPageRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/media/video:amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getOnDemandRadioRegex 1`] = `"/:service(news|persian|igbo):variant(/simp|/trad|/cyr|/lat)?/:serviceId(bbc_[a-z]+_radio)(/programmes)?/:mediaId([a-z0-9]+):amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getOnDemandRadioRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/:serviceId(bbc_[a-z]+_radio)(/programmes)?/:mediaId([a-z0-9]+):amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getOnDemandTvRegex 1`] = `"/:service(news|persian|igbo)/:serviceId(bbc_[a-z]+_tv)/:brandEpisode(tv|tv_programmes)/:mediaId([a-z0-9]+):amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getOnDemandTvRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/:serviceId(bbc_[a-z]+_tv)/:brandEpisode(tv|tv_programmes)/:mediaId([a-z0-9]+):amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getPodcastBrandRegex 1`] = `"/:service(news|persian|igbo):variant(/simp|/trad|/cyr|/lat)?/podcasts/:brandId([a-z0-9]+):amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getPodcastBrandRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/podcasts/:brandId([a-z0-9]+):amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getPodcastEpisodeRegex 1`] = `"/:service(news|persian|igbo):variant(/simp|/trad|/cyr|/lat)?/podcasts/:brandId([a-z0-9]+)/:mediaId([a-z0-9]+):amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getPodcastEpisodeRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/podcasts/:brandId([a-z0-9]+)/:mediaId([a-z0-9]+):amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getRecommendationsDataRegex 1`] = `"/:service(news|persian|igbo)/:assetUri([a-z0-9-_]{0,}[0-9]{8,})/recommendations:variant(/simp|/trad|/cyr|/lat)?.json"`; +exports[`regex utils snapshots should create expected regex from getRecommendationsDataRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/:assetUri([a-z0-9-_]{0,}[0-9]{8,})/recommendations:variant(/simp|/trad|/cyr|/lat)?.json"`; -exports[`regex utils snapshots should create expected regex from getSecondaryColumnDataRegex 1`] = `"/:service(news|persian|igbo)/sty-secondary-column:variant(/simp|/trad|/cyr|/lat)?.json"`; +exports[`regex utils snapshots should create expected regex from getSecondaryColumnDataRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/sty-secondary-column:variant(/simp|/trad|/cyr|/lat)?.json"`; -exports[`regex utils snapshots should create expected regex from getSwRegex 1`] = `"/:service(news|persian|igbo)/sw.js"`; +exports[`regex utils snapshots should create expected regex from getSwRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen)/sw.js"`; -exports[`regex utils snapshots should create expected regex from getTipoHomeRegex 1`] = `"/:service(news|persian|igbo):variant(/simp|/trad|/cyr|/lat)?/tipohome:amp(.amp)?"`; +exports[`regex utils snapshots should create expected regex from getTipoHomeRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/tipohome:amp(.amp)?"`; -exports[`regex utils snapshots should create expected regex from getTopicPageRegex 1`] = `"/:service(news|persian|igbo):variant(/simp|/trad|/cyr|/lat)?/topics/:id([a-z0-9]+)?"`; +exports[`regex utils snapshots should create expected regex from getTopicPageRegex 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/topics/:id([a-z0-9]+)?"`; diff --git a/src/app/routes/utils/regex/utils/index.js b/src/app/routes/utils/regex/utils/index.js index 71356caa8f6..38681e3e450 100644 --- a/src/app/routes/utils/regex/utils/index.js +++ b/src/app/routes/utils/regex/utils/index.js @@ -34,56 +34,22 @@ export const getArticleManifestRegex = services => { return `/:service(${serviceRegex})/:local(${articleLocalRegex})/manifest.json`; }; -const frontPageServicesToMigrate = [ - 'afaanoromoo', - 'afrique', - 'amharic', - 'arabic', - 'azeri', - 'bengali', - 'burmese', - 'gahuza', - 'gujarati', - 'hausa', - 'hindi', - 'igbo', - 'indonesia', - 'japanese', - 'korean', - 'kyrgyz', - 'marathi', - 'mundo', - 'nepali', - 'pashto', - 'persian', - 'pidgin', - 'portuguese', - 'punjabi', - 'russian', - 'sinhala', - 'somali', - 'swahili', - 'tamil', - 'telugu', - 'thai', - 'tigrinya', - 'turkce', - 'ukrainian', - 'urdu', - 'uzbek', - 'vietnamese', - 'yoruba', -]; +const homePageServices = ['kyrgyz']; + +const servicesWithVariants = ['serbian', 'ukchina', 'zhongwen']; export const getFrontPageRegex = services => { - // if environment is not live then filter out and remove kyrgyz from list of services - let frontPageServices = services; - if (!isLive()) { - frontPageServices = services.filter( - service => !frontPageServicesToMigrate.includes(service), + let frontPages = services; + if (isLive()) { + frontPages = services.filter( + service => !homePageServices.includes(service), + ); + } else { + frontPages = services.filter(service => + servicesWithVariants.includes(service), ); } - const serviceRegex = getServiceRegex(frontPageServices); + const serviceRegex = getServiceRegex(frontPages); return `/:service(${serviceRegex}):variant(${variantRegex})?:amp(${ampRegex})?`; }; @@ -92,12 +58,17 @@ export const getTipoHomeRegex = services => { return `/:service(${serviceRegex}):variant(${variantRegex})?/tipohome:amp(${ampRegex})?`; }; -// eslint-disable-next-line consistent-return -export const getHomePageRegex = () => { - if (!isLive()) { - const homePageServiceRegex = getServiceRegex(frontPageServicesToMigrate); - return `/:service(${homePageServiceRegex}):variant(${variantRegex})?:amp(${ampRegex})?`; +export const getHomePageRegex = services => { + let homePages = services; + if (isLive()) { + homePages = services.filter(service => homePageServices.includes(service)); + } else { + homePages = services.filter( + service => !servicesWithVariants.includes(service), + ); } + const homePageServiceRegex = getServiceRegex(homePages); + return `/:service(${homePageServiceRegex}):variant(${variantRegex})?:amp(${ampRegex})?`; }; export const getSwRegex = services => { diff --git a/src/app/routes/utils/regex/utils/index.test.js b/src/app/routes/utils/regex/utils/index.test.js index 6bddafd6a57..05c43b509f5 100644 --- a/src/app/routes/utils/regex/utils/index.test.js +++ b/src/app/routes/utils/regex/utils/index.test.js @@ -1,11 +1,11 @@ import * as regexGenerators from '.'; +import serviceConfig from '../../../../lib/config/services/loadableConfig'; describe('regex utils snapshots', () => { + const services = Object.keys(serviceConfig); Object.keys(regexGenerators).forEach(funcName => { it(`should create expected regex from ${funcName}`, () => { - expect( - regexGenerators[funcName](['news', 'persian', 'igbo']), - ).toMatchSnapshot(); + expect(regexGenerators[funcName](services)).toMatchSnapshot(); }); }); });