Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue related to site and app #9

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,9 @@ export const spec = {
if (typeof bidderRequest.uspConsent !== typeof undefined) {
deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}
// Site
const url = config.getConfig('pageUrl') || deepAccess(bidderRequest, 'refererInfo.referer');
const urlObj = parseUrl(url);
deepSetValue(request, 'site.page', url);
deepSetValue(request, 'site.domain', urlObj && urlObj.hostname);
}

// First party data
const fpd = config.getConfig('ortb2');
if (fpd) {
if (fpd.site) {
request.site = request.site ? {...request.site, ...fpd.site} : fpd.site;
} else if (fpd.app) {
request.app = fpd.app;
}
}
ID_REQUEST.buildSiteOrApp(request, bidderRequest);

const bidRequest0 = bidRequests[0];

Expand Down Expand Up @@ -422,6 +409,28 @@ const ID_REQUEST = {
}
return null;
},

buildSiteOrApp(request, bidderRequest) {
const app = {};
const configAppSettings = config.getConfig('app') || {};
const fpdAppSettings = config.getConfig('ortb2.app') || {};
mergeDeep(app, configAppSettings, fpdAppSettings);

if (Object.keys(app).length !== 0) {
request.app = app;
} else {
const site = {};
const url = config.getConfig('pageUrl') || deepAccess(bidderRequest, 'refererInfo.referer');
if (url) {
site.page = url;
site.domain = parseUrl(url).hostname;
}
const configSiteSettings = config.getConfig('site') || {};
const fpdSiteSettings = config.getConfig('ortb2.site') || {};
mergeDeep(site, configSiteSettings, fpdSiteSettings);
request.site = site;
}
},
};

const ID_RESPONSE = {
Expand Down
82 changes: 82 additions & 0 deletions test/spec/modules/improvedigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,88 @@ describe('Improve Digital Adapter Tests', function () {
expect(payload.imp[0].ext.gpid).to.not.exist;
expect(payload.imp[0].instl).to.not.exist;
});

it('should not set site when app is defined in FPD', function () {
const getConfigStub = sinon.stub(config, 'getConfig');
getConfigStub.withArgs('ortb2.app').returns({ content: 'XYZ' });
let request = spec.buildRequests([simpleBidRequest], bidderRequest)[0];
let payload = JSON.parse(request.data);
expect(payload.site).does.not.exist;
expect(payload.app).does.exist;
expect(payload.app.content).does.exist.and.equal('XYZ');
getConfigStub.restore();
});

it('should not set site when app is defined in CONFIG', function () {
const getConfigStub = sinon.stub(config, 'getConfig');
getConfigStub.withArgs('app').returns({ content: 'XYZ' });
let request = spec.buildRequests([simpleBidRequest], bidderRequest)[0];
let payload = JSON.parse(request.data);
expect(payload.site).does.not.exist;
expect(payload.app).does.exist;
expect(payload.app.content).does.exist.and.equal('XYZ');
getConfigStub.restore();
});

it('should set correct site params', function () {
let getConfigStub = sinon.stub(config, 'getConfig');
getConfigStub.withArgs('site').returns({
content: 'XYZ',
page: 'https://improveditigal.com/',
domain: 'improveditigal.com'
});
let request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0];
let payload = JSON.parse(request.data);
expect(payload.site.content).does.exist.and.equal('XYZ');
expect(payload.site.page).does.exist.and.equal('https://improveditigal.com/');
expect(payload.site.domain).does.exist.and.equal('improveditigal.com');
getConfigStub.restore();

request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0];
payload = JSON.parse(request.data);
expect(payload.site.content).does.not.exist;
expect(payload.site.page).does.exist.and.equal('https://blah.com/test.html');
expect(payload.site.domain).does.exist.and.equal('blah.com');

getConfigStub = sinon.stub(config, 'getConfig');
getConfigStub.withArgs('ortb2.site').returns({
content: 'ZZZ',
});
request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0];
payload = JSON.parse(request.data);
expect(payload.site.content).does.exist.and.equal('ZZZ');
expect(payload.site.page).does.exist.and.equal('https://blah.com/test.html');
expect(payload.site.domain).does.exist.and.equal('blah.com');
getConfigStub.restore();
});

it('should set pageUrl as site param', function () {
let getConfigStub = sinon.stub(config, 'getConfig');
getConfigStub.withArgs('pageUrl').returns('https://improvidigital.com/test-page');
let request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0];
let payload = JSON.parse(request.data);
expect(payload.site.page).does.exist.and.equal('https://improvidigital.com/test-page');
expect(payload.site.domain).does.exist.and.equal('improvidigital.com');
getConfigStub.restore();

getConfigStub = sinon.stub(config, 'getConfig');
getConfigStub.withArgs('pageUrl').returns(undefined);
request = spec.buildRequests([simpleBidRequest], bidderRequestReferrer)[0];
payload = JSON.parse(request.data);
expect(payload.site.page).does.exist.and.equal('https://blah.com/test.html');
expect(payload.site.domain).does.exist.and.equal('blah.com');
getConfigStub.restore();
});

it('should set site when app not available', function () {
const getConfigStub = sinon.stub(config, 'getConfig');
getConfigStub.withArgs('app').returns(undefined);
let request = spec.buildRequests([simpleBidRequest], bidderRequest)[0];
let payload = JSON.parse(request.data);
expect(payload.site).does.exist;
expect(payload.app).does.not.exist;
getConfigStub.restore();
});
});

const serverResponse = {
Expand Down