Skip to content

Commit

Permalink
Merge pull request #205 from spring-media/TRAC-1983_domain_to_location
Browse files Browse the repository at this point in the history
document.domain replaced by location.hostname for doPlugin contexts
  • Loading branch information
nickyanalytics authored Feb 19, 2024
2 parents dcd77a4 + 982d22c commit 6810fb5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions extensions/doPlugins_global.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ s._utils = {
},

setSportDatencenter: function () {
if (window.document.domain.includes('sport.bild.de') || window.document.domain.includes('sportdaten.sportbild.bild.de')){
if (window.location.hostname.includes('sport.bild.de') || window.location.hostname.includes('sportdaten.sportbild.bild.de')){
window.utag.data.page_document_type = window.location.pathname.includes('/liveticker/') ? 'live-sport' : 'sportdaten';
return window.utag.data.page_document_type;
}
Expand Down Expand Up @@ -178,7 +178,7 @@ s._articleViewTypeObj = {
// Same domain check including subdomains.
isFromInternal: function (referrer) {
const referringDomain = s._utils.getDomainFromURLString(referrer);
const domain = window.document.domain;
const domain = window.location.hostname;
const referringDomainSegments = referringDomain.split('.');
const documentDomainSegments = domain.split('.');

Expand Down
12 changes: 6 additions & 6 deletions tests/doplugins/doplugins_article_view_type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,30 @@ describe('articleViewType()', () => {

it('should return TRUE if referring domain is from the same domain', function () {
const anyDomain = 'any-domain.com';
window.document.domain = anyDomain;
window.location.hostname = anyDomain;
getDomainFromURLStringMock.mockReturnValue(anyDomain);
const result = s._articleViewTypeObj.isFromInternal(anyReferrer);
expect(result).toBe(true);
});

it('should return FALSE if referring domain is NOT from the same domain', function () {
window.document.domain = 'any-domain.com';
window.location.hostname = 'any-domain.com';
getDomainFromURLStringMock.mockReturnValue('any-other-domain.com');
const result = s._articleViewTypeObj.isFromInternal(anyReferrer);
expect(result).toBe(false);
});

it('should return TRUE if referring domain is from sub domain', function () {
const anyDomain = 'any-domain.com';
window.document.domain = anyDomain;
window.location.hostname = anyDomain;
getDomainFromURLStringMock.mockReturnValue(`any-sub-domain.${anyDomain}`);
const result = s._articleViewTypeObj.isFromInternal(anyReferrer);
expect(result).toBe(true);
});

it('should return TRUE if referring domain is from sub domain sportbild', function () {
const anyDomain = 'sportbild.bild.de';
window.document.domain = anyDomain;
window.location.hostname = anyDomain;
getDomainFromURLStringMock.mockReturnValue(anyDomain);
const result = s._articleViewTypeObj.isFromInternal(anyReferrer);
expect(result).toBe(true);
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('articleViewType()', () => {
const anyDomain = 'www.any-domain.de';
const referrer = `https://${anyDomain}`;
cleanUpReferrerMock.mockReturnValue(referrer);
window.document.domain = anyDomain;
window.location.hostname = anyDomain;
const result = s._articleViewTypeObj.isFromHome(referrer);
expect(result).toBe(true);
});
Expand All @@ -294,7 +294,7 @@ describe('articleViewType()', () => {
const anyDomain = 'www.any-domain.de';
const referrer = `https://${anyDomain}/any-path`;
cleanUpReferrerMock.mockReturnValue(referrer);
window.document.domain = anyDomain;
window.location.hostname = anyDomain;
const result = s._articleViewTypeObj.isFromHome(referrer);
expect(result).toBe(false);
});
Expand Down
10 changes: 5 additions & 5 deletions tests/doplugins/doplugins_bild_page_name.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ describe('_bildPageNameObj', () => {

describe('isSportDatencenterTyp', () => {
it('should be false if Domain is not sport', () => {
window.document.domain = 'any-sport.domain.de';
window.location.hostname = 'any-sport.domain.de';
const returnValue = s._bildPageNameObj.isSportDatencenterTyp(s);
expect(returnValue).toBe(false);
});

it('should be sportdaten if Domain is sport.bild.de', () => {
window.document.domain = 'sport.bild.de';
window.location.hostname = 'sport.bild.de';
const returnValue = s._bildPageNameObj.isSportDatencenterTyp(s);
expect(returnValue).toBe('sportdaten');
});

it('should be sportdaten if Domain is sportdaten.sportbild.bild.de', () => {
window.document.domain = 'sportdaten.sportbild.bild.de';
window.location.hostname = 'sportdaten.sportbild.bild.de';
const returnValue = s._bildPageNameObj.isSportDatencenterTyp(s);
expect(returnValue).toBe('sportdaten');
});
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('_bildPageNameObj', () => {

it('should set relevant data if isSportdatencentertyp live-sport is true', () => {
window.utag.data.page_id = '12345678';
window.document.domain = 'www.sport.bild.de';
window.location.hostname = 'www.sport.bild.de';
window.location.pathname = 'any/path/liveticker/';

s._bildPageNameObj.setPageName(s);
Expand All @@ -258,7 +258,7 @@ describe('_bildPageNameObj', () => {

it('should set relevant data if isSportdatencentertyp sportdaten is true', () => {
window.utag.data.page_id = '12345678';
window.document.domain = 'www.sport.bild.de';
window.location.hostname = 'www.sport.bild.de';
window.location.pathname = 'any/path/';

s._bildPageNameObj.setPageName(s);
Expand Down
4 changes: 3 additions & 1 deletion tests/mocks/browserMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function createWindowMock() {
referrer: '',
domain: '',
location: {
pathname: ''
pathname: '',
hostname: ''
}
},
navigator: {
Expand All @@ -39,6 +40,7 @@ function createWindowMock() {
hash: '',
search: '',
pathname: '',
hostname: ''
}
};
}
Expand Down

0 comments on commit 6810fb5

Please sign in to comment.