Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed May 4, 2017
1 parent cc85455 commit 3f27b45
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 88 deletions.
2 changes: 1 addition & 1 deletion components/n-ui/ads/js/oAdsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function (flags, appName, adOptions) {
let url;
const apiUrlRoot = 'https://ads-api.ft.com/v1/';
if (appName === 'article') {
uuid = document.querySelector('[data-content-id]').getAttribute('data-content-id');
uuid = document.documentElement.getAttribute('data-content-id');

const referrer = utils.getReferrer();
url = `${apiUrlRoot}content/${uuid}`;
Expand Down
191 changes: 104 additions & 87 deletions components/n-ui/ads/test/oAdsConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const utils = require('../js/utils');
const oAdsConfig = require('../js/oAdsConfig');
const adsSandbox = require('../js/sandbox');
const fakeArticleUuid = '123456';
const fakeConceptUuidV1 = '1234567';
const fakeConceptUuid = '12345678';

let sandbox;
let targeting;
Expand All @@ -15,120 +17,135 @@ describe('Config', () => {

sandbox.stub(utils, 'getLayoutName', () => { return 'custom'; });
sandbox.stub(utils, 'getReferrer', () => null );

targeting = sandbox.stub(document, 'querySelector');
targeting.withArgs('[data-concept-id]').returns({getAttribute: () => fakeArticleUuid});
targeting.withArgs('[data-content-id]').returns({getAttribute: () => fakeArticleUuid});
targeting = sandbox.stub(document.documentElement, 'getAttribute');
targeting.withArgs('data-content-id').returns(fakeArticleUuid);
});

afterEach(() => {
sandbox.restore();
});

describe('third party', () => {
it('Should set gpt configuration value according to app name', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', false);
const gptAttributes = {
network: '5887',
site: 'ft.com',
zone: 'unclassified'
}

expect(config.gpt).to.deep.equal(gptAttributes);
});

it('Should set gpt configuration value according to app name', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', false);
const gptAttributes = {
network: '5887',
site: 'ft.com',
zone: 'unclassified'
}
it('Should set gpt configuration value according to app name and sandbox', () => {
const flags = { get: () => true };
sandbox.stub(adsSandbox, 'isActive', () => { return true; });
const config = oAdsConfig(flags, 'article');
const gptAttributes = {
network: '5887',
site: 'sandbox.next.ft',
zone: 'unclassified'
}
expect(config.gpt).to.deep.equal(gptAttributes);
});

expect(config.gpt).to.deep.equal(gptAttributes);
});

it('Should set gpt configuration value according to app name and sandbox', () => {
const flags = { get: () => true };
sandbox.stub(adsSandbox, 'isActive', () => { return true; });
const config = oAdsConfig(flags, 'article');
const gptAttributes = {
network: '5887',
site: 'sandbox.next.ft',
zone: 'unclassified'
}
expect(config.gpt).to.deep.equal(gptAttributes);
});
it('Should set krux configuration when flag is set to false', () => {
const flags = { get: () => true };
document.cookie = 'FT_U=EID=1234_PID=abc';
const config = oAdsConfig(flags, 'article' );
const userExpectation = {
eid: '1234'
};

expect(config.krux.id).to.be.ok;
expect(config.krux.attributes).to.be.ok;
expect(config.krux.attributes.user).to.be.ok;
expect(config.krux.attributes.user).to.deep.equal(userExpectation);
});

it('Should set krux configuration when flag is set to false', () => {
const flags = { get: () => true };
document.cookie = 'FT_U=EID=1234_PID=abc';
const config = oAdsConfig(flags, 'article' );
const userExpectation = {
eid: '1234'
};
it('Should not set krux configuration when flag is set to false', () => {
const flags = { get: (param) => param === 'krux' ? false : true };
const config = oAdsConfig(flags, 'article' );

expect(config.krux.id).to.be.ok;
expect(config.krux.attributes).to.be.ok;
expect(config.krux.attributes.user).to.be.ok;
expect(config.krux.attributes.user).to.deep.equal(userExpectation);
});
expect(config.krux).to.be.false;
});

it('Should not set krux configuration when flag is set to false', () => {
const flags = { get: (param) => param === 'krux' ? false : true };
const config = oAdsConfig(flags, 'article' );
it('Should not set krux configuration when app requests no targeting', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', { noTargeting: true } );

expect(config.krux).to.be.false;
});
expect(config.krux).to.be.false;
});
it('Should set dfp_targeting config', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article' );
document.cookie = 'FT_U=EID=1234_PID=abc';
const expectation = 'pt=art;eid=1234;nlayout=custom'.split(';');

it('Should not set krux configuration when app requests no targeting', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', { noTargeting: true } );

expect(config.krux).to.be.false;
});
it('Should set dfp_targeting config', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article' );
document.cookie = 'FT_U=EID=1234_PID=abc';
const expectation = 'pt=art;eid=1234;nlayout=custom'.split(';');
expectation.forEach((value) => expect(config.dfp_targeting).to.contain(value));
});

