Skip to content

Commit

Permalink
Merge pull request #11013 from bbc/ati-analytics-test-improvements
Browse files Browse the repository at this point in the history
WSTEAMA-593: ATI analytics test improvements
  • Loading branch information
karinathomasbbc authored Aug 17, 2023
2 parents 289f58b + f7d7fff commit 11ac124
Show file tree
Hide file tree
Showing 17 changed files with 1,115 additions and 254 deletions.
106 changes: 56 additions & 50 deletions src/app/components/ATIAnalytics/atiUrl/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,21 @@ describe('getThingAttributes', () => {

const queryParamsArray = splitUrl(queryParams);

expect(queryParamsArray).toMatchInlineSnapshot(`
[
"s=getDestination",
"idclient=getAtUserId",
"r=getScreenInfo",
"re=getBrowserViewPort",
"hl=getCurrentTime",
"lng=getDeviceLanguage",
"x2=[getAppType]",
"x5=[getHref]",
"x6=[getReferrer]",
"x9=[sanitise]",
"x18=[isLocServeCookieSet]",
"xto=-----%40",
"ref=getReferrer",
]
`);
expect(queryParamsArray).toEqual([
's=getDestination',
'idclient=getAtUserId',
'r=getScreenInfo',
're=getBrowserViewPort',
'hl=getCurrentTime',
'lng=getDeviceLanguage',
'x2=[getAppType]',
'x5=[getHref]',
'x6=[getReferrer]',
'x9=[sanitise]',
'x18=[isLocServeCookieSet]',
'xto=-----%40',
'ref=getReferrer',
]);
});

it('should build query params for .app routes', () => {
Expand All @@ -175,24 +173,22 @@ describe('getThingAttributes', () => {

const queryParamsArray = splitUrl(queryParams);

expect(queryParamsArray).toMatchInlineSnapshot(`
[
"s=getDestination",
"idclient=getAtUserId",
"r=getScreenInfo",
"re=getBrowserViewPort",
"hl=getCurrentTime",
"lng=getDeviceLanguage",
"x2=[getAppType]",
"x3=[news-app]",
"x5=[getHref]",
"x6=[getReferrer]",
"x9=[sanitise]",
"x18=[isLocServeCookieSet]",
"xto=-----%40",
"ref=getReferrer",
]
`);
expect(queryParamsArray).toEqual([
's=getDestination',
'idclient=getAtUserId',
'r=getScreenInfo',
're=getBrowserViewPort',
'hl=getCurrentTime',
'lng=getDeviceLanguage',
'x2=[getAppType]',
'x3=[news-app]',
'x5=[getHref]',
'x6=[getReferrer]',
'x9=[sanitise]',
'x18=[isLocServeCookieSet]',
'xto=-----%40',
'ref=getReferrer',
]);
});

it('if ref param is provided, it should be the very last param so that ATI can interpret it correctly as part of the referrer URL', () => {
Expand Down Expand Up @@ -235,20 +231,30 @@ describe('buildATIEventTrackUrl', () => {

it('should return the correct url', () => {
process.env.SIMORGH_ATI_BASE_URL = 'http://foobar.com?';
expect(
buildATIEventTrackUrl({
pageIdentifier: 'pageIdentifier',
service: 'news',
platform: 'canonical',
statsDestination: 'statsDestination',
componentName: 'component',
type: 'type',
campaignID: 'campaignID',
format: 'format',
url: 'url',
}),
).toMatchInlineSnapshot(
`"http://foobar.com?idclient=getAtUserId&s=getDestination&p=pageIdentifier&r=getScreenInfo&re=getBrowserViewPort&hl=getCurrentTime&lng=getDeviceLanguage&atc=PUB-[campaignID]-[component]-[]-[format]-[pageIdentifier]-[]-[]-[url]&type=AT"`,
);

const atiEventTrackUrl = buildATIEventTrackUrl({
pageIdentifier: 'pageIdentifier',
service: 'news',
platform: 'canonical',
statsDestination: 'statsDestination',
componentName: 'component',
type: 'type',
campaignID: 'campaignID',
format: 'format',
url: 'url',
});

expect(splitUrl(atiEventTrackUrl)).toEqual([
'http://foobar.com',
'idclient=getAtUserId',
's=getDestination',
'p=pageIdentifier',
'r=getScreenInfo',
're=getBrowserViewPort',
'hl=getCurrentTime',
'lng=getDeviceLanguage',
'atc=PUB-[campaignID]-[component]-[]-[format]-[pageIdentifier]-[]-[]-[url]',
'type=AT',
]);
});
});
21 changes: 16 additions & 5 deletions src/app/components/ATIAnalytics/beacon/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,22 @@ describe('beacon', () => {
pageIdentifier: 'pageIdentifier',
});
expect(sendBeaconSpy).toHaveBeenCalledTimes(1);
expect(sendBeaconSpy.mock.calls[0]).toMatchInlineSnapshot(`
[
"https://foobar.com?idclient=123-456-789&s=598285&p=pageIdentifier&r=0x0x24x24&re=1024x768&hl=00-00-00&lng=en-US&atc=PUB-[]-[component]-[]-[]-[pageIdentifier]-[]-[]-[]&type=AT",
]
`);

const parsedATIParams = Object.fromEntries(
new URLSearchParams(new URL(sendBeaconSpy.mock.calls[0][0]).search),
);

expect(parsedATIParams).toEqual({
idclient: '123-456-789',
s: '598285',
p: 'pageIdentifier',
r: '0x0x24x24',
re: '1024x768',
hl: '00-00-00',
lng: 'en-US',
atc: 'PUB-[]-[component]-[]-[]-[pageIdentifier]-[]-[]-[]',
type: 'AT',
});
});
});
});
Loading

0 comments on commit 11ac124

Please sign in to comment.