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

WSTEAMA-1565 - Remove old route pattern matcher #12342

Merged
merged 18 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fa538e8
Merge branch 'latest' of github.com:bbc/simorgh into latest
louisearchibald Jan 24, 2025
951be9c
Merge branch 'latest' of github.com:bbc/simorgh into latest
louisearchibald Jan 28, 2025
d6718e1
delete old route matcher
louisearchibald Jan 28, 2025
282117b
remove reference to old route matcher in utils regex
louisearchibald Jan 28, 2025
ebe590e
remove reference to old route matcher in routes/topic/index
louisearchibald Jan 28, 2025
e0cc21a
rename new route matcher to refer to topic page regex and not variant…
louisearchibald Jan 28, 2025
a1abd53
update references to new route matcher to reflect new name
louisearchibald Jan 28, 2025
f299df8
reference update
louisearchibald Jan 28, 2025
bdefced
delete old topic tests and rename new route tests to be topicPath
louisearchibald Jan 28, 2025
eb9d841
Merge branch 'latest' into WSTEAMA-1565-remove-old-route-pattern-matcher
louisearchibald Jan 28, 2025
d1c1206
Merge branch 'WSTEAMA-1565-remove-old-route-pattern-matcher' of githu…
louisearchibald Jan 28, 2025
82ba57a
delete old route server topic tests
louisearchibald Jan 28, 2025
db22630
rename new route server topic tests to be not variant specific
louisearchibald Jan 28, 2025
d4ab9a1
reference update
louisearchibald Jan 28, 2025
638dcc8
Merge branch 'latest' into WSTEAMA-1565-remove-old-route-pattern-matcher
louisearchibald Jan 28, 2025
5a66f2c
Merge branch 'WSTEAMA-1565-remove-old-route-pattern-matcher' of githu…
louisearchibald Jan 28, 2025
054e113
snapshots
louisearchibald Jan 28, 2025
653b8e2
Merge branch 'latest' into WSTEAMA-1565-remove-old-route-pattern-matcher
amoore108 Jan 28, 2025
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
4 changes: 2 additions & 2 deletions src/app/routes/topic/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { TopicPage } from '#pages';
import { topicPath, variantTopicPath } from '#app/routes/utils/regex';
import { topicPath } from '#app/routes/utils/regex';
import { TOPIC_PAGE } from '#app/routes/utils/pageTypes';
import getInitialData from './getInitialData';

export default {
path: [topicPath, variantTopicPath, '/persian/afghanistan'],
path: [topicPath, '/persian/afghanistan'],
exact: true,
component: TopicPage,
getInitialData,
Expand Down
3 changes: 0 additions & 3 deletions src/app/routes/utils/regex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
getOnDemandRadioRegex,
getOnDemandTvRegex,
getTopicPageRegex,
getVariantTopicPageRegex,
getErrorPageRegex,
getLegacyAssetRegex,
getMostReadPageRegex,
Expand Down Expand Up @@ -66,8 +65,6 @@ export const onDemandTvDataPath = `${onDemandTvPath}.json`;
export const topicPath = getTopicPageRegex(allServices);
export const topicDataPath = `${topicPath}.json`;

export const variantTopicPath = getVariantTopicPageRegex(allServices);

export const errorPagePath = getErrorPageRegex(allServices);

export const legacyAssetPagePath = getLegacyAssetRegex(allServices);
Expand Down
28 changes: 2 additions & 26 deletions src/app/routes/utils/regex/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
tipoHomeDataPath,
tipoHomePath,
topicPath,
variantTopicPath,
} from './index';

import serviceConfig from '../../../lib/config/services/loadableConfig';
Expand Down Expand Up @@ -607,37 +606,14 @@ describe('frontPage -> homePage migration', () => {
});

describe('topicPath', () => {
const validRoutes = [
'/zhongwen/trad/topics/cd6qem06z92t',
'/zhongwen/trad/topics/c1ez1k4emn0t',
'/serbian/lat/topics/cr50vdy9q6wt',
'/serbian/lat/topics/c2lej05e1eqt',
'/pidgin/topics/c2dwqd1zr92t',
];
shouldMatchValidRoutes(validRoutes, topicPath);

const invalidRoutes = [
'/serbian/topics/c2lej05e1eqt/lat',
'/serbian/topics/c2lej05qwesae1eqt/lat',
'/zhongwen/c1ez1k4emn0t',
'/zhongwen/trad/topics',
'/hindi/topic/c5jje4ejkqv',
'/mundo/topic/',
'/serbian/topic/c5jje4ejkqvo/foobar',
'/urdu/topic/c5jje4ejkqvo/.amp',
];
shouldNotMatchInvalidRoutes(invalidRoutes, topicPath);
});

