Skip to content

Commit

Permalink
Merge branch 'latest' into revert-11261-revert-11122-remove-nodefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
amoore108 authored Apr 24, 2024
2 parents 373639e + b0a4822 commit f168a45
Show file tree
Hide file tree
Showing 78 changed files with 19,139 additions and 2,099 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 18 additions & 2 deletions cypress/e2e/pages/mediaAssetPage/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,30 @@ const getMediaId = jsonData => {
return versionId || externalId || id;
};

const getCAFMediaID = jsonData => {
const mediaBlock = jsonData.promo.extrinsicPromo?.media;
const aresMediaBlock = mediaBlock.blocks[0].model.blocks[1];
const aresMediaMetadataBlock = aresMediaBlock.model.blocks[0].model;

const [versionId, externalId, id] = paths(
[['versions', 0, 'versionId'], ['externalId'], ['id']],
aresMediaMetadataBlock,
);

return versionId || externalId || id;
};

export const getEmbedUrl = (jsonData, language, isAmp = false) => {
const prefix = jsonData.promo.media.type === 'legacyMedia' ? 'legacy' : 'cps';
const prefix =
jsonData.promo.media?.type === 'legacyMedia' ? 'legacy' : 'cps';

const mediaID = getMediaId(jsonData) || getCAFMediaID(jsonData);

const embedUrl = [
isAmp ? envConfig.avEmbedBaseUrlAmp : envConfig.avEmbedBaseUrlCanonical,
'ws/av-embeds',
`${prefix}${jsonData.metadata.locators.assetUri}`,
getMediaId(jsonData),
mediaID,
language,
].join('/');

Expand Down
6 changes: 5 additions & 1 deletion cypress/e2e/pages/mediaAssetPage/testsForAMPOnly.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable import/prefer-default-export */
import config from '../../../support/config/services';
import appConfig from '../../../../src/server/utilities/serviceConfigs';
import CafEnabledServices from '../../../../src/app/lib/cafServices.const';
import { getEmbedUrl, hasMedia } from './helpers';

// For testing features that may differ across services but share a common logic e.g. translated strings.
Expand All @@ -12,10 +13,13 @@ export const testsThatFollowSmokeTestConfigForAMPOnly = ({
describe(`testsThatFollowSmokeTestConfigForAMPOnly for ${service} ${pageType}`, () => {
describe('Media Player', () => {
const language = appConfig[config[service].name][variant].lang;
const pageTypeForFetch = CafEnabledServices.includes(service)
? 'article'
: 'cpsAsset';

it('should render an iframe with a valid URL', () => {
if (!`${Cypress.env('currentPath')}`.includes('/russian/av/')) {
cy.getPageData({ service, pageType: 'cpsAsset', variant }).then(
cy.getPageData({ service, pageType: pageTypeForFetch, variant }).then(
({ body }) => {
const {
data: { article: jsonData },
Expand Down
6 changes: 5 additions & 1 deletion cypress/e2e/pages/mediaAssetPage/testsForCanonicalOnly.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable import/prefer-default-export */
import config from '../../../support/config/services';
import appConfig from '../../../../src/server/utilities/serviceConfigs';
import CafEnabledServices from '../../../../src/app/lib/cafServices.const';
import { getEmbedUrl, hasMedia } from './helpers';
import appToggles from '../../../support/helpers/useAppToggles';
import envConfig from '../../../support/config/envs';
Expand All @@ -14,10 +15,13 @@ export const testsThatFollowSmokeTestConfigForCanonicalOnly = ({
describe(`testsThatFollowSmokeTestConfigForCanonicalOnly for ${service} ${pageType}`, () => {
describe('Media Player', () => {
const language = appConfig[config[service].name][variant].lang;
const pageTypeForFetch = CafEnabledServices.includes(service)
? 'article'
: 'cpsAsset';

it('should render an iframe with a valid URL', () => {
if (!`${Cypress.env('currentPath')}`.includes('/russian/av/')) {
cy.getPageData({ service, pageType: 'cpsAsset', variant }).then(
cy.getPageData({ service, pageType: pageTypeForFetch, variant }).then(
({ body }) => {
const {
data: { article: jsonData },
Expand Down
25 changes: 19 additions & 6 deletions cypress/e2e/pages/photoGalleryPage/tests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import CafEnabledServices from '../../../../src/app/lib/cafServices.const';

/* eslint-disable import/prefer-default-export */
// For testing features that may differ across services but share a common logic e.g. translated strings.
export const testsThatFollowSmokeTestConfig = ({
Expand All @@ -7,12 +9,23 @@ export const testsThatFollowSmokeTestConfig = ({
}) => {
describe(`testsThatFollowSmokeTestConfig to run for ${service} ${variant} ${pageType}`, () => {
it('should render a description for the page', () => {
cy.getPageData({ service, pageType: 'cpsAsset', variant }).then(
({ body }) => {
const description = body.data.article.promo.summary;
cy.get('main p').first().should('contain', description);
},
);
if (CafEnabledServices.includes(service)) {
cy.getPageData({ service, pageType: 'article', variant }).then(
({ body }) => {
const description =
body.data.article.promo.summary.blocks[0].model.blocks[0].model
.text;
cy.get('main p').first().should('contain', description);
},
);
} else {
cy.getPageData({ service, pageType: 'cpsAsset', variant }).then(
({ body }) => {
const description = body.data.article.promo.summary;
cy.get('main p').first().should('contain', description);
},
);
}
});
});
};
26 changes: 22 additions & 4 deletions cypress/e2e/pages/storyPage/tests.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
/* eslint-disable import/prefer-default-export */
import pathOr from 'ramda/src/pathOr';
import path from 'ramda/src/path';
import paths from 'ramda/src/paths';
import getDataUrl from '../../../support/helpers/getDataUrl';
import topicTagsTest from '../../../support/helpers/topicTagsTest';
import envConfig from '../../../support/config/envs';
import { crossPlatform as mostReadAssertions } from '../mostReadPage/mostReadAssertions';
import getAppEnv from '../../../support/helpers/getAppEnv';
import CafEnabledServices from '../../../../src/app/lib/cafServices.const';

const twoYearsAgo = new Date().getFullYear() - 2;

Expand All @@ -19,18 +21,33 @@ const isArticleLessThanTwoYearsOld = () => {
});
};

const getContentBlocks = body => {
const contentBlock = body.data.article.content;

const [cpsAssetBlocks, cafBlocks] = paths(
[['blocks'], ['model', 'blocks']],
contentBlock,
);
return cpsAssetBlocks || cafBlocks;
};

// For testing features that may differ across services but share a common logic e.g. translated strings.
export const testsThatFollowSmokeTestConfig = ({
service,
pageType,
isAmp,
variant,
}) => {
const pageTypeForFetch = CafEnabledServices.includes(service)
? 'article'
: 'cpsAsset';

describe(`testsThatFollowSmokeTestConfig to run for ${service} ${variant} ${pageType} `, () => {
it('should render a description for the page', () => {
cy.getPageData({ service, pageType: 'cpsAsset', variant }).then(
cy.getPageData({ service, pageType: pageTypeForFetch, variant }).then(
({ body }) => {
const descriptionBlock = body.data.article.content.blocks.find(
const contentBlocks = getContentBlocks(body);
const descriptionBlock = contentBlocks.find(
block => block.role === 'introduction',
);
// Condition added because introduction is non-mandatory
Expand All @@ -47,9 +64,10 @@ export const testsThatFollowSmokeTestConfig = ({
});

it('should render paragraph text for the page', () => {
cy.getPageData({ service, pageType: 'cpsAsset', variant }).then(
cy.getPageData({ service, pageType: pageTypeForFetch, variant }).then(
({ body }) => {
const paragraphBlock = body.data.article.content.blocks.find(
const contentBlocks = getContentBlocks(body);
const paragraphBlock = contentBlocks.find(
block => block.type === 'paragraph',
);
// Conditional because in test assets the data model structure is sometimes variable and unusual
Expand Down
15 changes: 9 additions & 6 deletions cypress/support/commands/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// - Certain types of network error are retried automatically (retryOnNetworkFailure)
import config from '../config/services';

const getOptimoOrTipoId = path => path.match(/(c[a-zA-Z0-9]{10}(o|t))/)?.[1];

export const testResponseCodeAndType = ({
path,
responseCode,
Expand Down Expand Up @@ -117,14 +119,15 @@ export const getPageData = ({ service, pageType, variant = 'default', id }) => {
: 'live';
}
const ctxServEnv = ctxEnv || env;
const pageTypeId =
id ||
(pageType === 'cpsAsset'
? Cypress.env('currentPath')
: Cypress.env('currentPath').match(/(c[a-zA-Z0-9]{10}(o|t))/)?.[1]);

const assetId =
id || // passed in as an argument
getOptimoOrTipoId(Cypress.env('currentPath')) || // Extract Optimo or Tipo ID from the current path
`${Cypress.env('currentPath')}`; // Extract the current path as the asset ID (typically CPS pages)

const bffUrl = `https://web-cdn.${
env === 'live' ? '' : `${env}.`
}api.bbci.co.uk/fd/simorgh-bff?pageType=${pageType}&id=${pageTypeId}&service=${service}${
}api.bbci.co.uk/fd/simorgh-bff?pageType=${pageType}&id=${assetId}&service=${service}${
variant !== 'default' ? `&variant=${variant}` : ''
}`;
return cy.request({
Expand Down
26 changes: 13 additions & 13 deletions cypress/support/config/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@ module.exports = () => ({
enabled: true,
},
},
smoke: false,
smoke: true,
},
mostWatchedPage: { environments: undefined, smoke: false },
photoGalleryPage: {
Expand All @@ -2063,18 +2063,18 @@ module.exports = () => ({
environments: {
live: {
paths: ['/hausa/labarai-54292969'],
enabled: false,
enabled: true,
},
test: {
paths: ['/hausa/labarai-23190660'],
enabled: false,
enabled: true,
},
local: {
paths: [],
enabled: false,
paths: ['/hausa/labarai-23190660'],
enabled: true,
},
},
smoke: false,
smoke: true,
},
mostReadPage: {
environments: {
Expand Down Expand Up @@ -4775,7 +4775,7 @@ module.exports = () => ({
enabled: true,
},
},
smoke: false,
smoke: true,
},
mostWatchedPage: { environments: undefined, smoke: false },
photoGalleryPage: {
Expand Down Expand Up @@ -6965,7 +6965,7 @@ module.exports = () => ({
enabled: true,
},
},
smoke: false,
smoke: true,
},
mostWatchedPage: { environments: undefined, smoke: false },
photoGalleryPage: {
Expand All @@ -6983,24 +6983,24 @@ module.exports = () => ({
enabled: true,
},
},
smoke: false,
smoke: true,
},
storyPage: {
environments: {
live: {
paths: ['/thai/international-53381389'],
enabled: false,
enabled: true,
},
test: {
paths: ['/thai/23124008'],
enabled: false,
enabled: true,
},
local: {
paths: ['/thai/international-23252825'],
enabled: false,
enabled: true,
},
},
smoke: false,
smoke: true,
},
mostReadPage: {
environments: {
Expand Down
Loading

0 comments on commit f168a45

Please sign in to comment.