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

av-embeds - AMP Articles to use parentPID instead of versionPID #12165

Draft
wants to merge 12 commits into
base: latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/app/components/MediaLoader/configs/aresMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export default ({

const versionsBlock = aresMediaMetadata?.[versionParameter]?.[0];

const versionID = versionsBlock?.versionId ?? '';
// Referred to as 'vPID' or 'version PID'
const versionPID = versionsBlock?.versionId ?? '';

const orientation =
ORIENTATION_MAPPING[versionsBlock?.types?.[0]] ??
Expand Down Expand Up @@ -90,7 +91,8 @@ export default ({

const subType = aresMediaMetadata?.subType;

const videoId = aresMediaMetadata?.id;
// Referred to as 'clip PID', 'episode PID' or 'parent PID'
const parentPID = aresMediaMetadata?.id;

const holdingImageURL = rawImage
? buildIChefURL({
Expand All @@ -103,7 +105,12 @@ export default ({
const isLive = aresMediaMetadata?.live ?? false;

const items: PlaylistItem[] = [
{ versionID, kind, duration: rawDuration, ...(isLive && { live: true }) },
{
versionID: versionPID,
kind,
duration: rawDuration,
...(isLive && { live: true }),
},
];

if (showAds) items.unshift({ kind: 'advert' });
Expand All @@ -120,9 +127,14 @@ export default ({
placeholderImageLocator: locator,
});

const ampIframeUrl = getAmpIframeUrl({ id, versionID, lang });
const ampIframeUrl = getAmpIframeUrl({ id, parentPID, versionPID, lang });

const externalEmbedUrl = getExternalEmbedUrl({ id, versionID, lang });
const externalEmbedUrl = getExternalEmbedUrl({
id,
parentPID,
versionPID,
lang,
});

return {
mediaType: actualFormat || 'video',
Expand All @@ -143,8 +155,8 @@ export default ({
...(pageType === 'mediaArticle' && { preload: 'high' }),
statsObject: {
...basePlayerConfig.statsObject,
...(subType === 'clip' && { clipPID: videoId }),
...(subType === 'episode' && { episodePID: videoId }),
...(subType === 'clip' && { clipPID: parentPID }),
...(subType === 'episode' && { episodePID: parentPID }),
},
},
placeholderConfig,
Expand Down
9 changes: 6 additions & 3 deletions src/app/components/MediaLoader/configs/clipMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export default ({

const originCode = source?.replace('Image', '');

const versionID = video?.version?.id;
// Referred to as 'vPID' or 'version PID'
const versionPID = video?.version?.id;

const clipISO8601Duration = video?.version?.duration;

Expand Down Expand Up @@ -81,11 +82,13 @@ export default ({
guidanceMessage,
});

const items: PlaylistItem[] = [{ versionID, kind, duration: rawDuration }];
const items: PlaylistItem[] = [
{ versionID: versionPID, kind, duration: rawDuration },
];

if (showAds) items.unshift({ kind: 'advert' });

const externalEmbedUrl = getExternalEmbedUrl({ id, versionID, lang });
const externalEmbedUrl = getExternalEmbedUrl({ id, versionPID, lang });

return {
mediaType: type || 'video',
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/MediaLoader/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ describe('MediaLoader', () => {

expect(ampPlayer).toBeInTheDocument();
expect(ampIframeUrl).toEqual(
'https://web-cdn.test.api.bbci.co.uk/ws/av-embeds/articles/cn8jgj8rjppo/p01k6msp/en-GB/amp',
'https://web-cdn.test.api.bbci.co.uk/ws/av-embeds/articles/cn8jgj8rjppo/p01k6msm/en-GB/amp',
);
});
});
Expand Down
64 changes: 39 additions & 25 deletions src/app/components/MediaLoader/utils/urlConstructors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const ampIframeTestCases = [
{
description: 'CPS without variant',
id: 'thai/international-55160422',
versionID: 'p0908t9z',
versionPID: 'p0908t9z',
lang: 'th',
expected:
'https://web-cdn.test.api.bbci.co.uk/ws/av-embeds/cps/thai/international-55160422/p0908t9z/th/amp',
},
{
description: 'CPS without variant (no versionID)',
description: 'CPS without variant (no versionPID)',
id: 'thai/international-55160422',
lang: 'th',
expected:
Expand All @@ -28,13 +28,13 @@ const ampIframeTestCases = [
{
description: 'CPS with variant',
id: 'serbian/cyr/srbija-68707945',
versionID: 'p0cfmdwn',
versionPID: 'p0cfmdwn',
lang: 'sr-cyrl',
expected:
'https://web-cdn.test.api.bbci.co.uk/ws/av-embeds/cps/serbian/cyr/srbija-68707945/p0cfmdwn/sr-cyrl/amp',
},
{
description: 'CPS with variant (no versionID)',
description: 'CPS with variant (no versionPID)',
id: 'serbian/cyr/srbija-68707945',
lang: 'sr-cyrl',
expected:
Expand All @@ -43,7 +43,7 @@ const ampIframeTestCases = [
{
description: 'Optimo',
id: 'mundo/articles/c805k05kr73o',
versionID: 'p0cfmdwn',
parentPID: 'p0cfmdwn',
lang: 'es',
expected:
'https://web-cdn.test.api.bbci.co.uk/ws/av-embeds/articles/c805k05kr73o/p0cfmdwn/es/amp',
Expand All @@ -59,13 +59,13 @@ const externalEmbedUrlTestCases = [
{
description: 'CPS without variant',
id: 'thai/international-55160422',
versionID: 'p0908t9z',
versionPID: 'p0908t9z',
lang: 'th',
expected:
'https://www.test.bbc.com/thai/av-embeds/international-55160422/vpid/p0908t9z',
},
{
description: 'CPS without variant (no versionID)',
description: 'CPS without variant (no versionPID)',
id: 'thai/international-55160422',
lang: 'th',
expected:
Expand All @@ -74,13 +74,13 @@ const externalEmbedUrlTestCases = [
{
description: 'CPS with variant',
id: 'serbian/cyr/srbija-68707945',
versionID: 'p0cfmdwn',
versionPID: 'p0cfmdwn',
lang: 'sr-cyrl',
expected:
'https://www.test.bbc.com/serbian/cyr/av-embeds/srbija-68707945/vpid/p0cfmdwn',
},
{
description: 'CPS with variant (no versionID)',
description: 'CPS with variant (no versionPID)',
id: 'serbian/cyr/srbija-68707945',
lang: 'sr-cyrl',
expected:
Expand All @@ -89,27 +89,27 @@ const externalEmbedUrlTestCases = [
{
description: 'CPS Syndicated route without variant',
id: 'news/av-embeds/58869966/vpid/p07r2y68',
versionID: 'p07r2y68',
versionPID: 'p07r2y68',
lang: 'en-gb',
expected:
'https://www.test.bbc.com/news/av-embeds/58869966/vpid/p07r2y68',
},
{
description: 'CPS Syndicated route without variant (no versionID)',
description: 'CPS Syndicated route without variant (no versionPID)',
id: 'news/av-embeds/58869966',
lang: 'en-gb',
expected: 'https://www.test.bbc.com/news/av-embeds/58869966',
},
{
description: 'CPS Syndicated route with variant',
id: 'serbian/cyr/av-embeds/srbija-68707945/pid/p0cfmdwn',
versionID: 'p0cfmdwn',
versionPID: 'p0cfmdwn',
lang: 'sr-cyrl',
expected:
'https://www.test.bbc.com/serbian/cyr/av-embeds/srbija-68707945/vpid/p0cfmdwn',
},
{
description: 'CPS Syndicated route with variant (no versionID)',
description: 'CPS Syndicated route with variant (no versionPID)',
id: 'serbian/cyr/av-embeds/srbija-68707945',
lang: 'sr-cyrl',
expected:
Expand All @@ -118,13 +118,13 @@ const externalEmbedUrlTestCases = [
{
description: 'Optimo',
id: 'mundo/articles/c805k05kr73o',
versionID: 'p0cfmdwn',
parentPID: 'p0cfmdwn',
lang: 'es',
expected:
'https://www.test.bbc.com/ws/av-embeds/articles/c805k05kr73o/p0cfmdwn/es',
},
{
description: 'Optimo (no versionID)',
description: 'Optimo (no parentPID)',
id: 'mundo/articles/c805k05kr73o',
lang: 'es',
expected:
Expand All @@ -133,13 +133,13 @@ const externalEmbedUrlTestCases = [
{
description: 'Optimo Syndicated route',
id: 'ws/av-embeds/articles/cd1rmn075d1o/p0jd37n8/ig',
versionID: 'p0jd37n8',
parentPID: 'p0jd37n8',
lang: 'ig',
expected:
'https://www.test.bbc.com/ws/av-embeds/articles/cd1rmn075d1o/p0jd37n8/ig',
},
{
description: 'Optimo Syndicated route (no versionID)',
description: 'Optimo Syndicated route (no parentPID)',
id: 'ws/av-embeds/articles/cd1rmn075d1o/p0jd37n8/ig',
lang: 'ig',
expected:
Expand All @@ -154,11 +154,18 @@ describe('urlConstructors', () => {
ampIframeTestCases.forEach(({ description, cases }) => {
describe(description, () => {
cases.forEach(
({ description: caseDescription, id, versionID, lang, expected }) => {
({
description: caseDescription,
id,
parentPID,
versionPID,
lang,
expected,
}) => {
it(caseDescription, () => {
expect(getAmpIframeUrl({ id, versionID, lang })).toEqual(
expected,
);
expect(
getAmpIframeUrl({ id, parentPID, versionPID, lang }),
).toEqual(expected);
});
},
);
Expand All @@ -170,11 +177,18 @@ describe('urlConstructors', () => {
externalEmbedUrlTestCases.forEach(({ description, cases }) => {
describe(description, () => {
cases.forEach(
({ description: caseDescription, id, versionID, lang, expected }) => {
({
description: caseDescription,
id,
parentPID,
versionPID,
lang,
expected,
}) => {
it(caseDescription, () => {
expect(getExternalEmbedUrl({ id, versionID, lang })).toEqual(
expected,
);
expect(
getExternalEmbedUrl({ id, parentPID, versionPID, lang }),
).toEqual(expected);
});
},
);
Expand Down
25 changes: 18 additions & 7 deletions src/app/components/MediaLoader/utils/urlConstructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,52 @@ const TEST_AMP_URL = 'https://web-cdn.test.api.bbci.co.uk';

type FuncProps = {
id: string | null;
versionID?: string;
parentPID?: string;
versionPID?: string;
lang?: string;
};

export const getAmpIframeUrl = ({ id, versionID, lang }: FuncProps) => {
export const getAmpIframeUrl = ({
id,
parentPID,
versionPID,
lang,
}: FuncProps) => {
if (!id) return null;

const { platform, service, variant, assetId } = parseAvRoute(id);

const ampBaseUrl = isLive() ? LIVE_AMP_URL : TEST_AMP_URL;

if (platform === 'cps') {
return `${ampBaseUrl}/ws/av-embeds/cps/${service}${variant ? `/${variant}` : ''}/${assetId}${versionID ? `/${versionID}` : ''}${lang ? `/${lang}` : ''}/amp`;
return `${ampBaseUrl}/ws/av-embeds/cps/${service}${variant ? `/${variant}` : ''}/${assetId}${versionPID ? `/${versionPID}` : ''}${lang ? `/${lang}` : ''}/amp`;
}

if (platform === 'articles') {
return `${ampBaseUrl}/ws/av-embeds/articles/${assetId}${versionID ? `/${versionID}` : ''}${lang ? `/${lang}` : ''}/amp`;
return `${ampBaseUrl}/ws/av-embeds/articles/${assetId}${parentPID ? `/${parentPID}` : ''}${lang ? `/${lang}` : ''}/amp`;
}

return null;
};

export const getExternalEmbedUrl = ({ id, versionID, lang }: FuncProps) => {
export const getExternalEmbedUrl = ({
id,
parentPID,
versionPID,
lang,
}: FuncProps) => {
if (!id) return null;

const { platform, service, variant, assetId } = parseAvRoute(id);

const baseUrl = isLive() ? LIVE_BASE_URL : TEST_BASE_URL;

if (platform === 'cps') {
return `${baseUrl}/${service}${variant ? `/${variant}` : ''}/av-embeds/${assetId}${versionID ? `/vpid/${versionID}` : ''}`;
return `${baseUrl}/${service}${variant ? `/${variant}` : ''}/av-embeds/${assetId}${versionPID ? `/vpid/${versionPID}` : ''}`;
}

if (platform === 'articles') {
return `${baseUrl}/ws/av-embeds/articles/${assetId}${versionID ? `/${versionID}` : ''}${lang ? `/${lang}` : ''}`;
return `${baseUrl}/ws/av-embeds/articles/${assetId}${parentPID ? `/${parentPID}` : ''}${lang ? `/${lang}` : ''}`;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ exports[`AMP Articles SEO Linked data should match text 2`] = `
"@type": "VideoObject",
"description": "They may be tiny, but us humans could learn a thing or two from ants.",
"duration": "PT3M11S",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/c2nr6xqmnewo/p01k6msp/ha",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/c2nr6xqmnewo/p01k6msm/ha",
"name": "Five things ants can teach us about management",
"thumbnailUrl": "https://ichef.test.bbci.co.uk/images/ic/1024x576/p01k6mtv.jpg",
"uploadDate": "2018-10-22T14:35:32.000Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ exports[`Canonical Articles SEO Linked data should match text 2`] = `
"@type": "VideoObject",
"description": "They may be tiny, but us humans could learn a thing or two from ants.",
"duration": "PT3M11S",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/c2nr6xqmnewo/p01k6msp/ha",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/c2nr6xqmnewo/p01k6msm/ha",
"name": "Five things ants can teach us about management",
"thumbnailUrl": "https://ichef.test.bbci.co.uk/images/ic/1024x576/p01k6mtv.jpg",
"uploadDate": "2018-10-22T14:35:32.000Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ exports[`AMP Articles SEO Linked data should match text 2`] = `
"@type": "VideoObject",
"description": "ُثسف شسسثف",
"duration": "PT16S",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/cej3lzd5e0go/p01kf9q6/fa",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/cej3lzd5e0go/p01kf9q4/fa",
"name": "«قشزهذ شسسثف هر ُثسف",
"thumbnailUrl": "https://ichef.test.bbci.co.uk/images/ic/1024x576/p01kf9s0.jpg",
"uploadDate": "2018-11-12T15:00:22.000Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ exports[`Canonical Articles SEO Linked data should match text 2`] = `
"@type": "VideoObject",
"description": "ُثسف شسسثف",
"duration": "PT16S",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/cej3lzd5e0go/p01kf9q6/fa",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/cej3lzd5e0go/p01kf9q4/fa",
"name": "«قشزهذ شسسثف هر ُثسف",
"thumbnailUrl": "https://ichef.test.bbci.co.uk/images/ic/1024x576/p01kf9s0.jpg",
"uploadDate": "2018-11-12T15:00:22.000Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ exports[`AMP Articles SEO Linked data should match text 2`] = `
"@type": "VideoObject",
"description": "They may be tiny, but us humans could learn a thing or two from ants.",
"duration": "PT3M11S",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/czwj5l0n210o/p01k6msp/en-GB",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/czwj5l0n210o/p01k6msm/en-GB",
"name": "Five things ants can teach us about management",
"thumbnailUrl": "https://ichef.test.bbci.co.uk/images/ic/1024x576/p01k6mtv.jpg",
"uploadDate": "2018-10-22T14:35:32.000Z",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ exports[`Canonical Articles SEO Linked data should match text 2`] = `
"@type": "VideoObject",
"description": "They may be tiny, but us humans could learn a thing or two from ants.",
"duration": "PT3M11S",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/czwj5l0n210o/p01k6msp/en-GB",
"embedURL": "https://www.test.bbc.com/ws/av-embeds/articles/czwj5l0n210o/p01k6msm/en-GB",
"name": "Five things ants can teach us about management",
"thumbnailUrl": "https://ichef.test.bbci.co.uk/images/ic/1024x576/p01k6mtv.jpg",
"uploadDate": "2018-10-22T14:35:32.000Z",
Expand Down
Loading
Loading