describe('topicVariantPath', () => {
const validRoutes = [
'/zhongwen/topics/cd6qem06z92t/trad',
'/zhongwen/topics/c1ez1k4emn0t/trad',
'/serbian/topics/cr50vdy9q6wt/lat',
'/serbian/topics/c2lej05e1eqt/lat',
'/pidgin/topics/c2dwqd1zr92t',
];
shouldMatchValidRoutes(validRoutes, variantTopicPath);
shouldMatchValidRoutes(validRoutes, topicPath);

const invalidRoutes = [
'/serbian/lat/topics/c2lej05e1eqt',
Expand All @@ -649,5 +625,5 @@ describe('topicVariantPath', () => {
'/serbian/topic/c5jje4ejkqvo/foobar',
'/urdu/topic/c5jje4ejkqvo/.amp',
];
shouldNotMatchInvalidRoutes(invalidRoutes, variantTopicPath);
shouldNotMatchInvalidRoutes(invalidRoutes, topicPath);
});
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ exports[`regex utils snapshots should create expected regex from getTipoHomeRege

exports[`regex utils snapshots should create expected regex from getTipoHomeRegex when isLive = true 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/tipohome:amp(.amp)?:lite(.lite)?"`;

exports[`regex utils snapshots should create expected regex from getTopicPageRegex when isLive = false 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/topics/:id([a-z0-9]+)?:lite(.lite)?"`;
exports[`regex utils snapshots should create expected regex from getTopicPageRegex when isLive = false 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/topics/:id([a-z0-9]+)?:variant(/simp|/trad|/cyr|/lat)?:lite(.lite)?"`;

exports[`regex utils snapshots should create expected regex from getTopicPageRegex when isLive = true 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen):variant(/simp|/trad|/cyr|/lat)?/topics/:id([a-z0-9]+)?:lite(.lite)?"`;

exports[`regex utils snapshots should create expected regex from getVariantTopicPageRegex when isLive = false 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/topics/:id([a-z0-9]+)?:variant(/simp|/trad|/cyr|/lat)?:lite(.lite)?"`;

exports[`regex utils snapshots should create expected regex from getVariantTopicPageRegex when isLive = true 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/topics/:id([a-z0-9]+)?:variant(/simp|/trad|/cyr|/lat)?:lite(.lite)?"`;
exports[`regex utils snapshots should create expected regex from getTopicPageRegex when isLive = true 1`] = `"/:service(afaanoromoo|afrique|amharic|arabic|archive|azeri|bengali|burmese|cymrufyw|gahuza|gujarati|hausa|hindi|igbo|indonesia|japanese|korean|kyrgyz|marathi|mundo|naidheachdan|nepali|news|newsround|pashto|persian|pidgin|portuguese|punjabi|russian|scotland|serbian|sinhala|somali|sport|swahili|tamil|telugu|thai|tigrinya|turkce|ukchina|ukrainian|urdu|uzbek|vietnamese|ws|yoruba|zhongwen)/topics/:id([a-z0-9]+)?:variant(/simp|/trad|/cyr|/lat)?:lite(.lite)?"`;
5 changes: 0 additions & 5 deletions src/app/routes/utils/regex/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ export const getOnDemandTvRegex = services => {
};

export const getTopicPageRegex = services => {
const serviceRegex = getServiceRegex(services);
return `/:service(${serviceRegex}):variant(${variantRegex})?/topics/:id(${topicIdRegex})?:lite(${liteRegex})?`;
};

export const getVariantTopicPageRegex = services => {
const serviceRegex = getServiceRegex(services);
return `/:service(${serviceRegex})/topics/:id(${topicIdRegex})?:variant(${variantRegex})?:lite(${liteRegex})?`;
};
Expand Down
96 changes: 1 addition & 95 deletions src/server/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,100 +397,6 @@ const testArticles = ({ platform, service, variant, queryString = '' }) => {
};

const testTopics = ({ service, variant, queryString = '' }) => {
describe(`Tipo Topic: /${service}/${variant}/topics/tipoId${queryString}`, () => {
const successDataResponse = {
data: { some: 'data' },
service: 'someService',
status: 200,
};

const notFoundDataResponse = {
data: { some: 'data' },
service: 'someService',
status: 404,
};

const id = `c0000000001o`;
const topicURL = `/${service}/${variant}/topics/${id}${queryString}`;

describe('Successful render', () => {
describe('200 status code', () => {
beforeEach(() => {
mockRouteProps({
id,
service,
dataResponse: successDataResponse,
variant,
});
});

const configs = {
url: topicURL,
service,
successDataResponse,
variant,
};

it('should respond with rendered data', testRenderedData(configs));
});

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

beforeEach(() => {
mockRouteProps({
id,
service,
dataResponse: notFoundDataResponse,
variant,
pageType,
});
});

it('should respond with a rendered 404', async () => {
const { status, text } = await makeRequest(topicURL);
expect(status).toBe(404);
expect(text).toEqual(
'<!doctype html><html><body><h1>Mock app</h1></body></html>',
);
});

assertNon200ResponseCustomMetrics({
requestUrl: topicURL,
pageType,
statusCode: 404,
});
});
});

describe('Unknown error within the data fetch, react router or its dependencies', () => {
const pageType = 'topic';
beforeEach(() => {
mockRouteProps({
id,
service,
dataResponse: Error('Error!'),
responseType: 'reject',
variant,
pageType,
});
});

it('should respond with a 500', async () => {
const { status, text } = await makeRequest(topicURL);
expect(status).toEqual(500);
expect(text).toEqual('Internal server error');
});

assertNon200ResponseCustomMetrics({
requestUrl: topicURL,
pageType,
});
});
});
};

const testVariantTopics = ({ service, variant, queryString = '' }) => {
describe(`Tipo Topic: /${service}/topics/tipoId/${variant}${queryString}`, () => {
const successDataResponse = {
data: { some: 'data' },
Expand Down Expand Up @@ -1391,7 +1297,7 @@ describe('Server', () => {

testTopics({ service: 'pidgin' });

testVariantTopics({ service: 'zhongwen', variant: 'simp' });
testTopics({ service: 'zhongwen', variant: 'simp' });

testMediaPages({
platform: 'amp',
Expand Down
Loading