Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSTEAM1-1488: Delete MEDIA_PAGE references #12227

Open
wants to merge 8 commits into
base: latest
Choose a base branch
from
113 changes: 4 additions & 109 deletions src/app/components/ATIAnalytics/params/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as analyticsUtils from '../../../lib/analyticsUtils';
import {
ARTICLE_PAGE,
FRONT_PAGE,
MEDIA_PAGE,
MEDIA_ASSET_PAGE,
PHOTO_GALLERY_PAGE,
MEDIA_ARTICLE_PAGE,
Expand Down Expand Up @@ -58,14 +57,6 @@ const frontPage: PageData = {
},
};

const media: PageData = {
id: 'id',
language: 'language',
pageIdentifier: 'pageIdentifier',
pageTitle: 'pageTitle',
contentType: 'player-live',
};

const homePageAnalyticsData: ATIData = {
contentId: 'urn:bbc:tipo:topic:cm7682qz7v1t',
contentType: 'index-home',
Expand Down Expand Up @@ -260,36 +251,6 @@ describe('ATIAnalytics params', () => {
});
});

it('should return the correct media url', () => {
const url = buildATIUrl({
requestContext: { ...requestContext, pageType: MEDIA_PAGE },
data: media,
serviceContext,
});

const parsedATIParams = Object.fromEntries(
new URLSearchParams(url as string),
);

expect(parsedATIParams).toEqual({
s: '598285',
s2: 'atiAnalyticsProducerId',
p: 'pageIdentifier',
r: '0x0x24x24',
re: '1024x768',
hl: '00-00-00',
lng: 'en-US',
x1: '[id]',
x2: '[responsive]',
x3: '[atiAnalyticsAppName]',
x4: '[language]',
x5: '[http%3A%2F%2Flocalhost%2F]',
x7: '[player-live]',
x8: '[simorgh]',
x9: '[pageTitle]',
});
});

