Skip to content

Commit

Permalink
PubMatic bid adapter to support app object set using setConfig (prebi…
Browse files Browse the repository at this point in the history
…d#5090)

* added support for pubcommon, digitrust, id5id

* added support for IdentityLink

* changed the source for id5

* added unit test cases

* changed source param for identityLink

* merge the device object from setConfig

* set app from config and site, remove site if app is set

* added test cases for reading device from config

* unit test case for reading app from conf

* delete the site object

* set undefined not null
  • Loading branch information
pm-harshad-mane authored and rjvelicaria committed Apr 9, 2020
1 parent 993e47e commit 2ecc534
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,11 @@ export const spec = {
payload.site.page = conf.kadpageurl.trim() || payload.site.page.trim();
payload.site.domain = _getDomainFromURL(payload.site.page);

// merge the device from config.getConfig('device')
if (typeof config.getConfig('device') === 'object') {
payload.device = Object.assign(payload.device, config.getConfig('device'));
}

// passing transactionId in source.tid
utils.deepSetValue(payload, 'source.tid', conf.transactionId);

Expand Down Expand Up @@ -953,6 +958,16 @@ export const spec = {
_handleEids(payload, validBidRequests);
_blockedIabCategoriesValidation(payload, blockedIabCategories);

// Note: Do not move this block up
// if site object is set in Prebid config then we need to copy required fields from site into app and unset the site object
if (typeof config.getConfig('app') === 'object') {
payload.app = config.getConfig('app');
// not copying domain from site as it is a derived value from page
payload.app.publisher = payload.site.publisher;
payload.app.ext = payload.site.ext || UNDEFINED;
delete payload.site;
}

return {
method: 'POST',
url: ENDPOINT,
Expand Down
64 changes: 64 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,70 @@ describe('PubMatic adapter', function () {
expect(data.source.ext.schain).to.deep.equal(bidRequests[0].schain);
});

it('Merge the device info from config', function() {
let sandbox = sinon.sandbox.create();
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
device: {
'newkey': 'new-device-data'
}
};
return config[key];
});
let request = spec.buildRequests(bidRequests);
let data = JSON.parse(request.data);
expect(data.device.js).to.equal(1);
expect(data.device.dnt).to.equal((navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0);
expect(data.device.h).to.equal(screen.height);
expect(data.device.w).to.equal(screen.width);
expect(data.device.language).to.equal(navigator.language);
expect(data.device.newkey).to.equal('new-device-data');// additional data from config
sandbox.restore();
});

it('Merge the device info from config; data from config overrides the info we have gathered', function() {
let sandbox = sinon.sandbox.create();
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
device: {
newkey: 'new-device-data',
language: 'MARATHI'
}
};
return config[key];
});
let request = spec.buildRequests(bidRequests);
let data = JSON.parse(request.data);
expect(data.device.js).to.equal(1);
expect(data.device.dnt).to.equal((navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0);
expect(data.device.h).to.equal(screen.height);
expect(data.device.w).to.equal(screen.width);
expect(data.device.language).to.equal('MARATHI');// // data overriding from config
expect(data.device.newkey).to.equal('new-device-data');// additional data from config
sandbox.restore();
});

it('Set app from config, copy publisher and ext from site, unset site', function() {
let sandbox = sinon.sandbox.create();
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
app: {
bundle: 'org.prebid.mobile.demoapp',
domain: 'prebid.org'
}
};
return config[key];
});
let request = spec.buildRequests(bidRequests);
let data = JSON.parse(request.data);
expect(data.app.bundle).to.equal('org.prebid.mobile.demoapp');
expect(data.app.domain).to.equal('prebid.org');
expect(data.app.publisher.id).to.equal(bidRequests[0].params.publisherId);
expect(data.app.ext.key_val).to.exist.and.to.equal(bidRequests[0].params.dctr);
expect(data.site).to.not.exist;
sandbox.restore();
});

it('Request params check: without adSlot', function () {
delete bidRequests[0].params.adSlot;
let request = spec.buildRequests(bidRequests);
Expand Down

0 comments on commit 2ecc534

Please sign in to comment.