From afd00ff5510f504b8772b4cb47f25683d51b3116 Mon Sep 17 00:00:00 2001 From: seldinpQ Date: Fri, 29 Nov 2024 00:53:21 +0100 Subject: [PATCH 1/4] fix(TMP-1657): Update deck-data-api endpoint --- .../src/article-body/article-body.js | 16 +++++++++++++++- .../BigNumbers.stories.tsx | 9 ++++++--- .../InfoCardBulletPoints.stories.tsx | 5 ++++- .../in-article-timelines/Timelines.stories.tsx | 7 +++++-- .../ts-components/src/utils/getDeckApiUrl.ts | 13 +++++++++++++ 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 packages/ts-components/src/utils/getDeckApiUrl.ts diff --git a/packages/article-skeleton/src/article-body/article-body.js b/packages/article-skeleton/src/article-body/article-body.js index 7797c18a5e7..5768fee5ce1 100644 --- a/packages/article-skeleton/src/article-body/article-body.js +++ b/packages/article-skeleton/src/article-body/article-body.js @@ -61,7 +61,21 @@ import { InlineAdTitle } from "../styles/article-body/responsive"; -const deckApiUrl = "https://gobble.timesdev.tools/deck/api/deck-post-action/"; +let deckApiUrl; +if (typeof window !== 'undefined') { + const environmentName = window.__TIMES_CONFIG__ && window.__TIMES_CONFIG__.environmentName; + + if (environmentName === 'prod') { + deckApiUrl = + 'https://editorial-tm.newsapis.co.uk/prod/deck-component-data-api'; + } else { + deckApiUrl = + 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; + } +} else { + deckApiUrl = + 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; +} const disabledAds = ["c8bf6998-d498-11ed-b5c3-54651fc826e9"]; const hasDisabledAds = id => disabledAds.includes(id); diff --git a/packages/ts-components/src/components/in-article-big-numbers/BigNumbers.stories.tsx b/packages/ts-components/src/components/in-article-big-numbers/BigNumbers.stories.tsx index f2538871083..eb7c8fab3b3 100644 --- a/packages/ts-components/src/components/in-article-big-numbers/BigNumbers.stories.tsx +++ b/packages/ts-components/src/components/in-article-big-numbers/BigNumbers.stories.tsx @@ -5,6 +5,9 @@ import { FetchProvider } from '../../helpers/fetch/FetchProvider'; import { BigNumbers } from './BigNumbers'; import { TrackingContextProvider } from '../../helpers/tracking/TrackingContextProvider'; import analyticsStream from '../../fixtures/analytics-actions/analytics-actions'; +import { getDeckApiUrl } from '../../utils/getDeckApiUrl'; + +const deckApiUrl = getDeckApiUrl(); storiesOf('Typescript Component/In Article/Big Numbers', module) .add('Standard without a headline', () => ( @@ -19,7 +22,7 @@ storiesOf('Typescript Component/In Article/Big Numbers', module) analyticsStream={analyticsStream} > - + @@ -37,7 +40,7 @@ storiesOf('Typescript Component/In Article/Big Numbers', module) analyticsStream={analyticsStream} > - + @@ -55,7 +58,7 @@ storiesOf('Typescript Component/In Article/Big Numbers', module) analyticsStream={analyticsStream} > - + diff --git a/packages/ts-components/src/components/in-article-info-card-bulletpoints/InfoCardBulletPoints.stories.tsx b/packages/ts-components/src/components/in-article-info-card-bulletpoints/InfoCardBulletPoints.stories.tsx index 0eac1fe516c..e3725f922b2 100644 --- a/packages/ts-components/src/components/in-article-info-card-bulletpoints/InfoCardBulletPoints.stories.tsx +++ b/packages/ts-components/src/components/in-article-info-card-bulletpoints/InfoCardBulletPoints.stories.tsx @@ -5,6 +5,9 @@ import { FetchProvider } from '../../helpers/fetch/FetchProvider'; import { InfoCardBulletPoints } from './InfoCardBulletPoints'; import { TrackingContextProvider } from '../../helpers/tracking/TrackingContextProvider'; import analyticsStream from '../../fixtures/analytics-actions/analytics-actions'; +import { getDeckApiUrl } from '../../utils/getDeckApiUrl'; + +const deckApiUrl: string = getDeckApiUrl(); storiesOf('Typescript Component/In Article/Info Card', module).add( 'Bullet Points', @@ -20,7 +23,7 @@ storiesOf('Typescript Component/In Article/Info Card', module).add( analyticsStream={analyticsStream} > - + diff --git a/packages/ts-components/src/components/in-article-timelines/Timelines.stories.tsx b/packages/ts-components/src/components/in-article-timelines/Timelines.stories.tsx index af6a5ca7eaf..67a4e6253ed 100644 --- a/packages/ts-components/src/components/in-article-timelines/Timelines.stories.tsx +++ b/packages/ts-components/src/components/in-article-timelines/Timelines.stories.tsx @@ -5,6 +5,9 @@ import { FetchProvider } from '../../helpers/fetch/FetchProvider'; import { Timelines } from './Timelines'; import { TrackingContextProvider } from '../../helpers/tracking/TrackingContextProvider'; import analyticsStream from '../../fixtures/analytics-actions/analytics-actions'; +import { getDeckApiUrl } from '../../utils/getDeckApiUrl'; + +const deckApiUrl = getDeckApiUrl(); storiesOf('Typescript Component/In Article/Timelines', module) .add('Timelines with Bullet Point', () => ( @@ -19,7 +22,7 @@ storiesOf('Typescript Component/In Article/Timelines', module) analyticsStream={analyticsStream} > - + @@ -37,7 +40,7 @@ storiesOf('Typescript Component/In Article/Timelines', module) analyticsStream={analyticsStream} > - + diff --git a/packages/ts-components/src/utils/getDeckApiUrl.ts b/packages/ts-components/src/utils/getDeckApiUrl.ts new file mode 100644 index 00000000000..d7882a694a5 --- /dev/null +++ b/packages/ts-components/src/utils/getDeckApiUrl.ts @@ -0,0 +1,13 @@ +export const getDeckApiUrl = (): string => { + if (typeof window !== 'undefined') { + const environmentName = window.__TIMES_CONFIG__ && window.__TIMES_CONFIG__.environmentName; + + if (environmentName === 'prod') { + return 'https://editorial-tm.newsapis.co.uk/prod/deck-component-data-api'; + } else { + return 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; + } + } else { + return 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; + } +}; From 7d82178c9b444edcdb1a117d9c48712473931b6d Mon Sep 17 00:00:00 2001 From: seldinpQ Date: Mon, 2 Dec 2024 16:08:23 +0100 Subject: [PATCH 2/4] chore(TMP-1657): lint --- .../ts-components/src/utils/getDeckApiUrl.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/ts-components/src/utils/getDeckApiUrl.ts b/packages/ts-components/src/utils/getDeckApiUrl.ts index d7882a694a5..a88dfa65c82 100644 --- a/packages/ts-components/src/utils/getDeckApiUrl.ts +++ b/packages/ts-components/src/utils/getDeckApiUrl.ts @@ -1,13 +1,14 @@ export const getDeckApiUrl = (): string => { - if (typeof window !== 'undefined') { - const environmentName = window.__TIMES_CONFIG__ && window.__TIMES_CONFIG__.environmentName; + if (typeof window !== 'undefined') { + const environmentName = + window.__TIMES_CONFIG__ && window.__TIMES_CONFIG__.environmentName; - if (environmentName === 'prod') { - return 'https://editorial-tm.newsapis.co.uk/prod/deck-component-data-api'; - } else { - return 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; - } + if (environmentName === 'prod') { + return 'https://editorial-tm.newsapis.co.uk/prod/deck-component-data-api'; } else { - return 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; + return 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; } + } else { + return 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; + } }; From b1f3379a75249a2392364b3d9546f6cf13079ce5 Mon Sep 17 00:00:00 2001 From: seldinpQ Date: Mon, 2 Dec 2024 17:25:01 +0100 Subject: [PATCH 3/4] chore(TMP-1657): fmt --- .../src/article-body/article-body.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/article-skeleton/src/article-body/article-body.js b/packages/article-skeleton/src/article-body/article-body.js index 5768fee5ce1..7cb849ab2ab 100644 --- a/packages/article-skeleton/src/article-body/article-body.js +++ b/packages/article-skeleton/src/article-body/article-body.js @@ -62,19 +62,20 @@ import { } from "../styles/article-body/responsive"; let deckApiUrl; -if (typeof window !== 'undefined') { - const environmentName = window.__TIMES_CONFIG__ && window.__TIMES_CONFIG__.environmentName; +if (typeof window !== "undefined") { + const environmentName = + window.__TIMES_CONFIG__ && window.__TIMES_CONFIG__.environmentName; - if (environmentName === 'prod') { + if (environmentName === "prod") { deckApiUrl = - 'https://editorial-tm.newsapis.co.uk/prod/deck-component-data-api'; + "https://editorial-tm.newsapis.co.uk/prod/deck-component-data-api"; } else { deckApiUrl = - 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; + "https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api"; } } else { deckApiUrl = - 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api'; + "https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api"; } const disabledAds = ["c8bf6998-d498-11ed-b5c3-54651fc826e9"]; From 410a98124e43741d9d7557bbe8be57e7e549f904 Mon Sep 17 00:00:00 2001 From: seldinpQ Date: Mon, 2 Dec 2024 19:38:36 +0100 Subject: [PATCH 4/4] chore(TMP-1657): Add test --- .../src/utils/__tests__/getDeckApiUrl.test.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 packages/ts-components/src/utils/__tests__/getDeckApiUrl.test.ts diff --git a/packages/ts-components/src/utils/__tests__/getDeckApiUrl.test.ts b/packages/ts-components/src/utils/__tests__/getDeckApiUrl.test.ts new file mode 100644 index 00000000000..2925036a6a2 --- /dev/null +++ b/packages/ts-components/src/utils/__tests__/getDeckApiUrl.test.ts @@ -0,0 +1,44 @@ +// getDeckApiUrl.test.ts +import { getDeckApiUrl } from '../getDeckApiUrl'; + +describe('getDeckApiUrl', () => { + beforeEach(() => { + (global as any).window = {}; + }); + + afterEach(() => { + delete (global as any).window; + }); + + it('should return the production URL when environmentName is prod', () => { + (global as any).window.__TIMES_CONFIG__ = { + environmentName: 'prod' + }; + expect(getDeckApiUrl()).toBe( + 'https://editorial-tm.newsapis.co.uk/prod/deck-component-data-api' + ); + }); + + it('should return the staging URL when environmentName is not prod', () => { + (global as any).window.__TIMES_CONFIG__ = { + environmentName: 'staging' + }; + expect(getDeckApiUrl()).toBe( + 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api' + ); + }); + + it('should return the staging URL when window is undefined', () => { + delete (global as any).window; + expect(getDeckApiUrl()).toBe( + 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api' + ); + }); + + it('should return the staging URL when __TIMES_CONFIG__ is undefined', () => { + (global as any).window = {}; + expect(getDeckApiUrl()).toBe( + 'https://editorial-tm.staging.newsapis.co.uk/staging/deck-component-data-api' + ); + }); +});