diff --git a/.env b/.env index 9dd92f33d90..9d8a631ae2e 100644 --- a/.env +++ b/.env @@ -8,4 +8,3 @@ SIMORGH_INCLUDES_BASE_URL=https://www.test.bbc.com/ws/includes LOG_DIR='log' LOG_LEVEL='debug' SIMORGH_APP_ENV=local - diff --git a/src/app/containers/ChartbeatAnalytics/utils/index.js b/src/app/containers/ChartbeatAnalytics/utils/index.js index e6148fa7cf8..345de39fc57 100644 --- a/src/app/containers/ChartbeatAnalytics/utils/index.js +++ b/src/app/containers/ChartbeatAnalytics/utils/index.js @@ -43,6 +43,8 @@ export const getType = (pageType, shorthand = false) => { return 'STY'; case 'PGL': return 'PGL'; + case 'FIX': + return 'FIX'; default: return null; } @@ -121,6 +123,8 @@ export const getTitle = ({ pageType, pageData, brandName, title }) => { return path(['promo', 'headlines', 'headline'], pageData); case 'PGL': return path(['promo', 'headlines', 'headline'], pageData); + case 'FIX': + return getPageTitle(pageData, brandName); default: return null; } diff --git a/src/app/containers/ChartbeatAnalytics/utils/index.test.js b/src/app/containers/ChartbeatAnalytics/utils/index.test.js index bf5fd8c24d0..e2b0277470f 100644 --- a/src/app/containers/ChartbeatAnalytics/utils/index.test.js +++ b/src/app/containers/ChartbeatAnalytics/utils/index.test.js @@ -56,6 +56,11 @@ describe('Chartbeat utilities', () => { expectedDefaultType: 'Index', expectedShortType: 'IDX', }, + { + type: 'FIX', + expectedDefaultType: 'FIX', + expectedShortType: 'FIX', + }, { type: 'MAP', expectedDefaultType: 'article-media-asset', @@ -263,6 +268,7 @@ describe('Chartbeat utilities', () => { pageType | brandName | pageTitle | expectedNumberOfCalls ${'index'} | ${'BBC News'} | ${'This is an index page title'} | ${1} ${'IDX'} | ${'BBC Persian'} | ${'This is an IDX page title'} | ${1} + ${'FIX'} | ${'BBC Afrique'} | ${'This is an FIX page title'} | ${1} ${'frontPage'} | ${'BBC News'} | ${'This is a frontpage title'} | ${1} ${'article'} | ${null} | ${'This is an article title'} | ${1} ${'foo'} | ${'BBC News'} | ${null} | ${0} @@ -784,6 +790,86 @@ describe('Chartbeat utilities', () => { expect(getConfig(fixtureData)).toStrictEqual(expectedConfig); }); + it('should return config for canonical pages when page type is FIX and env is not live', () => { + const fixtureData = { + isAmp: false, + platform: 'canonical', + pageType: 'FIX', + data: {}, + brandName: 'BBC-Afique', + chartbeatDomain: 'bbc.co.uk', + env: 'test', + service: 'afrique', + origin: 'test.bbc.com', + previousPath: '/previous-path', + }; + + const expectedConfig = { + domain: 'test.bbc.co.uk', + idSync: { + bbc_hid: 'foobar', + }, + path: '/', + sections: 'Afrique, Afrique - FIX', + title: 'This is a Feature Index page title', + type: 'FIX', + uid: 50924, + useCanonical: true, + virtualReferrer: 'test.bbc.com/previous-path', + }; + + const mockTitle = jest + .fn() + .mockImplementation(() => 'This is a Feature Index page title'); + + frontPageUtils.getPageTitle = mockTitle; + + const expectedCookieValue = 'foobar'; + jest.spyOn(Cookie, 'get').mockImplementation(() => expectedCookieValue); + + expect(getConfig(fixtureData)).toStrictEqual(expectedConfig); + }); + + it('should return config for canonical pages when page type is IDX and env is not live', () => { + const fixtureData = { + isAmp: false, + platform: 'canonical', + pageType: 'IDX', + data: {}, + brandName: 'BBC-Persian', + chartbeatDomain: 'bbc.co.uk', + env: 'test', + service: 'persian', + origin: 'test.bbc.com', + previousPath: '/previous-path', + }; + + const expectedConfig = { + domain: 'test.bbc.co.uk', + idSync: { + bbc_hid: 'foobar', + }, + path: '/', + sections: 'Persian, Persian - IDX', + title: 'This is an index page title', + type: 'Index', + uid: 50924, + useCanonical: true, + virtualReferrer: 'test.bbc.com/previous-path', + }; + + const mockTitle = jest + .fn() + .mockImplementation(() => 'This is an index page title'); + + frontPageUtils.getPageTitle = mockTitle; + + const expectedCookieValue = 'foobar'; + jest.spyOn(Cookie, 'get').mockImplementation(() => expectedCookieValue); + + expect(getConfig(fixtureData)).toStrictEqual(expectedConfig); + }); + it('should return null for virtualReferrer when there is no previousPath', () => { const fixtureData = { isAmp: false,