-
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 #10819 from bbc/WSTEAMA-359-new-pianoanalytics-com…
…ponent WSTEAMA-422: Simorgh Fetches Certain ATI (Piano) Metadata Analytics for new Homepage via BFF
- Loading branch information
Showing
11 changed files
with
318 additions
and
38 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
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
71 changes: 71 additions & 0 deletions
71
src/app/components/ATIAnalytics/params/genericPage/buildParams.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,71 @@ | ||
import * as analyticsUtils from '#lib/analyticsUtils'; | ||
import { RequestContextProps } from '../../../../contexts/RequestContext'; | ||
import { ServiceConfig } from '../../../../models/types/serviceConfig'; | ||
import { buildPageATIParams, buildPageATIUrl } from './buildParams'; | ||
|
||
(analyticsUtils.getAtUserId as jest.Mock) = jest.fn(); | ||
(analyticsUtils.getCurrentTime as jest.Mock) = jest | ||
.fn() | ||
.mockReturnValue('00-00-00'); | ||
(analyticsUtils.getPublishedDatetime as jest.Mock) = jest | ||
.fn() | ||
.mockReturnValue('1970-01-01T00:00:00.000Z'); | ||
|
||
// @ts-expect-error - only partial data required for testing purposes | ||
const requestContext: RequestContextProps = { | ||
platform: 'canonical', | ||
statsDestination: 'statsDestination', | ||
id: 'validId', | ||
}; | ||
|
||
// @ts-expect-error - only partial data required for testing purposes | ||
const serviceContext: ServiceConfig = { | ||
atiAnalyticsAppName: 'atiAnalyticsAppName', | ||
atiAnalyticsProducerId: 'atiAnalyticsProducerId', | ||
service: 'pidgin', | ||
lang: 'pcm', | ||
}; | ||
|
||
const atiData = { | ||
analytics: { | ||
contentId: 'urn:bbc:tipo:topic:cm7682qz7v1t', | ||
contentType: 'index-home', | ||
pageIdentifier: 'kyrgyz.page', | ||
}, | ||
title: 'pageTitle', | ||
}; | ||
|
||
const validPageURLParams = { | ||
appName: serviceContext.atiAnalyticsAppName, | ||
contentId: atiData.analytics.contentId, | ||
producerId: serviceContext.atiAnalyticsProducerId, | ||
contentType: atiData.analytics.contentType, | ||
pageIdentifier: atiData.analytics.pageIdentifier, | ||
pageTitle: atiData.title, | ||
platform: requestContext.platform, | ||
statsDestination: requestContext.statsDestination, | ||
service: serviceContext.service, | ||
libraryVersion: 'simorgh', | ||
language: serviceContext.lang, | ||
}; | ||
|
||
describe('implementation of buildPageATIParams and buildPageATIUrl', () => { | ||
it('should return the correct object for the page given the ATI configuration', () => { | ||
const result = buildPageATIParams({ | ||
atiData, | ||
requestContext, | ||
serviceContext, | ||
}); | ||
expect(result).toEqual(validPageURLParams); | ||
}); | ||
it('should return the correct url for a page given the ATI configuration', () => { | ||
const result = buildPageATIUrl({ | ||
atiData, | ||
requestContext, | ||
serviceContext, | ||
}); | ||
expect(result).toMatchInlineSnapshot( | ||
`"s=598285&s2=atiAnalyticsProducerId&p=kyrgyz.page&r=0x0x24x24&re=1024x768&hl=00-00-00&lng=en-US&x1=[urn%3Abbc%3Atipo%3Atopic%3Acm7682qz7v1t]&x2=[responsive]&x3=[atiAnalyticsAppName]&x4=[pcm]&x5=[http%253A%252F%252Flocalhost%252F]&x7=[index-home]&x8=[simorgh]&x9=[pageTitle]"`, | ||
); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
src/app/components/ATIAnalytics/params/genericPage/buildParams.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,47 @@ | ||
import { LIBRARY_VERSION } from '../../../../lib/analyticsUtils'; | ||
import { buildATIPageTrackPath } from '../../atiUrl'; | ||
import { ATIDataWithContexts } from '../../types'; | ||
|
||
export const buildPageATIParams = ({ | ||
atiData, | ||
requestContext, | ||
serviceContext, | ||
}: ATIDataWithContexts) => { | ||
const { platform, statsDestination } = requestContext; | ||
const { atiAnalyticsAppName, atiAnalyticsProducerId, service, lang } = | ||
serviceContext; | ||
const { | ||
analytics: { | ||
contentId, | ||
contentType, | ||
pageIdentifier, | ||
timePublished, | ||
timeUpdated, | ||
}, | ||
title: pageTitle, | ||
} = atiData; | ||
return { | ||
appName: atiAnalyticsAppName, | ||
contentId, | ||
producerId: atiAnalyticsProducerId, | ||
contentType, | ||
pageIdentifier, | ||
pageTitle, | ||
platform, | ||
statsDestination, | ||
service, | ||
timePublished, | ||
timeUpdated, | ||
libraryVersion: LIBRARY_VERSION, | ||
language: lang, | ||
}; | ||
}; | ||
|
||
export const buildPageATIUrl = ({ | ||
atiData, | ||
requestContext, | ||
serviceContext, | ||
}: ATIDataWithContexts) => | ||
buildATIPageTrackPath( | ||
buildPageATIParams({ atiData, requestContext, serviceContext }), | ||
); |
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
Oops, something went wrong.