it('Should use zone from metadata if present', () => {
sandbox.stub(utils, 'getMetaData', (param) => {
switch (param) {
case 'dfp_site':
return 'testDfpSite';
break;
case 'dfp_zone':
return 'testDfpZone';
break;
}
});

const flags = { get: () => true };
const config = oAdsConfig(flags, 'article');
expect(config.gpt.zone).to.equal('testDfpSite/testDfpZone');
});
})

expectation.forEach((value) => expect(config.dfp_targeting).to.contain(value));
});
describe('o-ads', () => {

it('Should pass the correct url to o-ads fetch', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article' );
const userUrl = 'https://ads-api.ft.com/v1/user'
const pageUrl = 'https://ads-api.ft.com/v1/content/'
it('Should pass the correct url to o-ads fetch', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article' );
const userUrl = 'https://ads-api.ft.com/v1/user'
const pageUrl = 'https://ads-api.ft.com/v1/content/'

expect(config.targetingApi.user).to.equal(userUrl);
expect(config.targetingApi.page).to.equal(pageUrl + fakeArticleUuid);
})

it('Should not request API targeting if app says not to', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', { noTargeting: true });
expect(config.targetingApi).to.equal(null);
})

expect(config.targetingApi.user).to.equal(userUrl);
expect(config.targetingApi.page).to.equal(pageUrl + fakeArticleUuid);
})

it('Should not request API targeting if app says not to', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'article', { noTargeting: true });
expect(config.targetingApi).to.equal(null);
})
it('Should access concept url to send to o-ads fetch', () => {
const flags = { get: () => true };
const config = oAdsConfig(flags, 'stream-page' );
const pageUrl = 'https://ads-api.ft.com/v1/concept/'
it('Should access v1 concept url to send to o-ads fetch if present', () => {
targeting.withArgs('data-concept-idv1').returns(fakeConceptUuidV1);
targeting.withArgs('data-concept-id').returns(fakeConceptUuid);

const flags = { get: () => true };
const config = oAdsConfig(flags, 'stream-page' );
const pageUrl = 'https://ads-api.ft.com/v1/concept/'

expect(config.targetingApi.page).to.equal(pageUrl + fakeArticleUuid);
});
expect(config.targetingApi.page).to.equal(pageUrl + fakeConceptUuidV1);
});

it('Should access v2 concept url to send to o-ads fetch if present', () => {
targeting.withArgs('data-concept-id').returns(fakeConceptUuid);

const flags = { get: () => true };
const config = oAdsConfig(flags, 'stream-page' );
const pageUrl = 'https://ads-api.ft.com/v1/concept/'

it('Should use zone from metadata if present', () => {
sandbox.stub(utils, 'getMetaData', (param) => {
switch (param) {
case 'dfp_site':
return 'testDfpSite';
break;
case 'dfp_zone':
return 'testDfpZone';
break;
}
expect(config.targetingApi.page).to.equal(pageUrl + fakeConceptUuid);
});

const flags = { get: () => true };
const config = oAdsConfig(flags, 'article');
expect(config.gpt.zone).to.equal('testDfpSite/testDfpZone');
});
})

});
1 change: 1 addition & 0 deletions components/n-ui/tracking/ft/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const oTrackingWrapper = {
const conceptId = getRootData('concept-idv1') || getRootData('concept-id');
if (conceptId) {
context.rootConceptId = conceptId;
context.rootConceptIdV1 = getRootData('concept-idv1');
context.rootTaxonomy = getRootData('taxonomy');
}

Expand Down

0 comments on commit 3f27b45

Please sign in to comment.