-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11968 from bbc/av-embeds-externalembedurl-logic-r…
…efactor Av-embeds `externalEmbedUrl` logic refactor
- Loading branch information
Showing
8 changed files
with
245 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 184 additions & 0 deletions
184
src/app/components/MediaLoader/utils/urlConstructors.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
import { getAmpIframeUrl, getExternalEmbedUrl } from './urlConstructors'; | ||
|
||
/* | ||
Note: | ||
The 'id' field is the ID of the page being visited, so for canonical article pages it would be something like: '/thai/international-55160422'. | ||
For Syndicated routes, it would be something like /serbian/cyr/av-embeds/srbija-68707945 or /ws/av-embeds/articles/cd1rmn075d1o/p0jd37n8/ig | ||
*/ | ||
|
||
const ampIframeTestCases = [ | ||
{ | ||
description: 'should build an AMP iframe URL for the page', | ||
cases: [ | ||
{ | ||
description: 'CPS without variant', | ||
id: 'thai/international-55160422', | ||
versionID: '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)', | ||
id: 'thai/international-55160422', | ||
lang: 'th', | ||
expected: | ||
'https://web-cdn.test.api.bbci.co.uk/ws/av-embeds/cps/thai/international-55160422/th/amp', | ||
}, | ||
{ | ||
description: 'CPS with variant', | ||
id: 'serbian/cyr/srbija-68707945', | ||
versionID: '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)', | ||
id: 'serbian/cyr/srbija-68707945', | ||
lang: 'sr-cyrl', | ||
expected: | ||
'https://web-cdn.test.api.bbci.co.uk/ws/av-embeds/cps/serbian/cyr/srbija-68707945/sr-cyrl/amp', | ||
}, | ||
{ | ||
description: 'Optimo', | ||
id: 'mundo/articles/c805k05kr73o', | ||
versionID: 'p0cfmdwn', | ||
lang: 'es', | ||
expected: | ||
'https://web-cdn.test.api.bbci.co.uk/ws/av-embeds/articles/c805k05kr73o/p0cfmdwn/es/amp', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const externalEmbedUrlTestCases = [ | ||
{ | ||
description: 'should build an external embed URL for the page', | ||
cases: [ | ||
{ | ||
description: 'CPS without variant', | ||
id: 'thai/international-55160422', | ||
versionID: 'p0908t9z', | ||
lang: 'th', | ||
expected: | ||
'https://www.test.bbc.com/thai/av-embeds/international-55160422/vpid/p0908t9z', | ||
}, | ||
{ | ||
description: 'CPS without variant (no versionID)', | ||
id: 'thai/international-55160422', | ||
lang: 'th', | ||
expected: | ||
'https://www.test.bbc.com/thai/av-embeds/international-55160422', | ||
}, | ||
{ | ||
description: 'CPS with variant', | ||
id: 'serbian/cyr/srbija-68707945', | ||
versionID: 'p0cfmdwn', | ||
lang: 'sr-cyrl', | ||
expected: | ||
'https://www.test.bbc.com/serbian/cyr/av-embeds/srbija-68707945/vpid/p0cfmdwn', | ||
}, | ||
{ | ||
description: 'CPS with variant (no versionID)', | ||
id: 'serbian/cyr/srbija-68707945', | ||
lang: 'sr-cyrl', | ||
expected: | ||
'https://www.test.bbc.com/serbian/cyr/av-embeds/srbija-68707945', | ||
}, | ||
{ | ||
description: 'CPS Syndicated route without variant', | ||
id: 'news/av-embeds/58869966/vpid/p07r2y68', | ||
versionID: 'p07r2y68', | ||
lang: 'en-gb', | ||
expected: | ||
'https://www.test.bbc.com/news/av-embeds/58869966/vpid/p07r2y68', | ||
}, | ||
{ | ||
description: 'CPS Syndicated route without variant (no versionID)', | ||
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', | ||
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)', | ||
id: 'serbian/cyr/av-embeds/srbija-68707945', | ||
lang: 'sr-cyrl', | ||
expected: | ||
'https://www.test.bbc.com/serbian/cyr/av-embeds/srbija-68707945', | ||
}, | ||
{ | ||
description: 'Optimo', | ||
id: 'mundo/articles/c805k05kr73o', | ||
versionID: 'p0cfmdwn', | ||
lang: 'es', | ||
expected: | ||
'https://www.test.bbc.com/ws/av-embeds/articles/c805k05kr73o/p0cfmdwn/es', | ||
}, | ||
{ | ||
description: 'Optimo (no versionID)', | ||
id: 'mundo/articles/c805k05kr73o', | ||
lang: 'es', | ||
expected: | ||
'https://www.test.bbc.com/ws/av-embeds/articles/c805k05kr73o/es', | ||
}, | ||
{ | ||
description: 'Optimo Syndicated route', | ||
id: 'ws/av-embeds/articles/cd1rmn075d1o/p0jd37n8/ig', | ||
versionID: 'p0jd37n8', | ||
lang: 'ig', | ||
expected: | ||
'https://www.test.bbc.com/ws/av-embeds/articles/cd1rmn075d1o/p0jd37n8/ig', | ||
}, | ||
{ | ||
description: 'Optimo Syndicated route (no versionID)', | ||
id: 'ws/av-embeds/articles/cd1rmn075d1o/p0jd37n8/ig', | ||
lang: 'ig', | ||
expected: | ||
'https://www.test.bbc.com/ws/av-embeds/articles/cd1rmn075d1o/ig', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
describe('urlConstructors', () => { | ||
describe('AMP iframe URL', () => { | ||
ampIframeTestCases.forEach(({ description, cases }) => { | ||
describe(description, () => { | ||
cases.forEach( | ||
({ description: caseDescription, id, versionID, lang, expected }) => { | ||
it(caseDescription, () => { | ||
expect(getAmpIframeUrl({ id, versionID, lang })).toEqual( | ||
expected, | ||
); | ||
}); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('External embed URL', () => { | ||
externalEmbedUrlTestCases.forEach(({ description, cases }) => { | ||
describe(description, () => { | ||
cases.forEach( | ||
({ description: caseDescription, id, versionID, lang, expected }) => { | ||
it(caseDescription, () => { | ||
expect(getExternalEmbedUrl({ id, versionID, lang })).toEqual( | ||
expected, | ||
); | ||
}); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import isLive from '#app/lib/utilities/isLive'; | ||
import parseAvRoute from '#app/routes/utils/parseAvRoute'; | ||
|
||
const LIVE_BASE_URL = 'https://www.bbc.com'; | ||
const TEST_BASE_URL = 'https://www.test.bbc.com'; | ||
|
||
const LIVE_AMP_URL = 'https://web-cdn.api.bbci.co.uk'; | ||
const TEST_AMP_URL = 'https://web-cdn.test.api.bbci.co.uk'; | ||
|
||
type FuncProps = { | ||
id: string | null; | ||
versionID?: string; | ||
lang?: string; | ||
}; | ||
|
||
export const getAmpIframeUrl = ({ id, versionID, 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`; | ||
} | ||
|
||
if (platform === 'articles') { | ||
return `${ampBaseUrl}/ws/av-embeds/articles/${assetId}${versionID ? `/${versionID}` : ''}${lang ? `/${lang}` : ''}/amp`; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export const getExternalEmbedUrl = ({ id, versionID, 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}` : ''}`; | ||
} | ||
|
||
if (platform === 'articles') { | ||
return `${baseUrl}/ws/av-embeds/articles/${assetId}${versionID ? `/${versionID}` : ''}${lang ? `/${lang}` : ''}`; | ||
} | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters