From d129612c3d31fbfa2e715d325cb9c1246bb70106 Mon Sep 17 00:00:00 2001 From: Toby Cox Date: Thu, 17 Oct 2024 09:49:43 +0100 Subject: [PATCH] NEWSWORLDSERVICE-2062: put zhongwen on CPS front page temporarily (#12051) * CHG: put zhongwen on CPS front page temporarily * FIX: unit tests * FIX: linting * FIX: handle homepages better * FIX: data transform * FIX: snapshot * Update src/app/routes/utils/regex/utils/index.js Co-authored-by: Karina Thomas <58214768+karinathomasbbc@users.noreply.github.com> * Update src/app/routes/utils/regex/index.test.js Co-authored-by: Karina Thomas <58214768+karinathomasbbc@users.noreply.github.com> * Update src/app/routes/utils/regex/utils/index.js Co-authored-by: Karina Thomas <58214768+karinathomasbbc@users.noreply.github.com> * Update src/app/routes/utils/regex/utils/index.js Co-authored-by: Karina Thomas <58214768+karinathomasbbc@users.noreply.github.com> * Update src/server/local/index.test.js Co-authored-by: Karina Thomas <58214768+karinathomasbbc@users.noreply.github.com> * ENH: all variants * FIX: snapshots * ENH: add tests * FIX: lint * FIX: remove extra arg --------- Co-authored-by: Karina Thomas <58214768+karinathomasbbc@users.noreply.github.com> --- .../legacy/containers/StoryPromo/index.jsx | 5 ++- .../lib/utilities/getStoryPromoInfo/index.jsx | 9 ++++- .../getStoryPromoInfo/index.test.jsx | 37 +++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/app/legacy/containers/StoryPromo/index.jsx b/src/app/legacy/containers/StoryPromo/index.jsx index 0b8e77a315d..2bd4bfb2fd1 100644 --- a/src/app/legacy/containers/StoryPromo/index.jsx +++ b/src/app/legacy/containers/StoryPromo/index.jsx @@ -149,7 +149,7 @@ const StoryPromoContainer = ({ sectionType = '', }) => { const { script, service } = useContext(ServiceContext); - const { isAmp, isLite, pageType } = useContext(RequestContext); + const { isAmp, isLite, pageType, variant } = useContext(RequestContext); const handleClickTracking = useCombinedClickTrackerHandler(eventTrackingData); const linkId = buildUniquePromoId({ @@ -167,7 +167,8 @@ const StoryPromoContainer = ({ isAssetTypeCode === 'PRO' && pathOr(null, ['contentType'], item) === 'Guide'; const headline = getHeadline(item); - const url = getUrl(item); + + const url = getUrl(item, variant); const isLive = getIsLive(item); const overtypedSummary = pathOr(null, ['overtypedSummary'], item); diff --git a/src/app/lib/utilities/getStoryPromoInfo/index.jsx b/src/app/lib/utilities/getStoryPromoInfo/index.jsx index c894f6b9910..30004f379e3 100644 --- a/src/app/lib/utilities/getStoryPromoInfo/index.jsx +++ b/src/app/lib/utilities/getStoryPromoInfo/index.jsx @@ -28,10 +28,15 @@ export const getHeadline = item => { return headline; }; -export const getUrl = item => { +export const getUrl = (item, variant = null) => { const assetUri = pathOr(null, ['locators', 'assetUri'], item); const canonicalUrl = pathOr(null, ['locators', 'canonicalUrl'], item); - const uri = pathOr(null, ['uri'], item); + let uri = pathOr(null, ['uri'], item); + if (uri && variant) { + if (uri.indexOf('/articles/') !== -1 && uri.indexOf(`/${variant}`) === -1) { + uri = uri.substr(0, uri.length - variant.length) + variant; + } + } return assetUri || makeRelativeUrlPath(uri) || canonicalUrl; }; diff --git a/src/app/lib/utilities/getStoryPromoInfo/index.test.jsx b/src/app/lib/utilities/getStoryPromoInfo/index.test.jsx index a05f6c5d525..f460d1f728d 100644 --- a/src/app/lib/utilities/getStoryPromoInfo/index.test.jsx +++ b/src/app/lib/utilities/getStoryPromoInfo/index.test.jsx @@ -20,6 +20,31 @@ const assetTypeCode = { type: 'link', }; +const optimoPromoItem = { + name: '以色列哈马斯战争一周年:当地人的生活改变——受伤、成为孤儿、精神创伤', + summary: 'abc', + indexImage: { + id: '64061011', + subType: 'index', + href: 'http://b.files.bbci.co.uk/2B08/test/_64061011_3d193a51-62c9-4853-a403-cafa9f26cee3.jpg', + path: '/cpsdevpb/2B08/test/_64061011_3d193a51-62c9-4853-a403-cafa9f26cee3.jpg', + height: 288, + width: 512, + altText: '一個男子在烤披薩。', + caption: '從左到右: 阿卜杜拉, 巴特舍瓦,阿卜杜勒拉赫曼, 克里斯蒂娜', + copyrightHolder: 'Stanley Leung', + allowSyndication: true, + type: 'image', + }, + uri: 'https://www.bbc.com/zhongwen/articles/cl01rmr1d8po/trad', + aresUrl: + 'https://ares-api.test.api.bbci.co.uk/api/asset/zhongwen/articles/cl01rmr1d8po/trad', + contentType: 'Text', + assetTypeCode: 'PRO', + timestamp: 1728290963000, + type: 'link', +}; + const noAssetTypeCode = { headlines: { headline: @@ -109,6 +134,18 @@ describe('getStoryPromoInfo', () => { ); }); + it('should return the correct url for optimoPromoItem', () => { + expect(getUrl(optimoPromoItem, 'trad')).toEqual( + '/zhongwen/articles/cl01rmr1d8po/trad', + ); + expect(getUrl(optimoPromoItem, 'simp')).toEqual( + '/zhongwen/articles/cl01rmr1d8po/simp', + ); + expect(getUrl(optimoPromoItem)).toEqual( + '/zhongwen/articles/cl01rmr1d8po/trad', + ); + }); + it('should return the correct url for live asset', () => { const liveAsset = { ...noAssetTypeCode, cpsType: 'LIV' }; expect(getUrl(liveAsset)).toEqual('/turkce/haberler-dunya-48735662');