it('should return the correct MAP url', () => {
const url = buildATIUrl({
requestContext: { ...requestContext, pageType: MEDIA_ASSET_PAGE },
Expand Down Expand Up @@ -470,9 +431,9 @@ describe('ATIAnalytics params', () => {
);
});

it('should not invoke buildPageATIUrl for an unsupported page type with no atiData', () => {
it('should not invoke buildPageATIUrl for an unmigrated page type with no atiData', () => {
buildATIUrl({
requestContext: { ...requestContext, pageType: MEDIA_PAGE },
requestContext: { ...requestContext, pageType: FRONT_PAGE },
atiData: undefined,
serviceContext,
});
Expand Down Expand Up @@ -582,27 +543,6 @@ describe('ATIAnalytics params', () => {
});
});

it('should return the correct media params', () => {
const params = buildATIEventTrackingParams({
requestContext: { ...requestContext, pageType: MEDIA_PAGE },
data: media,
serviceContext,
});
expect(params).toEqual({
appName: 'atiAnalyticsAppName',
contentId: 'id',
contentType: 'player-live',
language: 'language',
pageIdentifier: 'pageIdentifier',
pageTitle: 'pageTitle',
libraryVersion: 'simorgh',
platform: 'canonical',
producerId: 'atiAnalyticsProducerId',
service: 'pidgin',
statsDestination: 'statsDestination',
});
});

it('should return the correct MAP params', () => {
const params = buildATIEventTrackingParams({
requestContext: { ...requestContext, pageType: MEDIA_ASSET_PAGE },
Expand Down Expand Up @@ -743,60 +683,15 @@ describe('ATIAnalytics params', () => {
);
});

it('should not invoke buildPageATIParams for an unsupported page type with no atiData', () => {
it('should not invoke buildPageATIParams for an unmigrated page type with no atiData', () => {
buildATIEventTrackingParams({
requestContext: { ...requestContext, pageType: MEDIA_PAGE },
requestContext: { ...requestContext, pageType: FRONT_PAGE },
atiData: undefined,
serviceContext,
});

expect(console.error)
.toHaveBeenCalledWith(`ATI Event Tracking Error: Could not parse tracking values from page data:
Cannot read properties of undefined (reading 'id')`);
expect(buildPageATIParamsSpy).not.toHaveBeenCalled();
});
});

it('should not throw exception and return empty object if no pageData is passed in', () => {
const { error } = console;
console.error = jest.fn();

const pageData = null;
const params = buildATIEventTrackingParams({
requestContext: { ...requestContext, pageType: MEDIA_PAGE },
// @ts-expect-error - pass in null value to ensure error handling working as expected
data: pageData,
serviceContext,
});

expect(params).toEqual({});
expect(console.error).toHaveBeenCalledWith(
expect.stringContaining(
'ATI Event Tracking Error: Could not parse tracking values from page data:',
),
);
console.error = error;
});

it('should not throw exception and return empty object if no atiData is passed in', () => {
const { error } = console;
console.error = jest.fn();

const atiData = null;
const params = buildATIEventTrackingParams({
requestContext: { ...requestContext, pageType: MEDIA_PAGE },
// @ts-expect-error - pass in null value to ensure error handling working as expected
atiData,
serviceContext,
});

expect(params).toEqual({});
expect(console.error).toHaveBeenCalledWith(
expect.stringContaining(
'ATI Event Tracking Error: Could not parse tracking values from page data:',
),
);
console.error = error;
});
});
});
42 changes: 12 additions & 30 deletions src/app/components/ATIAnalytics/params/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
FEATURE_INDEX_PAGE,
MOST_READ_PAGE,
PHOTO_GALLERY_PAGE,
MEDIA_PAGE,
ERROR_PAGE,
LIVE_PAGE,
CPS_ASSET,
Expand All @@ -22,10 +21,6 @@ import {
AUDIO_PAGE,
TV_PAGE,
} from '../../../routes/utils/pageTypes';
import {
buildTvRadioATIParams,
buildTvRadioATIUrl,
} from './tvRadioPage/buildParams';
import { buildPageATIUrl, buildPageATIParams } from './buildParams';
import {
buildIndexPageATIParams,
Expand Down Expand Up @@ -68,7 +63,6 @@ const pageTypeUrlBuilders = {
[MEDIA_ARTICLE_PAGE]: noOp,
[STORY_PAGE]: noOp,
[FRONT_PAGE]: buildIndexPageATIUrl,
[MEDIA_PAGE]: buildTvRadioATIUrl,
[MOST_READ_PAGE]: noOp,
[FEATURE_INDEX_PAGE]: noOp,
[TOPIC_PAGE]: noOp,
Expand All @@ -92,7 +86,6 @@ const pageTypeParamBuilders = {
[ARTICLE_PAGE]: noOp,
[MEDIA_ARTICLE_PAGE]: noOp,
[FRONT_PAGE]: buildIndexPageATIParams,
[MEDIA_PAGE]: buildTvRadioATIParams,
[MOST_READ_PAGE]: noOp,
[FEATURE_INDEX_PAGE]: noOp,
[TOPIC_PAGE]: noOp,
Expand Down Expand Up @@ -167,32 +160,21 @@ export const buildATIEventTrackingParams = ({
data,
atiData,
}: ATIConfigurationDetailsProviders) => {
try {
const { pageType } = requestContext;
if (atiData && isMigrated(pageType)) {
return buildPageATIParams({
atiData,
requestContext,
serviceContext,
});
}

const buildParams = createBuilderFactory(
const { pageType } = requestContext;
if (atiData && isMigrated(pageType)) {
return buildPageATIParams({
atiData,
requestContext,
pageTypeParamBuilders,
);

return buildParams(data as PageData, requestContext, serviceContext);
} catch (error: unknown) {
const { message } = error as Error;
serviceContext,
});
}

// eslint-disable-next-line no-console
console.error(
`ATI Event Tracking Error: Could not parse tracking values from page data:\n${message}`,
);
const buildParams = createBuilderFactory(
requestContext,
pageTypeParamBuilders,
);

return {};
Comment on lines -186 to -194
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm maybe I should leave in the error handling just in case something occurs within buildPageATIParams or buildParams

}
return buildParams(data as PageData, requestContext, serviceContext);
};

export default buildATIUrl;
7 changes: 0 additions & 7 deletions src/app/components/ChartbeatAnalytics/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import onClient from '../../../lib/utilities/onClient';
import {
ARTICLE_PAGE,
FRONT_PAGE,
MEDIA_PAGE,
MOST_READ_PAGE,
FEATURE_INDEX_PAGE,
MEDIA_ASSET_PAGE,
Expand Down Expand Up @@ -84,11 +83,6 @@ describe('Chartbeat utilities', () => {
expectedDefaultType: 'article-media-asset',
expectedShortType: 'article-media-asset',
},
{
pageType: MEDIA_PAGE,
expectedDefaultType: 'Radio',
expectedShortType: 'Radio',
},
{
pageType: AUDIO_PAGE,
expectedDefaultType: 'Radio',
Expand Down Expand Up @@ -303,7 +297,6 @@ describe('Chartbeat utilities', () => {
${MOST_READ_PAGE} | ${'Most Read Page Title'} | ${'BBC News Pidgin'} | ${'Most Read Page Title - BBC News Pidgin'}
${TOPIC_PAGE} | ${'Topic Page Title'} | ${'BBC News Pidgin'} | ${'Topic Page Title - BBC News Pidgin'}
${LIVE_PAGE} | ${'Live Page Title'} | ${'BBC News Pidgin'} | ${'Live Page Title - BBC News Pidgin'}
${MEDIA_PAGE} | ${'Media Page Title'} | ${'BBC News Pidgin'} | ${'Media Page Title - BBC News Pidgin'}
${AUDIO_PAGE} | ${'Audio Page Title'} | ${'BBC News Pidgin'} | ${'Audio Page Title - BBC News Pidgin'}
${TV_PAGE} | ${'TV Page Title'} | ${'BBC News Pidgin'} | ${'TV Page Title - BBC News Pidgin'}
${'index'} | ${'index Page Title'} | ${'BBC News Pidgin'} | ${'index Page Title - BBC News Pidgin'}
Expand Down
4 changes: 0 additions & 4 deletions src/app/components/ChartbeatAnalytics/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getReferrer } from '../../../lib/analyticsUtils';
import {
ARTICLE_PAGE,
FRONT_PAGE,
MEDIA_PAGE,
MOST_READ_PAGE,
FEATURE_INDEX_PAGE,
MEDIA_ASSET_PAGE,
Expand Down Expand Up @@ -61,7 +60,6 @@ export const getType = (pageType: PageTypes | 'index', shorthand = false) => {
return 'article-media-asset';
case LIVE_RADIO_PAGE:
case AUDIO_PAGE:
case MEDIA_PAGE:
return 'Radio';
case TV_PAGE:
return 'TV';
Expand Down Expand Up @@ -150,7 +148,6 @@ export const buildSections = ({
: []),
].join(', ');
case LIVE_RADIO_PAGE:
case MEDIA_PAGE:
case AUDIO_PAGE:
case TV_PAGE:
return [
Expand Down Expand Up @@ -190,7 +187,6 @@ export const getTitle = ({ pageType, title, brandName }: GetTitleProps) => {
case TOPIC_PAGE:
case LIVE_PAGE:
case LIVE_RADIO_PAGE:
case MEDIA_PAGE:
case AUDIO_PAGE:
case TV_PAGE:
case 'index':
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/MediaLoader/Metadata/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import {
ARTICLE_PAGE,
AUDIO_PAGE,
MEDIA_PAGE,
LIVE_RADIO_PAGE,
TV_PAGE,
} from '#app/routes/utils/pageTypes';
import Metadata from '.';
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('Media Loader - Metadata', () => {
expect(container).toMatchSnapshot();
});

it.each([MEDIA_PAGE, AUDIO_PAGE, TV_PAGE])(
it.each([AUDIO_PAGE, TV_PAGE, LIVE_RADIO_PAGE])(
'should not render metadata component as the %s page type is not supported',
async pageType => {
let container;
Expand Down
2 changes: 0 additions & 2 deletions src/app/contexts/EventTrackingContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import useToggle from '../../hooks/useToggle';
import {
ARTICLE_PAGE,
FRONT_PAGE,
MEDIA_PAGE,
MOST_READ_PAGE,
FEATURE_INDEX_PAGE,
MEDIA_ASSET_PAGE,
Expand Down Expand Up @@ -60,7 +59,6 @@ const getCampaignID = (pageType: CampaignPageTypes) => {
[ARTICLE_PAGE]: 'article',
[MEDIA_ARTICLE_PAGE]: 'article-sfv',
[FRONT_PAGE]: 'index-home',
[MEDIA_PAGE]: 'player-episode',
[MOST_READ_PAGE]: 'list-datadriven-read',
[FEATURE_INDEX_PAGE]: 'index-section-fix',
[MEDIA_ASSET_PAGE]: 'article-media-asset',
Expand Down
4 changes: 2 additions & 2 deletions src/app/legacy/containers/OnDemandImage/index.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { RequestContextProvider } from '#contexts/RequestContext';
import { MEDIA_PAGE } from '#app/routes/utils/pageTypes';
import { AUDIO_PAGE } from '#app/routes/utils/pageTypes';
import { render } from '../../../components/react-testing-library-with-providers';
import { ServiceContextProvider } from '../../../contexts/ServiceContext';
import OnDemandImage from '.';
Expand All @@ -10,7 +10,7 @@ const component = ({ url, isAmp, service, alt }) => (
<RequestContextProvider
isAmp={isAmp}
service={service}
pageType={MEDIA_PAGE}
pageType={AUDIO_PAGE}
pathname="/path"
>
<OnDemandImage imageUrl={url} alt={alt} />
Expand Down
1 change: 0 additions & 1 deletion src/app/routes/utils/pageTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export const ARTICLE_PAGE = 'article' as const;
export const MEDIA_ARTICLE_PAGE = 'mediaArticle' as const;
export const FRONT_PAGE = 'frontPage' as const;
export const MEDIA_PAGE = 'media' as const;
export const MOST_READ_PAGE = 'mostRead' as const;
export const ERROR_PAGE = 'error' as const;
export const FEATURE_INDEX_PAGE = 'FIX' as const;
Expand Down
6 changes: 3 additions & 3 deletions src/server/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
SERVER_SIDE_RENDER_REQUEST_RECEIVED,
SERVER_SIDE_REQUEST_FAILED,
} from '#lib/logger.const';
import { FRONT_PAGE, MEDIA_PAGE } from '#app/routes/utils/pageTypes';
import { FRONT_PAGE, LIVE_RADIO_PAGE } from '#app/routes/utils/pageTypes';
import Document from './Document/component';
import routes from '../app/routes';
import * as renderDocument from './Document';
Expand Down Expand Up @@ -562,7 +562,7 @@ const testMediaPages = ({
});

describe('404 status code', () => {
const pageType = MEDIA_PAGE;
const pageType = LIVE_RADIO_PAGE;

beforeEach(() => {
mockRouteProps({
Expand All @@ -589,7 +589,7 @@ const testMediaPages = ({
});

describe('Unknown error within the data fetch, react router or its dependencies', () => {
const pageType = 'liveRadio';
const pageType = LIVE_RADIO_PAGE;

beforeEach(() => {
mockRouteProps({
Expand Down
Loading